コード例 #1
0
        /// <inheritdoc/>
        public FieldMatrix <T> multiply(FieldMatrix <T> m)
        {
            // safety check
            checkMultiplicationCompatible(m);

            int             nRows = getRowDimension();
            int             nCols = m.getColumnDimension();
            int             nSum  = getColumnDimension();
            FieldMatrix <T> outp  = createMatrix(nRows, nCols);

            for (int row = 0; row < nRows; ++row)
            {
                for (int col = 0; col < nCols; ++col)
                {
                    T sum = field.getZero();
                    for (int i = 0; i < nSum; ++i)
                    {
                        sum = sum.add(getEntry(row, i).multiply(m.getEntry(i, col)));
                    }
                    outp.setEntry(row, col, sum);
                }
            }

            return(outp);
        }
コード例 #2
0
 /// <summary>
 /// Returns the matrix L of the decomposition.
 /// <para>L is a lower-triangular matrix</para>
 /// </summary>
 /// <returns>the L matrix (or null if decomposed matrix is singular)</returns>
 public FieldMatrix <T> getL()
 {
     if ((cachedL == null) && !singular)
     {
         int m = pivot.Length;
         cachedL = new Array2DRowFieldMatrix <T>(field, m, m);
         for (int i = 0; i < m; ++i)
         {
             T[] luI = lu[i];
             for (int j = 0; j < i; ++j)
             {
                 cachedL.setEntry(i, j, luI[j]);
             }
             cachedL.setEntry(i, i, field.getOne());
         }
     }
     return(cachedL);
 }
コード例 #3
0
        /// <summary>
        /// Returns a diagonal matrix with specified elements.
        /// </summary>
        /// <typeparam name="T">the type of the field elements</typeparam>
        /// <param name="diagonal">diagonal elements of the matrix (the array elements
        /// will be copied)</param>
        /// <returns>diagonal matrix</returns>
        public static FieldMatrix <T> createFieldDiagonalMatrix <T>(T[] diagonal) where T : FieldElement <T>
        {
            FieldMatrix <T> m =
                createFieldMatrix(diagonal[0].getField(), diagonal.Length, diagonal.Length);

            for (int i = 0; i < diagonal.Length; ++i)
            {
                m.setEntry(i, i, diagonal[i]);
            }
            return(m);
        }
コード例 #4
0
        /// <inheritdoc/>
        public FieldMatrix <T> getColumnMatrix(int column)
        {
            checkColumnIndex(column);
            int             nRows = getRowDimension();
            FieldMatrix <T> outp  = createMatrix(nRows, 1);

            for (int i = 0; i < nRows; ++i)
            {
                outp.setEntry(i, 0, getEntry(i, column));
            }

            return(outp);
        }
コード例 #5
0
        /// <inheritdoc/>
        public FieldMatrix <T> getRowMatrix(int row)
        {
            checkRowIndex(row);
            int             nCols = getColumnDimension();
            FieldMatrix <T> outp  = createMatrix(1, nCols);

            for (int i = 0; i < nCols; ++i)
            {
                outp.setEntry(0, i, getEntry(row, i));
            }

            return(outp);
        }
コード例 #6
0
 /// <summary>
 /// Returns the P rows permutation matrix.
 /// <para>P is a sparse matrix with exactly one element set to 1.0 in
 /// each row and each column, all other elements being set to 0.0.</para>
 /// <para>The positions of the 1 elements are given by the <see cref="getPivot()">
 /// pivot permutation vector</see>.</para>
 /// </summary>
 /// <returns>the P rows permutation matrix (or null if decomposed matrix is singular)
 /// </returns>
 /// <remarks>
 /// See <see cref="getPivot()"/>
 /// </remarks>
 public FieldMatrix <T> getP()
 {
     if ((cachedP == null) && !singular)
     {
         int m = pivot.Length;
         cachedP = new Array2DRowFieldMatrix <T>(field, m, m);
         for (int i = 0; i < m; ++i)
         {
             cachedP.setEntry(i, pivot[i], field.getOne());
         }
     }
     return(cachedP);
 }
コード例 #7
0
        /// <inheritdoc/>
        public FieldMatrix <T> scalarAdd(T d)
        {
            int             rowCount    = getRowDimension();
            int             columnCount = getColumnDimension();
            FieldMatrix <T> outp        = createMatrix(rowCount, columnCount);

            for (int row = 0; row < rowCount; ++row)
            {
                for (int col = 0; col < columnCount; ++col)
                {
                    outp.setEntry(row, col, getEntry(row, col).add(d));
                }
            }
            return(outp);
        }
