Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#AT_LEAST_ONE_COLUMN

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#AT_LEAST_ONE_COLUMN . 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: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {
    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 2
Source File: Array2DRowRealMatrix.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new RealMatrix using the input array as the underlying
 * data array.
 * If an array is built specially in order to be embedded in a
 * RealMatrix and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.
 *
 * @param d Data for new matrix.
 * @param copyArray if {@code true}, the input array will be copied,
 * otherwise it will be referenced.
 * @throws DimensionMismatchException if {@code d} is not rectangular.
 * @throws NoDataException if {@code d} row or column dimension is zero.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @see #Array2DRowRealMatrix(double[][])
 */
public Array2DRowRealMatrix(final double[][] d, final boolean copyArray)
    throws DimensionMismatchException, NoDataException,
    NullArgumentException {
    if (copyArray) {
        copyIn(d);
    } else {
        if (d == null) {
            throw new NullArgumentException();
        }
        final int nRows = d.length;
        if (nRows == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
        }
        final int nCols = d[0].length;
        if (nCols == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
        }
        for (int r = 1; r < nRows; r++) {
            if (d[r].length != nCols) {
                throw new DimensionMismatchException(d[r].length, nCols);
            }
        }
        data = d;
    }
}
 
Example 3
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 4
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 5
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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: Array2DRowFieldMatrix.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new {@code FieldMatrix<T>} using the input array as the underlying
 * data array.
 * <p>If an array is built specially in order to be embedded in a
 * {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.</p>
 *
 * @param field Field to which the elements belong.
 * @param d Data for the new matrix.
 * @param copyArray Whether to copy or reference the input array.
 * @throws DimensionMismatchException if {@code d} is not rectangular.
 * @throws NoDataException if there are not at least one row and one column.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @see #Array2DRowFieldMatrix(FieldElement[][])
 */
public Array2DRowFieldMatrix(final Field<T> field, final T[][] d, final boolean copyArray)
    throws DimensionMismatchException, NoDataException, NullArgumentException {
    super(field);
    if (copyArray) {
        copyIn(d);
    } else {
        MathUtils.checkNotNull(d);
        final int nRows = d.length;
        if (nRows == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
        }
        final int nCols = d[0].length;
        if (nCols == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
        }
        for (int r = 1; r < nRows; r++) {
            if (d[r].length != nCols) {
                throw new DimensionMismatchException(nCols, d[r].length);
            }
        }
        data = d;
    }
}
 
Example 7
Source File: Array2DRowFieldMatrix.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new {@code FieldMatrix<T>} using the input array as the underlying
 * data array.
 * <p>If an array is built specially in order to be embedded in a
 * {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be
 * set to {@code false}. This will prevent the copying and improve
 * performance as no new array will be built and no data will be copied.</p>
 *
 * @param field Field to which the elements belong.
 * @param d Data for the new matrix.
 * @param copyArray Whether to copy or reference the input array.
 * @throws DimensionMismatchException if {@code d} is not rectangular.
 * @throws NoDataException if there are not at least one row and one column.
 * @throws NullArgumentException if {@code d} is {@code null}.
 * @see #Array2DRowFieldMatrix(FieldElement[][])
 */
public Array2DRowFieldMatrix(final Field<T> field, final T[][] d, final boolean copyArray)
    throws DimensionMismatchException, NoDataException, NullArgumentException {
    super(field);
    if (copyArray) {
        copyIn(d);
    } else {
        MathUtils.checkNotNull(d);
        final int nRows = d.length;
        if (nRows == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
        }
        final int nCols = d[0].length;
        if (nCols == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
        }
        for (int r = 1; r < nRows; r++) {
            if (d[r].length != nCols) {
                throw new DimensionMismatchException(nCols, d[r].length);
            }
        }
        data = d;
    }
}
 
Example 8
Source File: AbstractFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setSubMatrix(final T[][] subMatrix, final int row, final int column) {
    if (subMatrix == null) {
        throw new NullArgumentException();
    }
    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }

    for (int r = 1; r < nRows; ++r) {
        if (subMatrix[r].length != nCols) {
            throw new DimensionMismatchException(nCols, subMatrix[r].length);
        }
    }

    checkRowIndex(row);
    checkColumnIndex(column);
    checkRowIndex(nRows + row - 1);
    checkColumnIndex(nCols + column - 1);

    for (int i = 0; i < nRows; ++i) {
        for (int j = 0; j < nCols; ++j) {
            setEntry(row + i, column + j, subMatrix[i][j]);
        }
    }
}
 
Example 9
Source File: AbstractFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 */
public void setSubMatrix(final T[][] subMatrix, final int row, final int column)
    throws DimensionMismatchException, NoDataException, NullArgumentException,
    OutOfRangeException {
    if (subMatrix == null) {
        throw new NullArgumentException();
    }
    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }

    for (int r = 1; r < nRows; ++r) {
        if (subMatrix[r].length != nCols) {
            throw new DimensionMismatchException(nCols, subMatrix[r].length);
        }
    }

    checkRowIndex(row);
    checkColumnIndex(column);
    checkRowIndex(nRows + row - 1);
    checkColumnIndex(nCols + column - 1);

    for (int i = 0; i < nRows; ++i) {
        for (int j = 0; j < nCols; ++j) {
            setEntry(row + i, column + j, subMatrix[i][j]);
        }
    }
}
 
