示例#1
0
        /// <summary>
        /// Replaces all cell values of the receiver with the values of another matrix.
        /// Both matrices must have the same number of Slices, Rows and Columns.
        /// 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="source">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>Slices != source.Slices || Rows != source.Rows || Columns != source.Columns</i></exception>
        public override ObjectMatrix3D Assign(ObjectMatrix3D source)
        {
            // overriden for performance only
            if (!(source is DenseObjectMatrix3D))
            {
                return(base.Assign(source));
            }
            DenseObjectMatrix3D other = (DenseObjectMatrix3D)source;

            if (other == this)
            {
                return(this);
            }
            CheckShape(other);
            if (HaveSharedCells(other))
            {
                ObjectMatrix3D c = other.Copy();
                if (!(c is DenseObjectMatrix3D))
                { // should not happen
                    return(base.Assign(source));
                }
                other = (DenseObjectMatrix3D)c;
            }

            if (!this.IsView && !other.IsView)
            { // quickest
                Array.Copy(other.Elements, 0, this.Elements, 0, this.Elements.Length);
                return(this);
            }
            return(base.Assign(other));
        }
示例#2
0
 /// <summary>
 /// Returns <i>true</i> if both matrices share common cells.
 /// More formally, returns <i>true</i> if <i>other != null</i> and at least one of the following conditions is met
 /// <ul>
 /// <li>the receiver is a view of the other matrix
 /// <li>the other matrix is a view of the receiver
 /// <li><i>this == other</i>
 /// </ul>
 /// </summary>
 protected new Boolean HaveSharedCellsRaw(ObjectMatrix3D other)
 {
     if (other is SelectedDenseObjectMatrix3D)
     {
         SelectedDenseObjectMatrix3D otherMatrix = (SelectedDenseObjectMatrix3D)other;
         return(this.Elements == otherMatrix.Elements);
     }
     else if (other is DenseObjectMatrix3D)
     {
         DenseObjectMatrix3D otherMatrix = (DenseObjectMatrix3D)other;
         return(this.Elements == otherMatrix.Elements);
     }
     return(false);
 }