use of org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix in project ignite by apache.
the class MatrixViewConstructorTest method attributeTest.
/**
*/
@Test
public void attributeTest() {
for (Matrix m : new Matrix[] { new DenseMatrix(3, 3), new DenseMatrix(3, 4), new DenseMatrix(4, 3) }) {
ViewMatrix matrixView = new ViewMatrix(m, 0, 0, m.rowSize(), m.columnSize());
ViewMatrixStorage delegateStorage = (ViewMatrixStorage) matrixView.getStorage();
assertEquals(m.rowSize(), matrixView.rowSize());
assertEquals(m.columnSize(), matrixView.columnSize());
assertEquals(m.rowSize(), (delegateStorage).rowsLength());
assertEquals(m.columnSize(), (delegateStorage).columnsLength());
assertEquals(m.isDense(), delegateStorage.isDense());
assertEquals(m.isArrayBased(), delegateStorage.isArrayBased());
assertArrayEquals(m.getStorage().data(), delegateStorage.data(), 0.0);
}
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix in project ignite by apache.
the class MatrixViewConstructorTest method invalidArgsTest.
/**
*/
@Test
public void invalidArgsTest() {
Matrix m = new DenseMatrix(1, 1);
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix((Matrix) null, 0, 0, 1, 1), "Null parent matrix.");
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix(m, -1, 0, 1, 1), "Invalid row offset.");
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix(m, 0, -1, 1, 1), "Invalid col offset.");
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix(m, 0, 0, 0, 1), "Invalid rows.");
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix(m, 0, 0, 1, 0), "Invalid cols.");
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix in project ignite by apache.
the class AbstractVector method toMatrixPlusOne.
/**
* {@inheritDoc}
*/
@Override
public Matrix toMatrixPlusOne(boolean rowLike, double zeroVal) {
Matrix res = likeMatrix(rowLike ? 1 : size() + 1, rowLike ? size() + 1 : 1);
if (res == null)
return null;
res.set(0, 0, zeroVal);
if (rowLike)
new ViewMatrix(res, 0, 1, 1, size()).assignRow(0, this);
else
new ViewMatrix(res, 1, 0, size(), 1).assignColumn(0, this);
return res;
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix in project ignite by apache.
the class MatrixViewConstructorTest method basicTest.
/**
*/
private void basicTest(Matrix parent, int rowOff, int colOff, int rows, int cols) {
for (int row = 0; row < parent.rowSize(); row++) for (int col = 0; col < parent.columnSize(); col++) parent.set(row, col, row * parent.columnSize() + col + 1);
Matrix view = new ViewMatrix(parent, rowOff, colOff, rows, cols);
assertEquals("Rows in view.", rows, view.rowSize());
assertEquals("Cols in view.", cols, view.columnSize());
for (int row = 0; row < rows; row++) for (int col = 0; col < cols; col++) assertEquals("Unexpected value at " + row + "x" + col, parent.get(row + rowOff, col + colOff), view.get(row, col), 0d);
for (int row = 0; row < rows; row++) for (int col = 0; col < cols; col++) view.set(row, col, 0d);
for (int row = 0; row < rows; row++) for (int col = 0; col < cols; col++) assertEquals("Unexpected value set at " + row + "x" + col, 0d, parent.get(row + rowOff, col + colOff), 0d);
}
Aggregations