// COLUMN COPY internal override void CopySubColumnToUnchecked(VectorStorage <T> target, int columnIndex, int sourceRowIndex, int targetRowIndex, int rowCount, ExistingData existingData) { var targetDense = target as DenseVectorStorage <T>; if (targetDense != null) { Array.Copy(Data, columnIndex * RowCount + sourceRowIndex, targetDense.Data, targetRowIndex, rowCount); return; } // FALL BACK var offset = columnIndex * RowCount; for (int i = sourceRowIndex, ii = targetRowIndex; i < sourceRowIndex + rowCount; i++, ii++) { target.At(ii, Data[offset + i]); } }
// VECTOR COPY internal override void CopyToUnchecked(VectorStorage <T> target, bool skipClearing = false) { var denseTarget = target as DenseVectorStorage <T>; if (denseTarget != null) { if (!ReferenceEquals(this, denseTarget)) { Array.Copy(Data, 0, denseTarget.Data, 0, Data.Length); } return; } // FALL BACK for (int i = 0; i < Data.Length; i++) { target.At(i, Data[i]); } }
// ROW COPY internal override void CopySubRowToUnchecked(VectorStorage <T> target, int rowIndex, int sourceColumnIndex, int targetColumnIndex, int columnCount, bool skipClearing = false) { 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]); } }
public virtual void CopySubVectorTo(VectorStorage <T> target, int sourceIndex, int targetIndex, int count, bool skipClearing = false) { if (target == null) { throw new ArgumentNullException("target"); } if (ReferenceEquals(this, target)) { throw new NotSupportedException(); } ValidateSubVectorRange(target, sourceIndex, targetIndex, count); for (int i = sourceIndex, ii = targetIndex; i < sourceIndex + count; i++, ii++) { target.At(ii, At(i)); } }
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) { for (int i = 0; i < Data.Length; 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])); } }
internal override void MapIndexedToUnchecked <TU>(VectorStorage <TU> target, Func <int, T, TU> f, Zeros zeros, ExistingData existingData) { if (target is DenseVectorStorage <TU> denseTarget) { 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])); } }
// VECTOR COPY internal override void CopyToUnchecked(VectorStorage <T> target, ExistingData existingData) { if (target is DenseVectorStorage <T> denseTarget) { if (!ReferenceEquals(this, denseTarget)) { Array.Copy(Data, 0, denseTarget.Data, 0, Data.Length); } return; } if (target is SparseVectorStorage <T> sparseTarget) { var indices = new List <int>(); var values = new List <T>(); for (int i = 0; i < Data.Length; i++) { var item = Data[i]; if (!Zero.Equals(item)) { values.Add(item); indices.Add(i); } } sparseTarget.Indices = indices.ToArray(); sparseTarget.Values = values.ToArray(); sparseTarget.ValueCount = values.Count; return; } // FALL BACK for (int i = 0; i < Data.Length; i++) { target.At(i, Data[i]); } }
// SUB-VECTOR COPY internal override void CopySubVectorToUnchecked(VectorStorage <T> target, int sourceIndex, int targetIndex, int count, ExistingData existingData = ExistingData.Clear) { 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]); } }
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)); } }
// FUNCTIONAL COMBINATORS internal override void MapToUnchecked <TU>(VectorStorage <TU> target, Func <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(Data[i]); } }); return; } // FALL BACK for (int i = 0; i < Length; i++) { target.At(i, f(Data[i])); } }
// VECTOR COPY internal override void CopyToUnchecked(VectorStorage <T> target, ExistingData existingData) { if (target is SparseVectorStorage <T> sparseTarget) { CopyToUnchecked(sparseTarget); return; } // FALL BACK if (existingData == ExistingData.Clear) { target.Clear(); } if (ValueCount != 0) { for (int i = 0; i < ValueCount; i++) { target.At(Indices[i], Values[i]); } } }