예제 #1
0
 internal virtual void Map2ToUnchecked(MatrixStorage <T> target, MatrixStorage <T> other, Func <T, T, T> f, Zeros zeros, ExistingData existingData)
 {
     for (int i = 0; i < RowCount; i++)
     {
         for (int j = 0; j < ColumnCount; j++)
         {
             target.At(i, j, f(At(i, j), other.At(i, j)));
         }
     }
 }
예제 #2
0
 internal virtual void TransposeToUnchecked(MatrixStorage <T> target, ExistingData existingData)
 {
     for (int j = 0; j < ColumnCount; j++)
     {
         for (int i = 0; i < RowCount; i++)
         {
             target.At(j, i, At(i, j));
         }
     }
 }
예제 #3
0
 internal virtual void MapIndexedToUnchecked <TU>(MatrixStorage <TU> target, Func <int, int, T, TU> f, Zeros zeros, ExistingData existingData)
     where TU : struct, IEquatable <TU>, IFormattable
 {
     for (int j = 0; j < ColumnCount; j++)
     {
         for (int i = 0; i < RowCount; i++)
         {
             target.At(i, j, f(i, j, At(i, j)));
         }
     }
 }
예제 #4
0
 internal virtual void CopySubMatrixToUnchecked(MatrixStorage <T> target,
                                                int sourceRowIndex, int targetRowIndex, int rowCount,
                                                int sourceColumnIndex, int targetColumnIndex, int columnCount,
                                                ExistingData existingData)
 {
     for (int j = sourceColumnIndex, jj = targetColumnIndex; j < sourceColumnIndex + columnCount; j++, jj++)
     {
         for (int i = sourceRowIndex, ii = targetRowIndex; i < sourceRowIndex + rowCount; i++, ii++)
         {
             target.At(ii, jj, At(i, j));
         }
     }
 }
예제 #5
0
        internal virtual TState Fold2Unchecked <TOther, TState>(MatrixStorage <TOther> other, Func <TState, T, TOther, TState> f, TState state, Zeros zeros)
            where TOther : struct, IEquatable <TOther>, IFormattable
        {
            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    state = f(state, At(i, j), other.At(i, j));
                }
            }

            return(state);
        }
