/// <summary>
        /// Constructs a matrix which is the concatenation of all given parts.
        /// Cells are copied.
        /// <summary>
        public ObjectMatrix1D Make(ObjectMatrix1D[] parts)
        {
            if (parts.Length == 0)
            {
                return(Make(0));
            }

            int size = 0;

            for (int i = 0; i < parts.Length; i++)
            {
                size += parts[i].Count();
            }

            ObjectMatrix1D vector = Make(size);

            size = 0;
            for (int i = 0; i < parts.Length; i++)
            {
                vector.ViewPart(size, parts[i].Count()).Assign(parts[i]);
                size += parts[i].Count();
            }

            return(vector);
        }
Example #2
0
        /// <summary>
        /// Constructs and returns a deep copy of the receiver.
        /// <p>
        /// <b>Note that the returned matrix is an independent deep copy.</b>
        /// The returned matrix is not backed by this matrix, so changes in the returned matrix are not reflected in this matrix, and vice-versad
        /// </summary>
        /// <returns>a deep copy of the receiver.</returns>
        public virtual ObjectMatrix1D Copy()
        {
            ObjectMatrix1D copy = Like();

            copy.Assign(this);
            return(copy);
        }
Example #3
0
 /// <summary>
 /// Assigns the result of a function to each cell; <i>x[i] = function(x[i], y[i])</i>.
 /// <p>
 /// <b>Example:</b>
 /// <pre>
 /// // assign x[i] = x[i]<sup>y[i]</sup>
 /// m1 = 0 1 2 3;
 /// m2 = 0 2 4 6;
 /// m1.assign(m2, Cern.jet.math.Functions.pow);
 /// -->
 /// m1 == 1 1 16 729
 /// </pre>
 /// For further examples, see the <see cref="Function.ObjectFunction{C}"/> doc</a>.
 /// </summary>
 /// <param name="y">the secondary matrix to operate on.</param>
 /// <param name="function">a function object taking as first argument the current cell's value of <i>this</i>,and as second argument the current cell's value of <i>y</i>,</param>
 /// <returns><i>this</i> (for convenience only).</returns>
 /// <exception cref="ArgumentException">if <i>Size != y.Count</i>.</exception>
 /// <see cref="Cern.Jet.Math.Functions"/>
 public virtual ObjectMatrix1D Assign(ObjectMatrix1D y, Cern.Colt.Function.ObjectObjectFunction <Object> function)
 {
     CheckSize(y);
     for (int i = Size; --i >= 0;)
     {
         this[i] = function(this[i], y[i]);
     }
     return(this);
 }
        /// <summary>
        /// C = A||B; Constructs a new matrix which is the concatenation of two other matrices.
        /// Example: <i>0 1</i> append<i>3 4</i> --> <i>0 1 3 4</i>.
        /// <summary>
        public ObjectMatrix1D Append(ObjectMatrix1D A, ObjectMatrix1D B)
        {
            // concatenate
            ObjectMatrix1D matrix = Make(A.Count() + B.Count());

            matrix.ViewPart(0, A.Count()).Assign(A);
            matrix.ViewPart(A.Count(), B.Count()).Assign(B);
            return(matrix);
        }
Example #5
0
 /// <summary>
 /// Swaps each element<i> this[i]</i> with <i>other [i]</i>.
 /// </summary>
 /// <exception cref="ArgumentException">if <i>Size != other.Count</i>.</exception>
 public virtual void Swap(ObjectMatrix1D other)
 {
     CheckSize(other);
     for (int i = Size; --i >= 0;)
     {
         Object tmp = this[i];
         this[i]  = other[i];
         other[i] = tmp;
     }
     return;
 }
Example #6
0
        public ObjectMatrix1D Diagonal(ObjectMatrix2D A)
        {
            int            min  = System.Math.Min(A.Rows, A.Columns);
            ObjectMatrix1D diag = Make1D(min);

            for (int i = min; --i >= 0;)
            {
                diag[i] = A[i, i];
            }
            return(diag);
        }
Example #7
0
        public ObjectMatrix2D Diagonal(ObjectMatrix1D vector)
        {
            int            size = vector.Size;
            ObjectMatrix2D diag = Make(size, size);

            for (int i = size; --i >= 0;)
            {
                diag[i, i] = vector[i];
            }
            return(diag);
        }
        /// <summary>
        ///		C = A||A||..||A; Constructs a new matrix which is concatenated<i> repeat</i> times.
        ///		Example:
        ///<pre>
        /// 0 1
        /// repeat(3) -->
        /// 0 1 0 1 0 1
        ///</pre>
        /// <summary>
        public ObjectMatrix1D Repeat(ObjectMatrix1D A, int repeat)
        {
            int            size   = A.Count();
            ObjectMatrix1D matrix = Make(repeat * size);

            for (int i = repeat; --i >= 0;)
            {
                matrix.ViewPart(size * i, size).Assign(A);
            }
            return(matrix);
        }
        /// <summary>
        /// Constructs a matrix from the values of the given list.
        /// The values are copiedd So subsequent changes in <i>values</i> are not reflected in the matrix, and vice-versa.
        ///
        /// <summary>
        /// <param name="values">The values to be filled into the new matrix.</param>
        /// <returns>a new matrix.</returns>
        public ObjectMatrix1D Make(Cern.Colt.List.ObjectArrayList values)
        {
            int            size   = values.Count();
            ObjectMatrix1D vector = Make(size);

            for (int i = size; --i >= 0;)
            {
                vector[i] = values[i];
            }
            return(vector);
        }
