Hi Phil,

As I do not have any CVS set up, so I do it this way:

4) Add the following new methods to both RealMatrix and BigMatrix interfaces:
RealMatrix getSubMatrix (int startRow, int endRow, int startColumn,
int endColumn)
RealMatrix getSubMatrix (int[] rows, int[] columns)
RealMatrix getRowMatrix(int row)
RealMatrix getColumnMatrix(int row)
RealMatrix createRowMatrix(double[] row)
RealMatrix createColumnMatrix(double[] column)

/** * Get a submatrix. Rows and columns are indicated * counting from 0 to n-1. * * @param startRow Initial row index * @param endRow Final row index * @param startColumn Initial column index * @param endColumn Final column index * @return The subMatrix containing the data of the * specified rows and columns * @exception MatrixIndexException matrix dimension * mismatch */ public RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn) throws MatrixIndexException { RealMatrix subMatrix = new RealMatrix(endRow - startRow + 1, endColumn - startColumn + 1); double[][] subMatrixData = subMatrix.getDataRef(); try { for (int i = startRow; i <= endRow; i++) { for (int j = startColumn; j <= endColumn; j++) { subMatrixData[i - startRow][j - startColumn] = data[i][j]; } } } catch (ArrayIndexOutOfBoundsException e) { throw new MatrixIndexException("matrix dimension mismatch"); } return subMatrix; }

/**
 * Get a submatrix. Rows and columns are indicated
 * counting from 0 to n-1.
 *
 * @param rows Array of row indices.
 * @param columns Array of column indices.
 * @return The subMatrix containing the data of the
 *         specified rows and columns
 * @exception MatrixIndexException matrix dimension
 *                mismatch
 */
public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
                        throws MatrixIndexException
{
  RealMatrix subMatrix = new RealMatrix(selectedRows.length,
                                selectedColumns.length);
  double[][] subMatrixData = subMatrix.getDataRef();
  try
  {
    for (int i = 0; i < selectedRows.length; i++)
    {
       for (int j = 0; j < selectedColumns.length; j++)
       {
          subMatrixData[i][j] = data[selectedRows[i]][selectedColumns[j]];
       }
    }
  }
  catch (ArrayIndexOutOfBoundsException e)
  {
    throw new MatrixIndexException("matrix dimension mismatch");
  }
  return subMatrix;
}

/**
 * Returns the entries in row number <code>row</code>
 * as a Matrix object.
 *
 * @param row the row to be fetched
 * @return RealMatrix with only one row
 * @throws MatrixIndexException if the specified row is
 *             greater than the number of rows in this
 *             matrix
 */
public Matrix getRowMatrix(int row) throws MatrixIndexException
{
  if (!isValidCoordinate(row, 0)) { throw new MatrixIndexException(
                                "illegal row argument"); }
  double[][] out = new double[1][columns];
  for (int y = 0; y < columns; y++)
  {
    out[0][y] = data[row][y];
  }
  return new RealMatrix (out);
}

/**
 * Returns the entries in column number <code>col</code>
 * as a RealMatrix object.
 *
 * @param col column to fetch
 * @return RealMatrix with only one column
 * @throws MatrixIndexException if the specified column
 *             is greater than the number of columns in
 *             this matrix
 */
public RealMatrix getColumnMatrix(int col) throws MatrixIndexException
{
  if (!isValidCoordinate(0, col)) { throw new MatrixIndexException(
                                "illegal row argument"); }
                
  double[][] out = new double[rows][1];
  for (int y = 0; y < rows; y++)
  {
    out[y][0] = data[y][col];
  }
  return new RealMatrix (out);
}

I do not have ready to use code for the last two methods.

I might have missed to add some 'Real's before the Matrix names....

Cheers,

Kim

--
http://www.kimvdlinde.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to