示例#1
0
        public static MatrixBase <T> SubMatrix(
            MatrixBase <T> matrix,
            RangeInt rowRange,
            RangeInt columnRange)
        {
            if (!matrix.ColumnRange.Contains(columnRange))
            {
                throw new ArgumentOutOfRangeException("columnRange");
            }
            if (!matrix.RowRange.Contains(rowRange))
            {
                throw new ArgumentOutOfRangeException("rowRange");
            }

            var rawResult = new T[rowRange.Length, columnRange.Length];

            for (int row = rowRange.Start; row < rowRange.End; row++)
            {
                for (int col = columnRange.Start; col < columnRange.End; col++)
                {
                    rawResult[row - rowRange.Start, col - columnRange.Start] = matrix.Data[row, col];
                }
            }
            MatrixBase <T> result = new MatrixBase <T>(rawResult);

            return(result);
        }
示例#2
0
        public static MatrixBase <T> AppendRows(
            MatrixBase <T> matrix,
            MatrixBase <T> rows)
        {
            if (matrix.ColumnCount != rows.ColumnCount)
            {
                throw new DimensionMismatchException("The number of columns in matrix does not equal the number of columns in rows");
            }
            var result = new MatrixBase <T>(new T[matrix.RowCount + rows.RowCount, matrix.ColumnCount]);

            for (var row = 0; row < matrix.RowCount; row++)
            {
                for (var col = 0; col < matrix.ColumnCount; col++)
                {
                    result[row, col] = matrix.Data[row, col];
                }
            }

            for (var row = matrix.RowCount; row < matrix.RowCount + rows.RowCount; row++)
            {
                for (var col = 0; col < matrix.ColumnCount; col++)
                {
                    result[row, col] = rows.Data[row - matrix.RowCount, col];
                }
            }
            return(result);
        }
示例#3
0
        public int FindColumn(MatrixBase <int> matrix, MatrixBase <int> columnToFind)
        {
            if (columnToFind.ColumnCount > 1)
            {
                throw new ArgumentException("The column matrix contains more than 1 column");
            }

            if (matrix.RowCount != columnToFind.RowCount)
            {
                throw new DimensionMismatchException("The number of rows in matrix does not equal the number of rows in the column");
            }

            for (var col = 0; col < matrix.ColumnCount; col++)
            {
                for (var row = 0; row < matrix.RowCount; row++)
                {
                    if (matrix.Data[row, col] != columnToFind.Data[row, 0])
                    {
                        break;
                    }

                    if (row == matrix.RowCount - 1)
                    {
                        return(col);
                    }
                }
            }
            return(-1);
        }
示例#4
0
        protected static MatrixBase <T> ElementWiseOperation(
            MatrixBase <T> matrixLeft,
            MatrixBase <T> matrixRight,
            Func <T, T, T> operation)
        {
            if (matrixLeft.RowCount != matrixRight.RowCount)
            {
                throw new DimensionMismatchException("The number of rows in matrix1 does not equal the number of rows in matrix2");
            }
            if (matrixLeft.ColumnCount != matrixRight.ColumnCount)
            {
                throw new DimensionMismatchException("The number of columns in matrix1 does not equal the number of columns in matrix2");
            }

            var rawResult = new T[matrixLeft.RowCount, matrixLeft.ColumnCount];

            for (int row = 0; row < rawResult.GetLength(0); row++)
            {
                for (int col = 0; col < rawResult.GetLength(1); col++)
                {
                    rawResult[row, col] = operation(matrixLeft[row, col], matrixRight[row, col]);
                }
            }

            MatrixBase <T> result = new MatrixBase <T>(rawResult);

            return(result);
        }
示例#5
0
        public static MatrixBase <T> Concatenate(
            MatrixBase <T> matrixLeft,
            MatrixBase <T> matrixRight)
        {
            if (matrixLeft.RowCount != matrixRight.RowCount)
            {
                throw new DimensionMismatchException("The number of rows in left matrix does not equal the number of rows in right matrix");
            }

            var rawResult = new T[matrixLeft.RowCount, matrixLeft.ColumnCount + matrixRight.ColumnCount];

            for (var row = 0; row < matrixLeft.RowCount; row++)
            {
                for (var col = 0; col < matrixLeft.ColumnCount; col++)
                {
                    rawResult[row, col] = matrixLeft[row, col];
                }

                for (var col = 0; col < matrixRight.ColumnCount; col++)
                {
                    rawResult[row, matrixLeft.ColumnCount + col] = matrixRight[row, col];
                }
            }
            var result = new MatrixBase <T>(rawResult);

            return(result);
        }
示例#6
0
        public static MatrixBase <T> SwapColumns(
            MatrixBase <T> matrix,
            int i,
            int j)
        {
            if (!matrix.ColumnRange.Contains(i))
            {
                throw new ArgumentOutOfRangeException("columnRange");
            }

            if (!matrix.ColumnRange.Contains(j))
            {
                throw new ArgumentOutOfRangeException("columnRange");
            }

            if (i == j)
            {
                return(matrix.Clone());
            }

            var result = matrix.Clone();

            for (var row = 0; row < matrix.RowCount; row++)
            {
                var temp = result.Data[row, i];
                result.Data[row, i] = result.Data[row, j];
                result.Data[row, j] = temp;
            }
            return(result);
        }
示例#7
0
        public static MatrixBase <T> SwapRows(
            MatrixBase <T> matrix,
            int i,
            int j)
        {
            if (!matrix.RowRange.Contains(i))
            {
                throw new ArgumentOutOfRangeException("rowRange");
            }

            if (!matrix.RowRange.Contains(j))
            {
                throw new ArgumentOutOfRangeException("rowRange");
            }

            if (i == j)
            {
                return(matrix.Clone());
            }

            var result = matrix.Clone();

            for (var col = 0; col < matrix.ColumnCount; col++)
            {
                var temp = result.Data[i, col];
                result.Data[i, col] = result.Data[j, col];
                result.Data[j, col] = temp;
            }

            return(result);
        }
