use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class BlasTest method testDot.
/**
* Test 'dot' operation.
*/
@Test
public void testDot() {
DenseVector v1 = new DenseVector(new double[] { 1.0, 1.0 });
DenseVector v2 = new DenseVector(new double[] { 2.0, 2.0 });
Assert.assertEquals(Blas.dot(v1, v2), v1.dot(v2), 0.0);
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector 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.vector.impl.DenseVector in project ignite by apache.
the class BlasTest method testSyrDenseDense.
/**
* Tests 'syr' operation for dense vector x and dense matrix A.
*/
@Test
public void testSyrDenseDense() {
double alpha = 2.0;
DenseVector x = new DenseVector(new double[] { 1.0, 2.0 });
DenseMatrix a = new DenseMatrix(new double[][] { { 10.0, 20.0 }, { 20.0, 10.0 } });
// alpha * x * x^T + A
DenseMatrix exp = (DenseMatrix) new DenseMatrix(new double[][] { { 1.0, 2.0 }, { 2.0, 4.0 } }).times(alpha).plus(a);
Blas.syr(alpha, x, a);
Assert.assertEquals(exp, a);
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class BlasTest method testSprDenseDense.
/**
* Test 'spr' operation for dense vector v and dense matrix A.
*/
@Test
public void testSprDenseDense() {
double alpha = 3.0;
DenseVector v = new DenseVector(new double[] { 1.0, 2.0 });
DenseVector u = new DenseVector(new double[] { 3.0, 13.0, 20.0, 0.0 });
// m is alpha * v * v^t
DenseMatrix m = (DenseMatrix) new DenseMatrix(new double[][] { { 1.0, 0.0 }, { 2.0, 4.0 } }, StorageConstants.COLUMN_STORAGE_MODE).times(alpha);
DenseMatrix a = new DenseMatrix(new double[][] { { 3.0, 0.0 }, { 13.0, 20.0 } }, StorageConstants.COLUMN_STORAGE_MODE);
// 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(m.plus(a), mu);
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector 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);
}
Aggregations