Example 10
Source File: Array2DRowFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void setSubMatrix(final T[][] subMatrix, final int row, final int column) {
    if (data == null) {
        if (row > 0) {
            throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
        }
        if (column > 0) {
            throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
        }
        final int nRows = subMatrix.length;
        if (nRows == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
        }

        final int nCols = subMatrix[0].length;
        if (nCols == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
        }
        data = buildArray(getField(), subMatrix.length, nCols);
        for (int i = 0; i < data.length; ++i) {
            if (subMatrix[i].length != nCols) {
                throw new DimensionMismatchException(nCols, subMatrix[i].length);
            }
            System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
        }
    } else {
        super.setSubMatrix(subMatrix, row, column);
    }

}
 
Example 11
Source File: AbstractRealMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
    throws NoDataException, OutOfRangeException,
    DimensionMismatchException, NullArgumentException {
    MathUtils.checkNotNull(subMatrix);
    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }

    for (int r = 1; r < nRows; ++r) {
        if (subMatrix[r].length != nCols) {
            throw new DimensionMismatchException(nCols, subMatrix[r].length);
        }
    }

    MatrixUtils.checkRowIndex(this, row);
    MatrixUtils.checkColumnIndex(this, column);
    MatrixUtils.checkRowIndex(this, nRows + row - 1);
    MatrixUtils.checkColumnIndex(this, nCols + column - 1);

    for (int i = 0; i < nRows; ++i) {
        for (int j = 0; j < nCols; ++j) {
            setEntry(row + i, column + j, subMatrix[i][j]);
        }
    }
}
 
Example 12
Source File: AbstractFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setSubMatrix(final T[][] subMatrix, final int row, final int column) {
    if (subMatrix == null) {
        throw new NullArgumentException();
    }
    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }

    for (int r = 1; r < nRows; ++r) {
        if (subMatrix[r].length != nCols) {
            throw new DimensionMismatchException(nCols, subMatrix[r].length);
        }
    }

    checkRowIndex(row);
    checkColumnIndex(column);
    checkRowIndex(nRows + row - 1);
    checkColumnIndex(nCols + column - 1);

    for (int i = 0; i < nRows; ++i) {
        for (int j = 0; j < nCols; ++j) {
            setEntry(row + i, column + j, subMatrix[i][j]);
        }
    }
}
 