示例#8
0
        public static MatrixOnGaloisField Concatenate(
            MatrixOnGaloisField matrixLeft,
            MatrixOnGaloisField matrixRight)
        {
            var baseResult = MatrixBase <int> .Concatenate(matrixLeft, matrixRight);

            var result = new MatrixOnGaloisField(baseResult, matrixLeft.GaloisField);

            return(result);
        }
示例#9
0
        public static MatrixInt Concatenate(
            MatrixInt matrixLeft,
            MatrixInt matrixRight)
        {
            var baseResult = MatrixBase <int> .Concatenate(matrixLeft, matrixRight);

            var result = new MatrixInt(baseResult);

            return(result);
        }
示例#10
0
        public PolynomialBase(MatrixBase <T> baseMatrix)
        {
            if (baseMatrix.RowCount > 1)
            {
                throw new DimensionMismatchException("Base matrix for shoud consist of single row");
            }

            Length       = baseMatrix.ColumnCount;
            Coefficients = new T[Length];

            for (var i = 0; i < Length; i++)
            {
                Coefficients[i] = baseMatrix.Data[0, i];
            }
        }
示例#11
0
        public static MatrixBase <T> Transpose(MatrixBase <T> matrix)
        {
            var rawDataTransposed = new T[matrix.ColumnCount, matrix.RowCount];

            for (int row = 0; row < matrix.RowCount; row++)
            {
                for (int col = 0; col < matrix.ColumnCount; col++)
                {
                    rawDataTransposed[col, row] = matrix[row, col];
                }
            }
            var result = new MatrixBase <T>(rawDataTransposed);

            return(result);
        }
示例#12
0
        public MatrixBase(MatrixBase <T> matrix)
        {
            RowCount    = matrix.RowCount;
            ColumnCount = matrix.ColumnCount;

            Data = new T[RowCount, ColumnCount];

            for (var row = 0; row < RowCount; row++)
            {
                for (var col = 0; col < ColumnCount; col++)
                {
                    Data[row, col] = matrix[row, col];
                }
            }
        }
示例#13
0
        protected static MatrixBase <T> UnaryElementWiseOperation(
            MatrixBase <T> matrix,
            Func <T, T> operation)
        {
            var rawResult = new T[matrix.RowCount, matrix.ColumnCount];

            for (int row = 0; row < rawResult.GetLength(0); row++)
            {
                for (int col = 0; col < rawResult.GetLength(1); col++)
                {
                    rawResult[row, col] = operation(matrix[row, col]);
                }
            }
            MatrixBase <T> result = new MatrixBase <T>(rawResult);

            return(result);
        }
示例#14
0
        public static MatrixBase <T> GetRow(
            MatrixBase <T> matrix,
            int rowNumber)
        {
            if (!matrix.RowRange.Contains(rowNumber))
            {
                throw new ArgumentOutOfRangeException("columnRange");
            }
            var rawResult = new T[1, matrix.ColumnCount];

            for (int col = 0; col < matrix.ColumnCount; col++)
            {
                rawResult[0, col] = matrix.Data[rowNumber, col];
            }
            MatrixBase <T> result = new MatrixBase <T>(rawResult);

            return(result);
        }
示例#15
0
        public static MatrixBase <T> PermuteRows(
            MatrixBase <T> matrix,
            IList <int> permutation)
        {
            if (matrix.RowCount != permutation.Count)
            {
                throw new DimensionMismatchException("The number of columns in matrix does not equal the permutation list count");
            }
            var result = new MatrixBase <T>(matrix.RowCount, matrix.ColumnCount);

            for (int row = 0; row < matrix.RowCount; row++)
            {
                for (int col = 0; col < matrix.ColumnCount; col++)
                {
                    result[row, col] = matrix[permutation[row], col];
                }
            }
            return(result);
        }
示例#16
0
        public static MatrixBase <T> GetColumn(
            MatrixBase <T> matrix,
            int columnNumber)
        {
            if (!matrix.ColumnRange.Contains(columnNumber))
            {
                throw new ArgumentOutOfRangeException("columnRange");
            }

            var rawResult = new T[matrix.RowCount, 1];

            for (int row = 0; row < matrix.RowCount; row++)
            {
                rawResult[row, 0] = matrix.Data[row, columnNumber];
            }
            MatrixBase <T> result = new MatrixBase <T>(rawResult);

            return(result);
        }
示例#17
0
        public static MatrixBase <T> GetRangeOfRows(
            MatrixBase <T> matrix,
            RangeInt rowRange)
        {
            if (!matrix.RowRange.Contains(rowRange))
            {
                throw new ArgumentOutOfRangeException("rowRange");
            }

            var rawResult = new T[rowRange.Length, matrix.ColumnCount];

            for (int row = rowRange.Start; row < rowRange.End; row++)
            {
                for (int col = 0; col < matrix.ColumnCount; col++)
                {
                    rawResult[row - rowRange.Start, col] = matrix.Data[row, col];
                }
            }
            MatrixBase <T> result = new MatrixBase <T>(rawResult);

            return(result);
        }
示例#18
0
 public MatrixInt(MatrixBase <int> matrix) : base(matrix)
 {
 }
示例#19
0
 public PolynomialDouble(MatrixBase <double> baseMatrix) : base(baseMatrix)
 {
 }
示例#20
0
 public MatrixOnGaloisField(MatrixBase <int> matrix, GaloisField galoisField) : base(matrix)
 {
     GaloisField = galoisField;
 }