Exemplo n.º 1
0
 /// <summary>
 /// Returns <i>true</i> if both matrices share at least one identical cell.
 /// </summary>
 protected new Boolean HaveSharedCellsRaw(ObjectMatrix1D other)
 {
     if (other is SelectedDenseObjectMatrix1D)
     {
         SelectedDenseObjectMatrix1D otherMatrix = (SelectedDenseObjectMatrix1D)other;
         return(this.Elements == otherMatrix.Elements);
     }
     else if (other is DenseObjectMatrix1D)
     {
         DenseObjectMatrix1D otherMatrix = (DenseObjectMatrix1D)other;
         return(this.Elements == otherMatrix.Elements);
     }
     return(false);
 }
Exemplo n.º 2
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="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>size() != other.Count</i>.</exception>
        public override ObjectMatrix1D Assign(ObjectMatrix1D source)
        {
            // overriden for performance only
            if (!(source is DenseObjectMatrix1D))
            {
                return(base.Assign(source));
            }
            DenseObjectMatrix1D other = (DenseObjectMatrix1D)source;

            if (other == this)
            {
                return(this);
            }
            CheckSize(other);
            if (!IsView && !other.IsView)
            { // quickest
                Array.Copy(other.Elements, 0, this.Elements, 0, this.Elements.Length);
                return(this);
            }
            if (HaveSharedCells(other))
            {
                ObjectMatrix1D c = other.Copy();
                if (!(c is DenseObjectMatrix1D))
                { // should not happen
                    return(base.Assign(source));
                }
                other = (DenseObjectMatrix1D)c;
            }

            Object[] elems      = this.Elements;
            Object[] otherElems = other.Elements;
            if (Elements == null || otherElems == null)
            {
                throw new NullReferenceException();
            }
            int s  = this.Stride;
            int ys = other.Stride;

            int index      = base.Index(0);
            int otherIndex = other.Index(0);

            for (int k = Size; --k >= 0;)
            {
                elems[index] = otherElems[otherIndex];
                index       += s;
                otherIndex  += ys;
            }
            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Swaps each element <i>this[i]</i> with <i>other[i]</i>.
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">if <i>size() != other.Count</i>.</exception>
        public override void Swap(ObjectMatrix1D other)
        {
            // overriden for performance only
            if (!(other is DenseObjectMatrix1D))
            {
                base.Swap(other);
            }
            DenseObjectMatrix1D y = (DenseObjectMatrix1D)other;

            if (y == this)
            {
                return;
            }
            CheckSize(y);

            Object[] elems      = this.Elements;
            Object[] otherElems = y.Elements;
            if (Elements == null || otherElems == null)
            {
                throw new NullReferenceException();
            }
            int s  = this.Stride;
            int ys = y.Stride;

            int index      = base.Index(0);
            int otherIndex = y.Index(0);

            for (int k = Size; --k >= 0;)
            {
                Object tmp = elems[index];
                elems[index]           = otherElems[otherIndex];
                otherElems[otherIndex] = tmp;
                index      += s;
                otherIndex += ys;
            }
            return;
        }