Example 13
Source File: Array2DRowFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void setSubMatrix(final T[][] subMatrix, final int row,
                         final int column)
    throws OutOfRangeException, NullArgumentException, NoDataException,
    DimensionMismatchException {
    if (data == null) {
        if (row > 0) {
            throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
        }
        if (column > 0) {
            throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
        }
        final int nRows = subMatrix.length;
        if (nRows == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
        }

        final int nCols = subMatrix[0].length;
        if (nCols == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
        }
        data = MathArrays.buildArray(getField(), subMatrix.length, nCols);
        for (int i = 0; i < data.length; ++i) {
            if (subMatrix[i].length != nCols) {
                throw new DimensionMismatchException(nCols, subMatrix[i].length);
            }
            System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
        }
    } else {
        super.setSubMatrix(subMatrix, row, column);
    }

}
 
Example 14
Source File: AbstractFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setSubMatrix(final T[][] subMatrix, final int row,
                         final int column)
    throws DimensionMismatchException, OutOfRangeException,
    NoDataException, NullArgumentException {
    if (subMatrix == null) {
        throw new NullArgumentException();
    }
    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }

    for (int r = 1; r < nRows; ++r) {
        if (subMatrix[r].length != nCols) {
            throw new DimensionMismatchException(nCols, subMatrix[r].length);
        }
    }

    checkRowIndex(row);
    checkColumnIndex(column);
    checkRowIndex(nRows + row - 1);
    checkColumnIndex(nCols + column - 1);

    for (int i = 0; i < nRows; ++i) {
        for (int j = 0; j < nCols; ++j) {
            setEntry(row + i, column + j, subMatrix[i][j]);
        }
    }
}
 
Example 15
Source File: AbstractRealMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
    throws NoDataException, OutOfRangeException,
    DimensionMismatchException, NullArgumentException {
    MathUtils.checkNotNull(subMatrix);
    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }

    for (int r = 1; r < nRows; ++r) {
        if (subMatrix[r].length != nCols) {
            throw new DimensionMismatchException(nCols, subMatrix[r].length);
        }
    }

    MatrixUtils.checkRowIndex(this, row);
    MatrixUtils.checkColumnIndex(this, column);
    MatrixUtils.checkRowIndex(this, nRows + row - 1);
    MatrixUtils.checkColumnIndex(this, nCols + column - 1);

    for (int i = 0; i < nRows; ++i) {
        for (int j = 0; j < nCols; ++j) {
            setEntry(row + i, column + j, subMatrix[i][j]);
        }
    }
}
 
