// ROW COPY

        internal override void CopySubRowToUnchecked(VectorStorage <T> target, int rowIndex, int sourceColumnIndex, int targetColumnIndex, int columnCount,
                                                     ExistingData existingData)
        {
            var targetDense = target as DenseVectorStorage <T>;

            if (targetDense != null)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    targetDense.Data[j + targetColumnIndex] = Data[(j + sourceColumnIndex) * RowCount + rowIndex];
                }
                return;
            }

            // FALL BACK

            for (int j = sourceColumnIndex, jj = targetColumnIndex; j < sourceColumnIndex + columnCount; j++, jj++)
            {
                target.At(jj, Data[(j * RowCount) + rowIndex]);
            }
        }
        internal override void MapIndexedToUnchecked <TU>(VectorStorage <TU> target, Func <int, T, TU> f, Zeros zeros, ExistingData existingData)
        {
            var denseTarget = target as DenseVectorStorage <TU>;

            if (denseTarget != null)
            {
                CommonParallel.For(0, Data.Length, 4096, (a, b) =>
                {
                    for (int i = a; i < b; i++)
                    {
                        denseTarget.Data[i] = f(i, Data[i]);
                    }
                });
                return;
            }

            // FALL BACK

            for (int i = 0; i < Length; i++)
            {
                target.At(i, f(i, Data[i]));
            }
        }
Example #3
0
        internal virtual void CopySubVectorToUnchecked(VectorStorage <T> target,
                                                       int sourceIndex, int targetIndex, int count, ExistingData existingData)
        {
            if (ReferenceEquals(this, target))
            {
                var tmp = new T[count];
                for (int i = 0; i < tmp.Length; i++)
                {
                    tmp[i] = At(i + sourceIndex);
                }
                for (int i = 0; i < tmp.Length; i++)
                {
                    At(i + targetIndex, tmp[i]);
                }

                return;
            }

            for (int i = sourceIndex, ii = targetIndex; i < sourceIndex + count; i++, ii++)
            {
                target.At(ii, At(i));
            }
        }
        // SUB-VECTOR COPY

        internal override void CopySubVectorToUnchecked(VectorStorage <T> target,
                                                        int sourceIndex, int targetIndex, int count, ExistingData existingData)
        {
            var sparseTarget = target as SparseVectorStorage <T>;

            if (sparseTarget != null)
            {
                CopySubVectorToUnchecked(sparseTarget, sourceIndex, targetIndex, count, existingData);
                return;
            }

            // FALL BACK

            var offset = targetIndex - sourceIndex;

            var sourceFirst = Array.BinarySearch(Indices, 0, ValueCount, sourceIndex);
            var sourceLast  = Array.BinarySearch(Indices, 0, ValueCount, sourceIndex + count - 1);

            if (sourceFirst < 0)
            {
                sourceFirst = ~sourceFirst;
            }
            if (sourceLast < 0)
            {
                sourceLast = ~sourceLast - 1;
            }

            if (existingData == ExistingData.Clear)
            {
                target.Clear(targetIndex, count);
            }

            for (int i = sourceFirst; i <= sourceLast; i++)
            {
                target.At(Indices[i] + offset, Values[i]);
            }
        }