Java Code Examples for org.apache.commons.math.exception.util.LocalizedFormats#EMPTY_SELECTED_ROW_INDEX_ARRAY

The following examples show how to use org.apache.commons.math.exception.util.LocalizedFormats#EMPTY_SELECTED_ROW_INDEX_ARRAY . 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
/**
 * Check if submatrix ranges indices are valid.
 * Rows and columns are indicated counting from 0 to n-1.
 *
 * @param m Matrix.
 * @param selectedRows Array of row indices.
 * @param selectedColumns Array of column indices.
 * @throws NullArgumentException if {@code selectedRows} or
 * {@code selectedColumns} are {@code null}.
 * @throws NoDataException if the row or column selections are empty (zero
 * length).
 * @throws OutOfRangeException if row or column selections are not valid.
 */
public static void checkSubMatrixIndex(final AnyMatrix m,
                                       final int[] selectedRows,
                                       final int[] selectedColumns) {
    if (selectedRows == null) {
        throw new NullArgumentException();
    }
    if (selectedColumns == null) {
        throw new NullArgumentException();
    }
    if (selectedRows.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
    }
    if (selectedColumns.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
    }

    for (final int row : selectedRows) {
        checkRowIndex(m, row);
    }
    for (final int column : selectedColumns) {
        checkColumnIndex(m, column);
    }
}
 
Example 2
Source File: AbstractFieldMatrix.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check if submatrix ranges indices are valid.
 * Rows and columns are indicated counting from 0 to n-1.
 *
 * @param selectedRows Array of row indices.
 * @param selectedColumns Array of column indices.
 * @exception MatrixIndexException if row or column selections are not valid
 */
protected void checkSubMatrixIndex(final int[] selectedRows, final int[] selectedColumns) {
    if (selectedRows.length * selectedColumns.length == 0) {
        if (selectedRows.length == 0) {
            throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
        }
        throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
    }

    for (final int row : selectedRows) {
        checkRowIndex(row);
    }
    for (final int column : selectedColumns) {
        checkColumnIndex(column);
    }
}
 
Example 3
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check if submatrix ranges indices are valid.
 * Rows and columns are indicated counting from 0 to n-1.
 *
 * @param m matrix containing the submatrix
 * @param selectedRows Array of row indices.
 * @param selectedColumns Array of column indices.
 * @exception MatrixIndexException if row or column selections are not valid
 */
public static void checkSubMatrixIndex(final AnyMatrix m,
                                       final int[] selectedRows, final int[] selectedColumns)
    throws MatrixIndexException {
    if (selectedRows.length * selectedColumns.length == 0) {
        if (selectedRows.length == 0) {
            throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
        }
        throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
    }

    for (final int row : selectedRows) {
        checkRowIndex(m, row);
    }
    for (final int column : selectedColumns) {
        checkColumnIndex(m, column);
    }
}
 
Example 4
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check if submatrix ranges indices are valid.
 * Rows and columns are indicated counting from 0 to n-1.
 *
 * @param m Matrix.
 * @param selectedRows Array of row indices.
 * @param selectedColumns Array of column indices.
 * @throws NullArgumentException if {@code selectedRows} or
 * {@code selectedColumns} are {@code null}.
 * @throws NoDataException if the row or column selections are empty (zero
 * length).
 * @throws OutOfRangeException if row or column selections are not valid.
 */
public static void checkSubMatrixIndex(final AnyMatrix m,
                                       final int[] selectedRows,
                                       final int[] selectedColumns) {
    if (selectedRows == null) {
        throw new NullArgumentException();
    }
    if (selectedColumns == null) {
        throw new NullArgumentException();
    }
    if (selectedRows.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
    }
    if (selectedColumns.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
    }

    for (final int row : selectedRows) {
        checkRowIndex(m, row);
    }
    for (final int column : selectedColumns) {
        checkColumnIndex(m, column);
    }
}
 
Example 5
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check if submatrix ranges indices are valid.
 * Rows and columns are indicated counting from 0 to n-1.
 *
 * @param m Matrix.
 * @param selectedRows Array of row indices.
 * @param selectedColumns Array of column indices.
 * @throws NullArgumentException if {@code selectedRows} or
 * {@code selectedColumns} are {@code null}.
 * @throws NoDataException if the row or column selections are empty (zero
 * length).
 * @throws OutOfRangeException if row or column selections are not valid.
 */
public static void checkSubMatrixIndex(final AnyMatrix m,
                                       final int[] selectedRows,
                                       final int[] selectedColumns) {
    if (selectedRows == null) {
        throw new NullArgumentException();
    }
    if (selectedColumns == null) {
        throw new NullArgumentException();
    }
    if (selectedRows.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
    }
    if (selectedColumns.length == 0) {
        throw new NoDataException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
    }

    for (final int row : selectedRows) {
        checkRowIndex(m, row);
    }
    for (final int column : selectedColumns) {
        checkColumnIndex(m, column);
    }
}
 
Example 6
Source File: BigMatrixImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a submatrix. Rows and columns are indicated
 * counting from 0 to n-1.
 *
 * @param selectedRows Array of row indices must be non-empty
 * @param selectedColumns Array of column indices must be non-empty
 * @return The subMatrix containing the data in the
 *     specified rows and columns
 * @exception MatrixIndexException  if supplied row or column index arrays
 *     are not valid
 */
public BigMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
    throws MatrixIndexException {

    if (selectedRows.length * selectedColumns.length == 0) {
        if (selectedRows.length == 0) {
            throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY);
        }
        throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY);
    }

    final BigDecimal[][] subMatrixData =
        new BigDecimal[selectedRows.length][selectedColumns.length];
    try  {
        for (int i = 0; i < selectedRows.length; i++) {
            final BigDecimal[] subI = subMatrixData[i];
            final BigDecimal[] dataSelectedI = data[selectedRows[i]];
            for (int j = 0; j < selectedColumns.length; j++) {
                subI[j] = dataSelectedI[selectedColumns[j]];
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        // we redo the loop with checks enabled
        // in order to generate an appropriate message
        for (final int row : selectedRows) {
            MatrixUtils.checkRowIndex(this, row);
        }
        for (final int column : selectedColumns) {
            MatrixUtils.checkColumnIndex(this, column);
        }
    }
    return new BigMatrixImpl(subMatrixData, false);
}