Example 16
Source File: Array2DRowRealMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void setSubMatrix(final double[][] subMatrix,
                         final int row, final int column) {
    if (data == null) {
        if (row > 0) {
            throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
        }
        if (column > 0) {
            throw new MathIllegalStateException(LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
        }
        MathUtils.checkNotNull(subMatrix);
        final int nRows = subMatrix.length;
        if (nRows == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
        }

        final int nCols = subMatrix[0].length;
        if (nCols == 0) {
            throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
        }
        data = new double[subMatrix.length][nCols];
        for (int i = 0; i < data.length; ++i) {
            if (subMatrix[i].length != nCols) {
                throw new DimensionMismatchException(subMatrix[i].length, nCols);
            }
            System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
        }
    } else {
        super.setSubMatrix(subMatrix, row, column);
    }

}
 
Example 17
Source File: AbstractFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 18
Source File: AbstractFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setSubMatrix(final T[][] subMatrix, final int row,
                         final int column)
    throws DimensionMismatchException, OutOfRangeException,
    NoDataException, NullArgumentException {
    if (subMatrix == null) {
        throw new NullArgumentException();
    }
    final int nRows = subMatrix.length;
    if (nRows == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }

    for (int r = 1; r < nRows; ++r) {
        if (subMatrix[r].length != nCols) {
            throw new DimensionMismatchException(nCols, subMatrix[r].length);
        }
    }

    checkRowIndex(row);
    checkColumnIndex(column);
    checkRowIndex(nRows + row - 1);
    checkColumnIndex(nCols + column - 1);

    for (int i = 0; i < nRows; ++i) {
        for (int j = 0; j < nCols; ++j) {
            setEntry(row + i, column + j, subMatrix[i][j]);
        }
    }
}
 
Example 19
Source File: BlockFieldMatrix.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void setSubMatrix(final T[][] subMatrix, final int row, final int column) {
    // safety checks
    MathUtils.checkNotNull(subMatrix);
    final int refLength = subMatrix[0].length;
    if (refLength == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }
    final int endRow    = row + subMatrix.length - 1;
    final int endColumn = column + refLength - 1;
    checkSubMatrixIndex(row, endRow, column, endColumn);
    for (final T[] subRow : subMatrix) {
        if (subRow.length != refLength) {
            throw new DimensionMismatchException(refLength, subRow.length);
        }
    }

    // compute blocks bounds
    final int blockStartRow    = row / BLOCK_SIZE;
    final int blockEndRow      = (endRow + BLOCK_SIZE) / BLOCK_SIZE;
    final int blockStartColumn = column / BLOCK_SIZE;
    final int blockEndColumn   = (endColumn + BLOCK_SIZE) / BLOCK_SIZE;

    // perform copy block-wise, to ensure good cache behavior
    for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) {
        final int iHeight  = blockHeight(iBlock);
        final int firstRow = iBlock * BLOCK_SIZE;
        final int iStart   = FastMath.max(row,    firstRow);
        final int iEnd     = FastMath.min(endRow + 1, firstRow + iHeight);

        for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) {
            final int jWidth      = blockWidth(jBlock);
            final int firstColumn = jBlock * BLOCK_SIZE;
            final int jStart      = FastMath.max(column,    firstColumn);
            final int jEnd        = FastMath.min(endColumn + 1, firstColumn + jWidth);
            final int jLength     = jEnd - jStart;

            // handle one block, row by row
            final T[] block = blocks[iBlock * blockColumns + jBlock];
            for (int i = iStart; i < iEnd; ++i) {
                System.arraycopy(subMatrix[i - row], jStart - column,
                                 block, (i - firstRow) * jWidth + (jStart - firstColumn),
                                 jLength);
            }

        }
    }
}
 
Example 20
Source File: BlockFieldMatrix.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void setSubMatrix(final T[][] subMatrix, final int row,
                         final int column)
    throws DimensionMismatchException, OutOfRangeException,
    NoDataException, NullArgumentException {
    // safety checks
    MathUtils.checkNotNull(subMatrix);
    final int refLength = subMatrix[0].length;
    if (refLength == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }
    final int endRow    = row + subMatrix.length - 1;
    final int endColumn = column + refLength - 1;
    checkSubMatrixIndex(row, endRow, column, endColumn);
    for (final T[] subRow : subMatrix) {
        if (subRow.length != refLength) {
            throw new DimensionMismatchException(refLength, subRow.length);
        }
    }

    // compute blocks bounds
    final int blockStartRow    = row / BLOCK_SIZE;
    final int blockEndRow      = (endRow + BLOCK_SIZE) / BLOCK_SIZE;
    final int blockStartColumn = column / BLOCK_SIZE;
    final int blockEndColumn   = (endColumn + BLOCK_SIZE) / BLOCK_SIZE;

    // perform copy block-wise, to ensure good cache behavior
    for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) {
        final int iHeight  = blockHeight(iBlock);
        final int firstRow = iBlock * BLOCK_SIZE;
        final int iStart   = FastMath.max(row,    firstRow);
        final int iEnd     = FastMath.min(endRow + 1, firstRow + iHeight);

        for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) {
            final int jWidth      = blockWidth(jBlock);
            final int firstColumn = jBlock * BLOCK_SIZE;
            final int jStart      = FastMath.max(column,    firstColumn);
            final int jEnd        = FastMath.min(endColumn + 1, firstColumn + jWidth);
            final int jLength     = jEnd - jStart;

            // handle one block, row by row
            final T[] block = blocks[iBlock * blockColumns + jBlock];
            for (int i = iStart; i < iEnd; ++i) {
                System.arraycopy(subMatrix[i - row], jStart - column,
                                 block, (i - firstRow) * jWidth + (jStart - firstColumn),
                                 jLength);
            }

        }
    }
}