Example #10
0
 /// <summary>
 /// Returns <i>true</i> if both matrices share at least one identical cell.
 /// </summary>
 protected Boolean HaveSharedCells(ObjectMatrix1D other)
 {
     if (other == null)
     {
         return(false);
     }
     if (this == other)
     {
         return(true);
     }
     return(GetContent().HaveSharedCellsRaw(other.GetContent()));
 }
        /// <summary>
        /// Constructs a list from the given matrix.
        /// The values are copiedd So subsequent changes in <i>values</i> are not reflected in the list, and vice-versa.
        ///
        /// <summary>
        /// <param name="values">The values to be filled into the new list.</param>
        /// <returns>a new list.</returns>
        public Cern.Colt.List.ObjectArrayList ToList(ObjectMatrix1D values)
        {
            int size = values.Count();

            Cern.Colt.List.ObjectArrayList list = new Cern.Colt.List.ObjectArrayList(size);
            list.SetSize(size);
            for (int i = size; --i >= 0;)
            {
                list[i] = values[i];
            }
            return(list);
        }
Example #12
0
        /// <summary>
        /// Applies a function to each corresponding cell of two matrices and aggregates the results.
        /// Returns a value <i>v</i> such that<i> v==a(Size)</i> where<i> a(i) == aggr(a(i-1), f(get(i), other.Get(i)) )</i> and terminators are<i> a(1) == f(get(0),other.Get(0)), a(0)==null</i>.
        /// <p>
        /// <b>Example:</b>
        /// <pre>
        /// Cern.jet.math.Functions F = Cern.jet.math.Functions.Functions;
        /// x = 0 1 2 3
        /// y = 0 1 2 3
        ///
        /// // Sum( x[i]*y[i] )
        /// x.aggregate(y, F.plus, F.mult);
        /// --> 14
        ///
        /// // Sum( (x[i]+y[i])^2 )
        /// x.aggregate(y, F.plus, F.chain(F.square, F.plus));
        /// --> 56
        /// </pre>
        /// For further examples, see the <see cref="Function.ObjectFunction{C}"/> doc</a>.
        /// </summary>
        /// <param name="aggr">an aggregation function taking as first argument the current aggregation and as second argument the transformed current cell values.</param>
        /// <param name="f">a function transforming the current cell value.</param>
        /// <returns>the aggregated measure.</returns>
        /// <exception cref="ArgumentException">if <i>Size != other.Count</i>.</exception>
        public virtual Object Aggregate(ObjectMatrix1D other, Cern.Colt.Function.ObjectObjectFunction <Object> aggr, Cern.Colt.Function.ObjectObjectFunction <Object> f)
        {
            CheckSize(other);
            if (Size == 0)
            {
                return(null);
            }
            Object a = f(this[Size - 1], other[Size - 1]);

            for (int i = Size - 1; --i >= 0;)
            {
                a = aggr(a, f(this[i], other[i]));
            }
            return(a);
        }
Example #13
0
        /// <summary>
        /// Replaces all cell values of the receiver with the values of another matrix.
        /// Both matrices must have the same size.
        /// If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <i>other</i>.
        /// </summary>
        /// <param name="other">the source matrix to copy from (may be identical to the receiver).</param>
        /// <returns><i>this</i> (for convenience only).</returns>
        /// <exception cref="ArgumentException">if <i>Size != other.Count</i>.</exception>
        public virtual ObjectMatrix1D Assign(ObjectMatrix1D other)
        {
            if (other == this)
            {
                return(this);
            }
            CheckSize(other);
            if (HaveSharedCells(other))
            {
                other = other.Copy();
            }

            for (int i = Size; --i >= 0;)
            {
                this[i] = other[i];
            }
            return(this);
        }
Example #14
0
        /// <summary>
        /// Compares the specified Object with the receiver for equality.
        /// Returns true if and only if the specified Object is also at least an ObjectMatrix1D, both matrices have the
        /// same size, and all corresponding pairs of cells in the two matrices are the same.
        /// In other words, two matrices are defined to be equal if they contain the
        /// same cell values in the same order.
        /// Tests elements for equality or identity as specified by <i>testForEquality</i>.
        /// When testing for equality, two elements <i>e1</i> and
        /// <i>e2</i> are <i>equal</i> if <i>(e1==null ? e2==null :
        /// e1.Equals(e2))</i>d)
        /// </summary>
        /// <param name="otherObj">the Object to be compared for equality with the receiver.</param>
        /// <param name="testForEquality">if true -> tests for equality, otherwise for identity.</param>
        /// <returns>true if the specified Object is equal to the receiver.</returns>
        public Boolean Equals(Object otherObj, Boolean testForEquality)
        { //delta
            if (!(otherObj is ObjectMatrix1D))
            {
                return(false);
            }
            if (this == otherObj)
            {
                return(true);
            }
            if (otherObj == null)
            {
                return(false);
            }
            ObjectMatrix1D other = (ObjectMatrix1D)otherObj;

            if (Size != other.Size)
            {
                return(false);
            }

            if (!testForEquality)
            {
                for (int i = Size; --i >= 0;)
                {
                    if (this[i] != other[i])
                    {
                        return(false);
                    }
                }
            }
            else
            {
                for (int i = Size; --i >= 0;)
                {
                    if (!(this[i] == null ? other[i] == null : this[i].Equals(other[i])))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #15
0
 /// <summary>
 /// Returns <i>true</i> if both matrices share at least one identical cell.
 /// </summary>
 protected Boolean HaveSharedCellsRaw(ObjectMatrix1D other)
 {
     return(false);
 }