void CopyTo(DenseColumnMajorMatrixStorage <T> target, bool skipClearing) { if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { var message = string.Format(Resources.ArgumentMatrixDimensions2, RowCount + "x" + ColumnCount, target.RowCount + "x" + target.ColumnCount); throw new ArgumentException(message, "target"); } if (!skipClearing) { target.Clear(); } if (ValueCount != 0) { for (int row = 0; row < RowCount; row++) { var startIndex = RowPointers[row]; var endIndex = row < RowPointers.Length - 1 ? RowPointers[row + 1] : ValueCount; for (var j = startIndex; j < endIndex; j++) { target.At(row, ColumnIndices[j], Values[j]); } } } }
void CopySubMatrixTo(DenseColumnMajorMatrixStorage <T> target, int sourceRowIndex, int targetRowIndex, int rowCount, int sourceColumnIndex, int targetColumnIndex, int columnCount, bool skipClearing) { if (target == null) { throw new ArgumentNullException("target"); } ValidateSubMatrixRange(target, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount); if (!skipClearing) { target.Clear(targetRowIndex, rowCount, targetColumnIndex, columnCount); } if (sourceRowIndex > sourceColumnIndex && sourceColumnIndex + columnCount > sourceRowIndex) { // column by column, but skip resulting zero columns at the beginning int columnInit = sourceRowIndex - sourceColumnIndex; int offset = (columnInit + targetColumnIndex) * target.RowCount + targetRowIndex; int step = target.RowCount + 1; int end = Math.Min(columnCount - columnInit, rowCount) + sourceRowIndex; for (int i = sourceRowIndex, j = offset; i < end; i++, j += step) { target.Data[j] = Data[i]; } } else if (sourceRowIndex < sourceColumnIndex && sourceRowIndex + rowCount > sourceColumnIndex) { // row by row, but skip resulting zero rows at the beginning int rowInit = sourceColumnIndex - sourceRowIndex; int offset = targetColumnIndex * target.RowCount + rowInit + targetRowIndex; int step = target.RowCount + 1; int end = Math.Min(columnCount, rowCount - rowInit) + sourceColumnIndex; for (int i = sourceColumnIndex, j = offset; i < end; i++, j += step) { target.Data[j] = Data[i]; } } else { int offset = targetColumnIndex * target.RowCount + targetRowIndex; int step = target.RowCount + 1; var end = Math.Min(columnCount, rowCount) + sourceRowIndex; for (int i = sourceRowIndex, j = offset; i < end; i++, j += step) { target.Data[j] = Data[i]; } } }
void CopyToUnchecked(DenseColumnMajorMatrixStorage <T> target, ExistingData existingData) { if (existingData == ExistingData.Clear) { target.Clear(); } for (int i = 0; i < Data.Length; i++) { target.Data[i * (target.RowCount + 1)] = Data[i]; } }
void CopyToUnchecked(DenseColumnMajorMatrixStorage <T> target, bool skipClearing) { if (!skipClearing) { target.Clear(); } for (int i = 0; i < Data.Length; i++) { target.Data[i * (target.RowCount + 1)] = Data[i]; } }
void CopySubMatrixToUnchecked(DenseColumnMajorMatrixStorage <T> target, int sourceRowIndex, int targetRowIndex, int rowCount, int sourceColumnIndex, int targetColumnIndex, int columnCount, ExistingData existingData) { if (existingData == ExistingData.Clear) { target.Clear(targetRowIndex, rowCount, targetColumnIndex, columnCount); } if (sourceRowIndex > sourceColumnIndex && sourceColumnIndex + columnCount > sourceRowIndex) { // column by column, but skip resulting zero columns at the beginning int columnInit = sourceRowIndex - sourceColumnIndex; int offset = (columnInit + targetColumnIndex) * target.RowCount + targetRowIndex; int step = target.RowCount + 1; int end = Math.Min(columnCount - columnInit, rowCount) + sourceRowIndex; for (int i = sourceRowIndex, j = offset; i < end; i++, j += step) { target.Data[j] = Data[i]; } } else if (sourceRowIndex < sourceColumnIndex && sourceRowIndex + rowCount > sourceColumnIndex) { // row by row, but skip resulting zero rows at the beginning int rowInit = sourceColumnIndex - sourceRowIndex; int offset = targetColumnIndex * target.RowCount + rowInit + targetRowIndex; int step = target.RowCount + 1; int end = Math.Min(columnCount, rowCount - rowInit) + sourceColumnIndex; for (int i = sourceColumnIndex, j = offset; i < end; i++, j += step) { target.Data[j] = Data[i]; } } else { int offset = targetColumnIndex * target.RowCount + targetRowIndex; int step = target.RowCount + 1; var end = Math.Min(columnCount, rowCount) + sourceRowIndex; for (int i = sourceRowIndex, j = offset; i < end; i++, j += step) { target.Data[j] = Data[i]; } } }
void CopyToUnchecked(DenseColumnMajorMatrixStorage <T> target, bool skipClearing) { if (!skipClearing) { target.Clear(); } if (ValueCount != 0) { for (int row = 0; row < RowCount; row++) { var startIndex = RowPointers[row]; var endIndex = RowPointers[row + 1]; for (var j = startIndex; j < endIndex; j++) { target.At(row, ColumnIndices[j], Values[j]); } } } }
void CopyTo(DenseColumnMajorMatrixStorage <T> target, bool skipClearing) { if (target == null) { throw new ArgumentNullException("target"); } if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { var message = string.Format(Resources.ArgumentMatrixDimensions2, RowCount + "x" + ColumnCount, target.RowCount + "x" + target.ColumnCount); throw new ArgumentException(message, "target"); } if (!skipClearing) { target.Clear(); } for (int i = 0; i < Data.Length; i++) { target.Data[i * (target.RowCount + 1)] = Data[i]; } }
void MapSubMatrixIndexedToUnchecked <TU>(DenseColumnMajorMatrixStorage <TU> target, Func <int, int, T, TU> f, int sourceRowIndex, int targetRowIndex, int rowCount, int sourceColumnIndex, int targetColumnIndex, int columnCount, Zeros zeros, ExistingData existingData) where TU : struct, IEquatable <TU>, IFormattable { var processZeros = zeros == Zeros.Include || !Zero.Equals(f(0, 1, Zero)); if (existingData == ExistingData.Clear && !processZeros) { target.Clear(targetRowIndex, rowCount, targetColumnIndex, columnCount); } if (processZeros) { CommonParallel.For(0, columnCount, Math.Max(4096 / rowCount, 32), (a, b) => { int sourceColumn = sourceColumnIndex + a; int targetColumn = targetColumnIndex + a; for (int j = a; j < b; j++) { int targetIndex = targetRowIndex + (j + targetColumnIndex) * target.RowCount; int sourceRow = sourceRowIndex; int targetRow = targetRowIndex; for (int i = 0; i < rowCount; i++) { target.Data[targetIndex++] = f(targetRow++, targetColumn, sourceRow++ == sourceColumn ? Data[sourceColumn] : Zero); } sourceColumn++; targetColumn++; } }); } else { if (sourceRowIndex > sourceColumnIndex && sourceColumnIndex + columnCount > sourceRowIndex) { // column by column, but skip resulting zero columns at the beginning int columnInit = sourceRowIndex - sourceColumnIndex; int offset = (columnInit + targetColumnIndex) * target.RowCount + targetRowIndex; int step = target.RowCount + 1; int count = Math.Min(columnCount - columnInit, rowCount); for (int k = 0, j = offset; k < count; j += step, k++) { target.Data[j] = f(targetRowIndex + k, targetColumnIndex + columnInit + k, Data[sourceRowIndex + k]); } } else if (sourceRowIndex < sourceColumnIndex && sourceRowIndex + rowCount > sourceColumnIndex) { // row by row, but skip resulting zero rows at the beginning int rowInit = sourceColumnIndex - sourceRowIndex; int offset = targetColumnIndex * target.RowCount + rowInit + targetRowIndex; int step = target.RowCount + 1; int count = Math.Min(columnCount, rowCount - rowInit); for (int k = 0, j = offset; k < count; j += step, k++) { target.Data[j] = f(targetRowIndex + rowInit + k, targetColumnIndex + k, Data[sourceColumnIndex + k]); } } else { int offset = targetColumnIndex * target.RowCount + targetRowIndex; int step = target.RowCount + 1; var count = Math.Min(columnCount, rowCount); for (int k = 0, j = offset; k < count; j += step, k++) { target.Data[j] = f(targetRowIndex + k, targetColumnIndex + k, Data[sourceRowIndex + k]); } } } }