org.apache.commons.math3.FieldElement Java Examples
The following examples show how to use
org.apache.commons.math3.FieldElement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a data array in blocks layout. * <p> * This method can be used to create the array argument of the {@link * #BlockFieldMatrix(int, int, FieldElement[][], boolean)} * constructor. * </p> * @param <T> Type of the field elements. * @param field Field to which the elements belong. * @param rows Number of rows in the new matrix. * @param columns Number of columns in the new matrix. * @return a new data array in blocks layout. * @see #toBlocksLayout(FieldElement[][]) * @see #BlockFieldMatrix(int, int, FieldElement[][], boolean) */ public static <T extends FieldElement<T>> T[][] createBlocksLayout(final Field<T> field, final int rows, final int columns) { final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; final T[][] blocks = MathArrays.buildArray(field, blockRows * blockColumns, -1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = MathArrays.buildArray(field, iHeight * jWidth); ++blockIndex; } } return blocks; }
Example #2
Source File: BlockFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a data array in blocks layout. * <p> * This method can be used to create the array argument of the {@link * #BlockFieldMatrix(int, int, FieldElement[][], boolean)} * constructor. * </p> * @param <T> Type of the field elements. * @param field Field to which the elements belong. * @param rows Number of rows in the new matrix. * @param columns Number of columns in the new matrix. * @return a new data array in blocks layout. * @see #toBlocksLayout(FieldElement[][]) * @see #BlockFieldMatrix(int, int, FieldElement[][], boolean) */ public static <T extends FieldElement<T>> T[][] createBlocksLayout(final Field<T> field, final int rows, final int columns) { final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; final T[][] blocks = MathArrays.buildArray(field, blockRows * blockColumns, -1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = MathArrays.buildArray(field, iHeight * jWidth); ++blockIndex; } } return blocks; }
Example #3
Source File: AbstractFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** Build an array of elements. * <p> * Complete arrays are filled with field.getZero() * </p> * @param <T> Type of the field elements * @param field field to which array elements belong * @param rows number of rows * @param columns number of columns (may be negative to build partial * arrays in the same way <code>new Field[rows][]</code> works) * @return a new array */ @SuppressWarnings("unchecked") protected static <T extends FieldElement<T>> T[][] buildArray(final Field<T> field, final int rows, final int columns) { if (columns < 0) { T[] dummyRow = (T[]) Array.newInstance(field.getRuntimeClass(), 0); return (T[][]) Array.newInstance(dummyRow.getClass(), rows); } T[][] array = (T[][]) Array.newInstance(field.getRuntimeClass(), new int[] { rows, columns }); for (int i = 0; i < array.length; ++i) { Arrays.fill(array[i], field.getZero()); } return array; }
Example #4
Source File: DerivativeStructure.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public Field<DerivativeStructure> getField() { return new Field<DerivativeStructure>() { /** {@inheritDoc} */ public DerivativeStructure getZero() { return new DerivativeStructure(compiler.getFreeParameters(), compiler.getOrder(), 0.0); } /** {@inheritDoc} */ public DerivativeStructure getOne() { return new DerivativeStructure(compiler.getFreeParameters(), compiler.getOrder(), 1.0); } /** {@inheritDoc} */ public Class<? extends FieldElement<DerivativeStructure>> getRuntimeClass() { return DerivativeStructure.class; } }; }
Example #5
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a row {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param rowData the input row data * @return a 1 x rowData.length FieldMatrix * @throws NoDataException if {@code rowData} is empty. * @throws NullArgumentException if {@code rowData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createRowFieldMatrix(final T[] rowData) throws NoDataException, NullArgumentException { if (rowData == null) { throw new NullArgumentException(); } final int nCols = rowData.length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols); for (int i = 0; i < nCols; ++i) { m.setEntry(0, i, rowData[i]); } return m; }
Example #6
Source File: BlockFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a data array in blocks layout. * <p> * This method can be used to create the array argument of the {@link * #BlockFieldMatrix(int, int, FieldElement[][], boolean)} * constructor. * </p> * @param <T> Type of the field elements. * @param field Field to which the elements belong. * @param rows Number of rows in the new matrix. * @param columns Number of columns in the new matrix. * @return a new data array in blocks layout. * @see #toBlocksLayout(FieldElement[][]) * @see #BlockFieldMatrix(int, int, FieldElement[][], boolean) */ public static <T extends FieldElement<T>> T[][] createBlocksLayout(final Field<T> field, final int rows, final int columns) { final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; final T[][] blocks = MathArrays.buildArray(field, blockRows * blockColumns, -1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = MathArrays.buildArray(field, iHeight * jWidth); ++blockIndex; } } return blocks; }
Example #7
Source File: DerivativeStructure.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public Field<DerivativeStructure> getField() { return new Field<DerivativeStructure>() { /** {@inheritDoc} */ public DerivativeStructure getZero() { return new DerivativeStructure(compiler.getFreeParameters(), compiler.getOrder(), 0.0); } /** {@inheritDoc} */ public DerivativeStructure getOne() { return new DerivativeStructure(compiler.getFreeParameters(), compiler.getOrder(), 1.0); } /** {@inheritDoc} */ public Class<? extends FieldElement<DerivativeStructure>> getRuntimeClass() { return DerivativeStructure.class; } }; }
Example #8
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a column {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param columnData the input column data * @return a columnData x 1 FieldMatrix * @throws NoDataException if {@code data} is empty. * @throws NullArgumentException if {@code columnData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createColumnFieldMatrix(final T[] columnData) throws NoDataException, NullArgumentException { if (columnData == null) { throw new NullArgumentException(); } final int nRows = columnData.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; }
Example #9
Source File: AbstractFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** Build an array of elements. * <p> * Complete arrays are filled with field.getZero() * </p> * @param <T> Type of the field elements * @param field field to which array elements belong * @param rows number of rows * @param columns number of columns (may be negative to build partial * arrays in the same way <code>new Field[rows][]</code> works) * @return a new array */ @SuppressWarnings("unchecked") protected static <T extends FieldElement<T>> T[][] buildArray(final Field<T> field, final int rows, final int columns) { if (columns < 0) { T[] dummyRow = (T[]) Array.newInstance(field.getRuntimeClass(), 0); return (T[][]) Array.newInstance(dummyRow.getClass(), rows); } T[][] array = (T[][]) Array.newInstance(field.getRuntimeClass(), new int[] { rows, columns }); for (int i = 0; i < array.length; ++i) { Arrays.fill(array[i], field.getZero()); } return array; }
Example #10
Source File: SparseFieldVector.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public FieldMatrix<T> outerProduct(FieldVector<T> v) { if (v instanceof SparseFieldVector<?>) { return outerProduct((SparseFieldVector<T>)v); } else { final int n = v.getDimension(); FieldMatrix<T> res = new SparseFieldMatrix<T>(field, virtualSize, n); OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); int row = iter.key(); FieldElement<T>value = iter.value(); for (int col = 0; col < n; col++) { res.setEntry(row, col, value.multiply(v.getEntry(col))); } } return res; } }
Example #11
Source File: SparseFieldVector.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public FieldMatrix<T> outerProduct(FieldVector<T> v) { if (v instanceof SparseFieldVector<?>) { return outerProduct((SparseFieldVector<T>)v); } else { final int n = v.getDimension(); FieldMatrix<T> res = new SparseFieldMatrix<T>(field, virtualSize, n); OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); int row = iter.key(); FieldElement<T>value = iter.value(); for (int col = 0; col < n; col++) { res.setEntry(row, col, value.multiply(v.getEntry(col))); } } return res; } }
Example #12
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a row {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param rowData the input row data * @return a 1 x rowData.length FieldMatrix * @throws NoDataException if {@code rowData} is empty. * @throws NullArgumentException if {@code rowData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createRowFieldMatrix(final T[] rowData) throws NoDataException, NullArgumentException { if (rowData == null) { throw new NullArgumentException(); } final int nCols = rowData.length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols); for (int i = 0; i < nCols; ++i) { m.setEntry(0, i, rowData[i]); } return m; }
Example #13
Source File: BlockFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a data array in blocks layout. * <p> * This method can be used to create the array argument of the {@link * #BlockFieldMatrix(int, int, FieldElement[][], boolean)} * constructor. * </p> * @param <T> Type of the field elements. * @param field Field to which the elements belong. * @param rows Number of rows in the new matrix. * @param columns Number of columns in the new matrix. * @return a new data array in blocks layout. * @see #toBlocksLayout(FieldElement[][]) * @see #BlockFieldMatrix(int, int, FieldElement[][], boolean) */ public static <T extends FieldElement<T>> T[][] createBlocksLayout(final Field<T> field, final int rows, final int columns) { final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; final T[][] blocks = buildArray(field, blockRows * blockColumns, -1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = buildArray(field, iHeight * jWidth); ++blockIndex; } } return blocks; }
Example #14
Source File: SparseFieldVector.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public FieldMatrix<T> outerProduct(FieldVector<T> v) { if (v instanceof SparseFieldVector<?>) { return outerProduct((SparseFieldVector<T>)v); } else { final int n = v.getDimension(); FieldMatrix<T> res = new SparseFieldMatrix<T>(field, virtualSize, n); OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); int row = iter.key(); FieldElement<T>value = iter.value(); for (int col = 0; col < n; col++) { res.setEntry(row, col, value.multiply(v.getEntry(col))); } } return res; } }
Example #15
Source File: DerivativeStructure.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public Field<DerivativeStructure> getField() { return new Field<DerivativeStructure>() { /** {@inheritDoc} */ public DerivativeStructure getZero() { return new DerivativeStructure(compiler.getFreeParameters(), compiler.getOrder(), 0.0); } /** {@inheritDoc} */ public DerivativeStructure getOne() { return new DerivativeStructure(compiler.getFreeParameters(), compiler.getOrder(), 1.0); } /** {@inheritDoc} */ public Class<? extends FieldElement<DerivativeStructure>> getRuntimeClass() { return DerivativeStructure.class; } }; }
Example #16
Source File: SparseFieldVector.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public FieldMatrix<T> outerProduct(FieldVector<T> v) { if (v instanceof SparseFieldVector<?>) { return outerProduct((SparseFieldVector<T>)v); } else { final int n = v.getDimension(); FieldMatrix<T> res = new SparseFieldMatrix<T>(field, virtualSize, n); OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); int row = iter.key(); FieldElement<T>value = iter.value(); for (int col = 0; col < n; col++) { res.setEntry(row, col, value.multiply(v.getEntry(col))); } } return res; } }
Example #17
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a column {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param columnData the input column data * @return a columnData x 1 FieldMatrix * @throws NoDataException if {@code data} is empty. * @throws NullArgumentException if {@code columnData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createColumnFieldMatrix(final T[] columnData) { if (columnData == null) { throw new NullArgumentException(); } final int nRows = columnData.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; }
Example #18
Source File: SparseGradient.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public Field<SparseGradient> getField() { return new Field<SparseGradient>() { /** {@inheritDoc} */ public SparseGradient getZero() { return createConstant(0); } /** {@inheritDoc} */ public SparseGradient getOne() { return createConstant(1); } /** {@inheritDoc} */ public Class<? extends FieldElement<SparseGradient>> getRuntimeClass() { return SparseGradient.class; } }; }
Example #19
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a column {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param columnData the input column data * @return a columnData x 1 FieldMatrix * @throws NoDataException if {@code data} is empty. * @throws NullArgumentException if {@code columnData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createColumnFieldMatrix(final T[] columnData) throws NoDataException, NullArgumentException { if (columnData == null) { throw new NullArgumentException(); } final int nRows = columnData.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; }
Example #20
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a column {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param columnData the input column data * @return a columnData x 1 FieldMatrix * @throws NoDataException if {@code data} is empty. * @throws NullArgumentException if {@code columnData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createColumnFieldMatrix(final T[] columnData) throws NoDataException, NullArgumentException { if (columnData == null) { throw new NullArgumentException(); } final int nRows = columnData.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; }
Example #21
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a column {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param columnData the input column data * @return a columnData x 1 FieldMatrix * @throws NoDataException if {@code data} is empty. * @throws NullArgumentException if {@code columnData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createColumnFieldMatrix(final T[] columnData) throws NoDataException, NullArgumentException { if (columnData == null) { throw new NullArgumentException(); } final int nRows = columnData.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; }
Example #22
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a row {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param rowData the input row data * @return a 1 x rowData.length FieldMatrix * @throws NoDataException if {@code rowData} is empty. * @throws NullArgumentException if {@code rowData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createRowFieldMatrix(final T[] rowData) throws NoDataException, NullArgumentException { if (rowData == null) { throw new NullArgumentException(); } final int nCols = rowData.length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols); for (int i = 0; i < nCols; ++i) { m.setEntry(0, i, rowData[i]); } return m; }
Example #23
Source File: BlockFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a data array in blocks layout. * <p> * This method can be used to create the array argument of the {@link * #BlockFieldMatrix(int, int, FieldElement[][], boolean)} * constructor. * </p> * @param <T> Type of the field elements. * @param field Field to which the elements belong. * @param rows Number of rows in the new matrix. * @param columns Number of columns in the new matrix. * @return a new data array in blocks layout. * @see #toBlocksLayout(FieldElement[][]) * @see #BlockFieldMatrix(int, int, FieldElement[][], boolean) */ public static <T extends FieldElement<T>> T[][] createBlocksLayout(final Field<T> field, final int rows, final int columns) { final int blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE; final int blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE; final T[][] blocks = buildArray(field, blockRows * blockColumns, -1); int blockIndex = 0; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int pStart = iBlock * BLOCK_SIZE; final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows); final int iHeight = pEnd - pStart; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int qStart = jBlock * BLOCK_SIZE; final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns); final int jWidth = qEnd - qStart; blocks[blockIndex] = buildArray(field, iHeight * jWidth); ++blockIndex; } } return blocks; }
Example #24
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns a diagonal matrix with specified elements. * * @param <T> the type of the field elements * @param diagonal diagonal elements of the matrix (the array elements * will be copied) * @return diagonal matrix * @since 2.0 */ public static <T extends FieldElement<T>> FieldMatrix<T> createFieldDiagonalMatrix(final T[] diagonal) { final 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; }
Example #25
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns a diagonal matrix with specified elements. * * @param <T> the type of the field elements * @param diagonal diagonal elements of the matrix (the array elements * will be copied) * @return diagonal matrix * @since 2.0 */ public static <T extends FieldElement<T>> FieldMatrix<T> createFieldDiagonalMatrix(final T[] diagonal) { final 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; }
Example #26
Source File: AbstractFieldMatrix.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Get the elements type from an array. * * @param <T> Type of the field elements. * @param d Data array. * @return the field to which the array elements belong. * @throws NullArgumentException if the array is {@code null}. * @throws NoDataException if the array is empty. */ protected static <T extends FieldElement<T>> Field<T> extractField(final T[][] d) { if (d == null) { throw new NullArgumentException(); } if (d.length == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } if (d[0].length == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } return d[0][0].getField(); }
Example #27
Source File: AbstractFieldMatrix.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Get the elements type from an array. * * @param <T> Type of the field elements. * @param d Data array. * @return the field to which the array elements belong. * @throws NullArgumentException if the array is {@code null}. * @throws NoDataException if the array is empty. */ protected static <T extends FieldElement<T>> Field<T> extractField(final T[][] d) throws NoDataException, NullArgumentException { if (d == null) { throw new NullArgumentException(); } if (d.length == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } if (d[0].length == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } return d[0][0].getField(); }
Example #28
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns <code>dimension x dimension</code> identity matrix. * * @param <T> the type of the field elements * @param field field to which the elements belong * @param dimension dimension of identity matrix to generate * @return identity matrix * @throws IllegalArgumentException if dimension is not positive * @since 2.0 */ public static <T extends FieldElement<T>> FieldMatrix<T> createFieldIdentityMatrix(final Field<T> field, final int dimension) { final T zero = field.getZero(); final T one = field.getOne(); @SuppressWarnings("unchecked") final T[][] d = (T[][]) Array.newInstance(field.getRuntimeClass(), new int[] { dimension, dimension }); for (int row = 0; row < dimension; row++) { final T[] dRow = d[row]; Arrays.fill(dRow, zero); dRow[row] = one; } return new Array2DRowFieldMatrix<T>(field, d, false); }
Example #29
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns <code>dimension x dimension</code> identity matrix. * * @param <T> the type of the field elements * @param field field to which the elements belong * @param dimension dimension of identity matrix to generate * @return identity matrix * @throws IllegalArgumentException if dimension is not positive * @since 2.0 */ public static <T extends FieldElement<T>> FieldMatrix<T> createFieldIdentityMatrix(final Field<T> field, final int dimension) { final T zero = field.getZero(); final T one = field.getOne(); final T[][] d = MathArrays.buildArray(field, dimension, dimension); for (int row = 0; row < dimension; row++) { final T[] dRow = d[row]; Arrays.fill(dRow, zero); dRow[row] = one; } return new Array2DRowFieldMatrix<T>(field, d, false); }
Example #30
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Creates a {@link FieldVector} using the data from the input array. * * @param <T> the type of the field elements * @param data the input data * @return a data.length FieldVector * @throws NoDataException if {@code data} is empty. * @throws NullArgumentException if {@code data} is {@code null}. * @throws ZeroException if {@code data} has 0 elements */ public static <T extends FieldElement<T>> FieldVector<T> createFieldVector(final T[] data) throws NoDataException, NullArgumentException, ZeroException { if (data == null) { throw new NullArgumentException(); } if (data.length == 0) { throw new ZeroException(LocalizedFormats.VECTOR_MUST_HAVE_AT_LEAST_ONE_ELEMENT); } return new ArrayFieldVector<T>(data[0].getField(), data, true); }