Search in sources :

Example 11 with SparseVector

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);
}
Also used : SparseVector(org.apache.ignite.ml.math.primitives.vector.impl.SparseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Aggregations

SparseVector (org.apache.ignite.ml.math.primitives.vector.impl.SparseVector)11 DenseVector (org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)9 Test (org.junit.Test)6 DenseMatrix (org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix)3 CardinalityException (org.apache.ignite.ml.math.exceptions.math.CardinalityException)2 Vector (org.apache.ignite.ml.math.primitives.vector.Vector)2 DelegatingNamedVector (org.apache.ignite.ml.math.primitives.vector.impl.DelegatingNamedVector)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 MathIllegalArgumentException (org.apache.ignite.ml.math.exceptions.math.MathIllegalArgumentException)1 NonSquareMatrixException (org.apache.ignite.ml.math.exceptions.math.NonSquareMatrixException)1 SparseMatrix (org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix)1 LabeledVector (org.apache.ignite.ml.structures.LabeledVector)1