Exemple #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));
        }