コード例 #8
0
        /// <inheritdoc/>
        public FieldMatrix <T> getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
        {
            checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);

            FieldMatrix <T> subMatrix = createMatrix(endRow - startRow + 1, endColumn - startColumn + 1);

            for (int i = startRow; i <= endRow; ++i)
            {
                for (int j = startColumn; j <= endColumn; ++j)
                {
                    subMatrix.setEntry(i - startRow, j - startColumn, getEntry(i, j));
                }
            }

            return(subMatrix);
        }
コード例 #9
0
 /// <summary>
 /// Returns the matrix U of the decomposition.
 /// <para>U is an upper-triangular matrix</para>
 /// </summary>
 /// <returns>the U matrix (or null if decomposed matrix is singular)</returns>
 public FieldMatrix <T> getU()
 {
     if ((cachedU == null) && !singular)
     {
         int m = pivot.Length;
         cachedU = new Array2DRowFieldMatrix <T>(field, m, m);
         for (int i = 0; i < m; ++i)
         {
             T[] luI = lu[i];
             for (int j = i; j < m; ++j)
             {
                 cachedU.setEntry(i, j, luI[j]);
             }
         }
     }
     return(cachedU);
 }
コード例 #10
0
        /// <inheritdoc/>
        public FieldMatrix <T> subtract(FieldMatrix <T> m)
        {
            // safety check
            checkSubtractionCompatible(m);

            int             rowCount    = getRowDimension();
            int             columnCount = getColumnDimension();
            FieldMatrix <T> outp        = createMatrix(rowCount, columnCount);

            for (int row = 0; row < rowCount; ++row)
            {
                for (int col = 0; col < columnCount; ++col)
                {
                    outp.setEntry(row, col, getEntry(row, col).subtract(m.getEntry(row, col)));
                }
            }

            return(outp);
        }
コード例 #11
0
        /// <summary>
        /// Creates a column <see cref="FieldMatrix"/> using the data from the input
        /// array.
        /// </summary>
        /// <typeparam name="T">the type of the field elements</typeparam>
        /// <param name="columnData">the input column data</param>
        /// <returns>a columnData x 1 FieldMatrix</returns>
        /// <exception cref="NoDataException"> if <c>data</c> is empty.</exception>
        /// <exception cref="NullArgumentException"> if <c>columnData</c> is <c>null</c>.
        /// </exception>
        public static FieldMatrix <T> createColumnFieldMatrix <T>(T[] columnData) where T : FieldElement <T>
        {
            if (columnData == null)
            {
                throw new NullArgumentException();
            }
            int nRows = columnData.Length;

            if (nRows == 0)
            {
                throw new NoDataException(new LocalizedFormats("AT_LEAST_ONE_ROW"));
            }
            FieldMatrix <T> m = createFieldMatrix(columnData[0].getField(), nRows, 1);

            for (int i = 0; i < nRows; ++i)
            {
                m.setEntry(i, 0, columnData[i]);
            }
            return(m);
        }
コード例 #12
0
        /// <summary>
        /// Create a row <see cref="FieldMatrix"/> using the data from the input
        /// array.
        /// </summary>
        /// <typeparam name="T">the type of the field elements</typeparam>
        /// <param name="rowData">the input row data</param>
        /// <returns>a 1 x rowData.length FieldMatrix</returns>
        /// <exception cref="NoDataException"> if <c>rowData</c> is empty.</exception>
        /// <exception cref="NullArgumentException"> if <c>rowData</c> is <c>null</c>.</exception>
        public static FieldMatrix <T> createRowFieldMatrix <T>(T[] rowData) where T : FieldElement <T>
        {
            if (rowData == null)
            {
                throw new NullArgumentException();
            }
            int nCols = rowData.Length;

            if (nCols == 0)
            {
                throw new NoDataException(new LocalizedFormats("AT_LEAST_ONE_COLUMN"));
            }
            FieldMatrix <T> m = createFieldMatrix(rowData[0].getField(), 1, nCols);

            for (int i = 0; i < nCols; ++i)
            {
                m.setEntry(0, i, rowData[i]);
            }
            return(m);
        }
コード例 #13
0
 /// <inheritdoc/>
 public new void visit(int row, int column, U value)
 {
     outp.setEntry(column, row, value);
 }