// MATRIX COPY internal override void CopyToUnchecked(MatrixStorage <T> target, ExistingData existingData) { if (target is DiagonalMatrixStorage <T> diagonalTarget) { CopyToUnchecked(diagonalTarget); return; } if (target is DenseColumnMajorMatrixStorage <T> denseTarget) { CopyToUnchecked(denseTarget, existingData); return; } if (target is SparseCompressedRowMatrixStorage <T> sparseTarget) { CopyToUnchecked(sparseTarget, existingData); return; } // FALL BACK if (existingData == ExistingData.Clear) { target.Clear(); } for (int i = 0; i < Data.Length; i++) { target.At(i, i, Data[i]); } }
internal override void MapIndexedToUnchecked <TU>(MatrixStorage <TU> target, Func <int, int, T, TU> f, Zeros zeros, ExistingData existingData) { var processZeros = zeros == Zeros.Include || !Zero.Equals(f(0, 1, Zero)); if (target is DiagonalMatrixStorage <TU> diagonalTarget) { if (processZeros) { throw new NotSupportedException("Cannot map non-zero off-diagonal values into a diagonal matrix"); } CommonParallel.For(0, Data.Length, 4096, (a, b) => { for (int i = a; i < b; i++) { diagonalTarget.Data[i] = f(i, i, Data[i]); } }); return; } // FALL BACK if (existingData == ExistingData.Clear && !processZeros) { target.Clear(); } if (processZeros) { for (int j = 0; j < ColumnCount; j++) { for (int i = 0; i < RowCount; i++) { target.At(i, j, f(i, j, i == j ? Data[i] : Zero)); } } } else { for (int i = 0; i < Data.Length; i++) { target.At(i, i, f(i, i, Data[i])); } } }