Skip to content

Commit

Permalink
Deprecate rows/cols in favour of getRows/getColumns
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozsef Kutas committed Jun 26, 2023
1 parent 6944517 commit 50ed7b3
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 54 deletions.
58 changes: 40 additions & 18 deletions main/ejml-simple/src/org/ejml/simple/ConstMatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,46 @@ default int getNumElements() {
*/
T getColumn( int col );

/**
* Extracts the specified rows from the matrix.
*
* @param begin First row (inclusive).
* @param end Last row (exclusive).
* @return Submatrix that contains the specified rows.
* @deprecated Inconsistent API. Use {@link #getRows(int, int)} instead.
*/
@Deprecated
T rows( int begin, int end );

/**
* Extracts the specified rows from the matrix.
*
* @param begin First row (inclusive).
* @param end Last row (exclusive).
* @return Submatrix that contains the specified rows.
*/
T getRows( int begin, int end );

/**
* Extracts the specified columns from the matrix.
*
* @param begin First column (inclusive).
* @param end Last column (exclusive).
* @return Submatrix that contains the specified columns.
* @deprecated Inconsistent API. Use {@link #getColumns(int, int)} instead.
*/
@Deprecated
T cols( int begin, int end );

/**
* Extracts the specified columns from the matrix.
*
* @param begin First column (inclusive).
* @param end Last column (exclusive).
* @return Submatrix that contains the specified columns.
*/
T getColumns( int begin, int end );

/**
* <p>
* If a vector then a square matrix is returned if a matrix then a vector of diagonal ements is returned
Expand Down Expand Up @@ -750,24 +790,6 @@ default int getNumElements() {
*/
int bits();

/**
* Extracts the specified rows from the matrix.
*
* @param begin First row (inclusive).
* @param end Last row (exclusive).
* @return Submatrix that contains the specified rows.
*/
T rows( int begin, int end );

/**
* Extracts the specified columns from the matrix.
*
* @param begin First column (inclusive).
* @param end Last column (exclusive).
* @return Submatrix that contains the specified columns.
*/
T cols( int begin, int end );

/**
* <p>Concatenates all the matrices together along their columns. If the rows do not match the upper elements
* are set to zero.</p>
Expand Down
32 changes: 22 additions & 10 deletions main/ejml-simple/src/org/ejml/simple/SimpleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,28 @@ public void setColumn( int column, ConstMatrix<?> src ) {
// NOTE: For sparse to sparse this method is very inefficient...
}

/** {@inheritDoc} */
@Deprecated
@Override public T rows( int begin, int end ) {
return extractMatrix(begin, end, 0, SimpleMatrix.END);
}

/** {@inheritDoc} */
@Override public T getRows( int begin, int end ) {
return extractMatrix(begin, end, 0, SimpleMatrix.END);
}

/** {@inheritDoc} */
@Deprecated
@Override public T cols( int begin, int end ) {
return extractMatrix(0, SimpleMatrix.END, begin, end);
}

/** {@inheritDoc} */
@Override public T getColumns( int begin, int end ) {
return extractMatrix(0, SimpleMatrix.END, begin, end);
}

/**
* Converts a real array/vector into a complex one by setting imaginary component to zero
*/
Expand Down Expand Up @@ -1321,16 +1343,6 @@ public void printDimensions() {
return (T)combined;
}

/** {@inheritDoc} */
@Override public T rows( int begin, int end ) {
return extractMatrix(begin, end, 0, SimpleMatrix.END);
}

/** {@inheritDoc} */
@Override public T cols( int begin, int end ) {
return extractMatrix(0, SimpleMatrix.END, begin, end);
}

/** {@inheritDoc} */
@Override public MatrixType getType() {
return mat.getType();
Expand Down
8 changes: 4 additions & 4 deletions main/ejml-simple/src/org/ejml/simple/SimpleMatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@
* <td>Get the {@code i}<sup>th</sup> row.</td></tr>
* <tr><td>{@link #getColumn(int)}</td>
* <td>Get the {@code j}<sup>th</sup> column.</td></tr>
* <tr><td>{@link #getRows(int, int)}</td>
* <td>Extract the specified rows.</td></tr>
* <tr><td>{@link #getColumns(int, int)}</td>
* <td>Extract the specified columns.</td></tr>
* <tr><td>{@link #extractVector(boolean, int)}</td>
* <td>Extract the specified row or column vector.</td></tr>
* <tr><td>{@link #extractMatrix(int, int, int, int)}</td>
* <td>Extract the specified submatrix.</td></tr>
* <tr><td>{@link #rows(int, int)}</td>
* <td>Extract the specified rows.</td></tr>
* <tr><td>{@link #cols(int, int)}</td>
* <td>Extract the specified columns.</td></tr>
* <tr><td>{@link #diag()}</td>
* <td>Extract the matrix diagonal, or construct a diagonal matrix from a vector.</td></tr>
* </table>
Expand Down
44 changes: 22 additions & 22 deletions main/ejml-simple/test/org/ejml/simple/TestSimpleMatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,28 @@ void setColumn_SimpleMatrix_real_complex( SimpleMatrix a, SimpleMatrix b ) {
}
}

@Test void getRows() {
SimpleMatrix A = SimpleMatrix.random_DDRM(5, 7, -1, 1, rand);
SimpleMatrix B = A.getRows(1, 3);

for (int i = 1; i < 3; i++) {
for (int j = 0; j < 7; j++) {
assertEquals(A.get(i, j), B.get(i - 1, j), UtilEjml.TEST_F64);
}
}
}

@Test void getColumns() {
SimpleMatrix A = SimpleMatrix.random_DDRM(5, 7, -1, 1, rand);
SimpleMatrix B = A.getColumns(2, 4);

for (int i = 0; i < 5; i++) {
for (int j = 2; j < 4; j++) {
assertEquals(A.get(i, j), B.get(i, j - 2), UtilEjml.TEST_F64);
}
}
}

@Test void get_2d() {
SimpleMatrix a = SimpleMatrix.random_DDRM(3, 3, 0, 1, rand);

Expand Down Expand Up @@ -1246,28 +1268,6 @@ void setColumn_SimpleMatrix_real_complex( SimpleMatrix a, SimpleMatrix b ) {
assertTrue(C.isIdentical(D, UtilEjml.TEST_F64));
}

@Test void rows() {
SimpleMatrix A = SimpleMatrix.random_DDRM(5, 7, -1, 1, rand);
SimpleMatrix B = A.rows(1, 3);

for (int i = 1; i < 3; i++) {
for (int j = 0; j < 7; j++) {
assertEquals(A.get(i, j), B.get(i - 1, j), UtilEjml.TEST_F64);
}
}
}

@Test void cols() {
SimpleMatrix A = SimpleMatrix.random_DDRM(5, 7, -1, 1, rand);
SimpleMatrix B = A.rows(1, 3);

for (int i = 1; i < 3; i++) {
for (int j = 0; j < 7; j++) {
assertEquals(A.get(i, j), B.get(i - 1, j), UtilEjml.TEST_F64);
}
}
}

@Test void serialization() {
List<Matrix> matrixTypes = new ArrayList<>();
matrixTypes.add(new DMatrixRMaj(2, 3));
Expand Down

0 comments on commit 50ed7b3

Please sign in to comment.