use of org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix in project ignite by apache.
the class BlasTest method testGemvSparseDenseDense.
/**
* Tests 'gemv' operation for dense matrix A, dense vector x and dense vector y.
*/
@Test
public void testGemvSparseDenseDense() {
// y := alpha * A * x + beta * y
double alpha = 3.0;
SparseMatrix a = (SparseMatrix) new SparseMatrix(2, 2).assign(new double[][] { { 10.0, 11.0 }, { 0.0, 1.0 } });
DenseVector x = new DenseVector(new double[] { 1.0, 2.0 });
double beta = 2.0;
DenseVector y = new DenseVector(new double[] { 3.0, 4.0 });
DenseVector exp = (DenseVector) y.times(beta).plus(a.times(x).times(alpha));
Blas.gemv(alpha, a, x, beta, y);
Assert.assertEquals(exp, y);
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix in project ignite by apache.
the class BlasTest method testGemvDenseSparseDense.
/**
* Tests 'gemv' operation for dense matrix A, sparse vector x and dense vector y.
*/
@Test
public void testGemvDenseSparseDense() {
// y := alpha * A * x + beta * y
double alpha = 3.0;
SparseMatrix a = (SparseMatrix) new SparseMatrix(2, 2).assign(new double[][] { { 10.0, 11.0 }, { 0.0, 1.0 } });
SparseVector x = sparseFromArray(new double[] { 1.0, 2.0 });
double beta = 2.0;
DenseVector y = new DenseVector(new double[] { 3.0, 4.0 });
DenseVector exp = (DenseVector) y.times(beta).plus(a.times(x).times(alpha));
Blas.gemv(alpha, a, x, beta, y);
Assert.assertEquals(exp, y);
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix in project ignite by apache.
the class SparseMatrixConstructorTest method basicTest.
/**
*/
@Test
public void basicTest() {
assertEquals("Expected number of rows.", 1, new SparseMatrix(1, 2).rowSize());
assertEquals("Expected number of cols, int parameters.", 1, new SparseMatrix(2, 1).columnSize());
SparseMatrix m = new SparseMatrix(1, 1);
// noinspection EqualsWithItself
assertTrue("Matrix is expected to be equal to self.", m.equals(m));
assertFalse("Matrix is expected to be not equal to null.", m.equals(null));
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix in project ignite by apache.
the class BlasTest method testGemmSparseDenseDense.
/**
* Tests 'gemm' operation for sparse matrix A, dense matrix B and dense matrix C.
*/
@Test
public void testGemmSparseDenseDense() {
// C := alpha * A * B + beta * C
double alpha = 1.0;
SparseMatrix a = (SparseMatrix) new SparseMatrix(2, 2).assign(new double[][] { { 10.0, 11.0 }, { 0.0, 1.0 } });
DenseMatrix b = new DenseMatrix(new double[][] { { 1.0, 0.3 }, { 0.0, 1.0 } });
double beta = 0.0;
DenseMatrix c = new DenseMatrix(new double[][] { { 1.0, 2.0 }, { 2.0, 3.0 } });
// .times(alpha).plus(c.times(beta));
Matrix exp = a.times(b);
Blas.gemm(alpha, a, b, beta, c);
Assert.assertTrue(Arrays.equals(exp.getStorage().data(), c.getStorage().data()));
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix in project ignite by apache.
the class SparseMatrixConstructorTest method invalidArgsTest.
/**
*/
@Test
public void invalidArgsTest() {
DenseMatrixConstructorTest.verifyAssertionError(() -> new SparseMatrix(0, 1), "invalid row parameter");
DenseMatrixConstructorTest.verifyAssertionError(() -> new SparseMatrix(1, 0), "invalid col parameter");
}
Aggregations