use of org.apache.ignite.ml.math.Matrix in project ignite by apache.
the class MatrixImplementationsTest method testMinusMatrix.
/**
*/
@Test
public void testMinusMatrix() {
consumeSampleMatrix((m, desc) -> {
if (ignore(m.getClass()))
return;
fillMatrix(m);
Matrix minus = m.minus(m);
for (int i = 0; i < m.rowSize(); i++) for (int j = 0; j < m.columnSize(); j++) assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")", 0.0, minus.get(i, j), 0d);
});
}
use of org.apache.ignite.ml.math.Matrix in project ignite by apache.
the class MatrixImplementationsTest method testCopy.
/**
*/
@Test
public void testCopy() {
consumeSampleMatrix((m, desc) -> {
Matrix cp = m.copy();
assertTrue("Incorrect copy for empty matrix " + desc, cp.equals(m));
if (!readOnly(m))
fillMatrix(m);
cp = m.copy();
assertTrue("Incorrect copy for matrix " + desc, cp.equals(m));
});
}
use of org.apache.ignite.ml.math.Matrix in project ignite by apache.
the class MatrixImplementationsTest method testTimesMatrix.
/**
*/
@Test
public void testTimesMatrix() {
consumeSampleMatrix((m, desc) -> {
if (ignore(m.getClass()))
return;
if (m instanceof DenseLocalOffHeapMatrix)
return;
double[][] data = fillAndReturn(m);
double[] arr = fillArray(m.columnSize());
Matrix mult = m.like(m.columnSize(), 1);
mult.setColumn(0, arr);
Matrix times = m.times(mult);
assertEquals("Unexpected rows for " + desc, times.rowSize(), m.rowSize());
assertEquals("Unexpected cols for " + desc, times.columnSize(), 1);
for (int i = 0; i < m.rowSize(); i++) {
double exp = 0.0;
for (int j = 0; j < m.columnSize(); j++) exp += arr[j] * data[i][j];
assertEquals("Unexpected value for " + desc + " at " + i, exp, times.get(i, 0), DEFAULT_DELTA);
}
testInvalidCardinality(() -> m.times(new DenseLocalOnHeapMatrix(m.columnSize() + 1, 1)), desc);
});
}
use of org.apache.ignite.ml.math.Matrix in project ignite by apache.
the class MatrixImplementationsTest method testTranspose.
/**
*/
@Test
public void testTranspose() {
consumeSampleMatrix((m, desc) -> {
if (ignore(m.getClass()))
return;
fillMatrix(m);
Matrix transpose = m.transpose();
for (int i = 0; i < m.rowSize(); i++) for (int j = 0; j < m.columnSize(); j++) assertEquals("Unexpected value for " + desc + " at (" + i + "," + j + ")", m.get(i, j), transpose.get(j, i), 0d);
});
}
use of org.apache.ignite.ml.math.Matrix in project ignite by apache.
the class MatrixImplementationsTest method testLike.
/**
*/
@Test
public void testLike() {
consumeSampleMatrix((m, desc) -> {
Class<? extends Matrix> cls = likeMatrixType(m);
if (cls != null) {
Matrix like = m.like(m.rowSize(), m.columnSize());
assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected rows.", like.rowSize(), m.rowSize());
assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected columns.", like.columnSize(), m.columnSize());
assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected class: " + like.getClass().toString(), cls, like.getClass());
return;
}
boolean expECaught = false;
try {
m.like(1, 1);
} catch (UnsupportedOperationException uoe) {
expECaught = true;
}
assertTrue("Expected exception was not caught for " + desc, expECaught);
});
}
Aggregations