예제 #6
0
 internal virtual void MapSubMatrixIndexedToUnchecked <TU>(MatrixStorage <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
 {
     for (int j = sourceColumnIndex, jj = targetColumnIndex; j < sourceColumnIndex + columnCount; j++, jj++)
     {
         for (int i = sourceRowIndex, ii = targetRowIndex; i < sourceRowIndex + rowCount; i++, ii++)
         {
             target.At(ii, jj, f(ii, jj, At(i, j)));
         }
     }
 }
예제 #7
0
        // COLUMN COPY

        internal override void CopyToColumnUnchecked(MatrixStorage <T> target, int columnIndex, ExistingData existingData)
        {
            if (target is DenseColumnMajorMatrixStorage <T> denseTarget)
            {
                Array.Copy(Data, 0, denseTarget.Data, columnIndex * denseTarget.RowCount, Data.Length);
                return;
            }

            // FALL BACK

            for (int i = 0; i < Length; i++)
            {
                target.At(i, columnIndex, Data[i]);
            }
        }
예제 #8
0
        // SUB-COLUMN COPY

        internal override void CopyToSubColumnUnchecked(MatrixStorage <T> target, int columnIndex,
                                                        int sourceRowIndex, int targetRowIndex, int rowCount, ExistingData existingData)
        {
            if (target is DenseColumnMajorMatrixStorage <T> denseTarget)
            {
                Array.Copy(Data, sourceRowIndex, denseTarget.Data, columnIndex * denseTarget.RowCount + targetRowIndex, rowCount);
                return;
            }

            // FALL BACK

            for (int i = sourceRowIndex, ii = targetRowIndex; i < sourceRowIndex + rowCount; i++, ii++)
            {
                target.At(ii, columnIndex, Data[i]);
            }
        }
예제 #9
0
        // COLUMN COPY

        internal override void CopyToColumnUnchecked(MatrixStorage <T> target, int columnIndex, ExistingData existingData)
        {
            if (existingData == ExistingData.Clear)
            {
                target.ClearUnchecked(0, Length, columnIndex, 1);
            }

            if (ValueCount == 0)
            {
                return;
            }

            for (int i = 0; i < ValueCount; i++)
            {
                target.At(Indices[i], columnIndex, Values[i]);
            }
        }
예제 #10
0
 internal virtual Tuple <int, int, T, TOther> Find2Unchecked <TOther>(MatrixStorage <TOther> other, Func <T, TOther, bool> predicate, Zeros zeros)
     where TOther : struct, IEquatable <TOther>, IFormattable
 {
     for (int i = 0; i < RowCount; i++)
     {
         for (int j = 0; j < ColumnCount; j++)
         {
             var item      = At(i, j);
             var otherItem = other.At(i, j);
             if (predicate(item, otherItem))
             {
                 return(new Tuple <int, int, T, TOther>(i, j, item, otherItem));
             }
         }
     }
     return(null);
 }
예제 #11
0
        // Row COPY

        internal override void CopyToRowUnchecked(MatrixStorage <T> target, int rowIndex, ExistingData existingData)
        {
            if (existingData == ExistingData.Clear)
            {
                target.ClearUnchecked(rowIndex, 1, 0, Length);
            }

            if (ValueCount == 0)
            {
                return;
            }

            for (int i = 0; i < ValueCount; i++)
            {
                target.At(rowIndex, Indices[i], Values[i]);
            }
        }
        // MATRIX COPY

        internal override void CopyToUnchecked(MatrixStorage <T> target, ExistingData existingData)
        {
            if (target is DenseColumnMajorMatrixStorage <T> denseTarget)
            {
                CopyToUnchecked(denseTarget);
                return;
            }

            // FALL BACK

            for (int j = 0, offset = 0; j < ColumnCount; j++, offset += RowCount)
            {
                for (int i = 0; i < RowCount; i++)
                {
                    target.At(i, j, Data[i + offset]);
                }
            }
        }
예제 #13
0
        // ROW COPY

        internal override void CopyToRowUnchecked(MatrixStorage <T> target, int rowIndex, ExistingData existingData)
        {
            if (target is DenseColumnMajorMatrixStorage <T> denseTarget)
            {
                for (int j = 0; j < Data.Length; j++)
                {
                    denseTarget.Data[j * target.RowCount + rowIndex] = Data[j];
                }
                return;
            }

            // FALL BACK

            for (int j = 0; j < Length; j++)
            {
                target.At(rowIndex, j, Data[j]);
            }
        }
예제 #14
0
        // SUB-ROW COPY

        internal override void CopyToSubRowUnchecked(MatrixStorage <T> target, int rowIndex,
                                                     int sourceColumnIndex, int targetColumnIndex, int columnCount, ExistingData existingData)
        {
            if (target is DenseColumnMajorMatrixStorage <T> denseTarget)
            {
                for (int j = 0; j < Data.Length; j++)
                {
                    denseTarget.Data[(j + targetColumnIndex) * target.RowCount + rowIndex] = Data[j + sourceColumnIndex];
                }
                return;
            }

            // FALL BACK

            for (int j = sourceColumnIndex, jj = targetColumnIndex; j < sourceColumnIndex + columnCount; j++, jj++)
            {
                target.At(rowIndex, jj, Data[j]);
            }
        }
        // TRANSPOSE

        internal override void TransposeToUnchecked(MatrixStorage <T> target, ExistingData existingData)
        {
            if (target is DenseColumnMajorMatrixStorage <T> denseTarget)
            {
                TransposeToUnchecked(denseTarget);
                return;
            }

            if (target is SparseCompressedRowMatrixStorage <T> sparseTarget)
            {
                TransposeToUnchecked(sparseTarget);
                return;
            }

            // FALL BACK

            for (int j = 0, offset = 0; j < ColumnCount; j++, offset += RowCount)
            {
                for (int i = 0; i < RowCount; i++)
                {
                    target.At(j, i, Data[i + offset]);
                }
            }
        }
        internal override void CopySubMatrixToUnchecked(MatrixStorage <T> target,
                                                        int sourceRowIndex, int targetRowIndex, int rowCount,
                                                        int sourceColumnIndex, int targetColumnIndex, int columnCount,
                                                        ExistingData existingData)
        {
            if (target is DenseColumnMajorMatrixStorage <T> denseTarget)
            {
                CopySubMatrixToUnchecked(denseTarget, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount);
                return;
            }

            // TODO: Proper Sparse Implementation

            // FALL BACK

            for (int j = sourceColumnIndex, jj = targetColumnIndex; j < sourceColumnIndex + columnCount; j++, jj++)
            {
                int index = sourceRowIndex + j * RowCount;
                for (int ii = targetRowIndex; ii < targetRowIndex + rowCount; ii++)
                {
                    target.At(ii, jj, Data[index++]);
                }
            }
        }
예제 #17
0
        internal override void MapSubMatrixIndexedToUnchecked <TU>(MatrixStorage <TU> target, Func <int, int, T, TU> f,
                                                                   int sourceRowIndex, int targetRowIndex, int rowCount,
                                                                   int sourceColumnIndex, int targetColumnIndex, int columnCount,
                                                                   Zeros zeros, ExistingData existingData)
        {
            if (target is DiagonalMatrixStorage <TU> diagonalTarget)
            {
                MapSubMatrixIndexedToUnchecked(diagonalTarget, f, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount, zeros);
                return;
            }

            if (target is DenseColumnMajorMatrixStorage <TU> denseTarget)
            {
                MapSubMatrixIndexedToUnchecked(denseTarget, f, sourceRowIndex, targetRowIndex, rowCount, sourceColumnIndex, targetColumnIndex, columnCount, zeros, existingData);
                return;
            }

            // TODO: Proper Sparse Implementation

            // FALL BACK

            if (existingData == ExistingData.Clear)
            {
                target.ClearUnchecked(targetRowIndex, rowCount, targetColumnIndex, columnCount);
            }

            if (sourceRowIndex == sourceColumnIndex)
            {
                int targetRow    = targetRowIndex;
                int targetColumn = targetColumnIndex;
                for (var i = 0; i < Math.Min(columnCount, rowCount); i++)
                {
                    target.At(targetRow, targetColumn, f(targetRow, targetColumn, Data[sourceRowIndex + i]));
                    targetRow++;
                    targetColumn++;
                }
            }
            else if (sourceRowIndex > sourceColumnIndex && sourceColumnIndex + columnCount > sourceRowIndex)
            {
                // column by column, but skip resulting zero columns at the beginning
                int columnInit   = sourceRowIndex - sourceColumnIndex;
                int targetRow    = targetRowIndex;
                int targetColumn = targetColumnIndex + columnInit;
                for (var i = 0; i < Math.Min(columnCount - columnInit, rowCount); i++)
                {
                    target.At(targetRow, targetColumn, f(targetRow, targetColumn, Data[sourceRowIndex + i]));
                    targetRow++;
                    targetColumn++;
                }
            }
            else if (sourceRowIndex < sourceColumnIndex && sourceRowIndex + rowCount > sourceColumnIndex)
            {
                // row by row, but skip resulting zero rows at the beginning
                int rowInit      = sourceColumnIndex - sourceRowIndex;
                int targetRow    = targetRowIndex + rowInit;
                int targetColumn = targetColumnIndex;
                for (var i = 0; i < Math.Min(columnCount, rowCount - rowInit); i++)
                {
                    target.At(targetRow, targetColumn, f(targetRow, targetColumn, Data[sourceColumnIndex + i]));
                    targetRow++;
                    targetColumn++;
                }
            }
        }