use of org.apache.ignite.ml.math.primitives.vector.impl.SparseVector in project ignite by apache.
the class BlasTest method testSprSparseDense1.
/**
* Test 'spr' operation for sparse vector v (sparse in representation, dense in fact) and dense matrix A.
*/
@Test
public void testSprSparseDense1() {
double alpha = 3.0;
SparseVector v = sparseFromArray(new double[] { 1.0, 2.0 });
DenseVector u = new DenseVector(new double[] { 3.0, 13.0, 20.0, 0.0 });
DenseMatrix a = new DenseMatrix(new double[][] { { 3.0, 0.0 }, { 13.0, 20.0 } }, StorageConstants.COLUMN_STORAGE_MODE);
DenseMatrix exp = (DenseMatrix) new DenseMatrix(new double[][] { { 1.0, 0.0 }, { 2.0, 4.0 } }, StorageConstants.COLUMN_STORAGE_MODE).times(alpha).plus(a);
// m := alpha * v * v.t + A
Blas.spr(alpha, v, u);
DenseMatrix mu = fromVector(u, a.rowSize(), StorageConstants.COLUMN_STORAGE_MODE, (i, j) -> i >= j);
Assert.assertEquals(exp, mu);
}
Aggregations