use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class BlasTest method testAxpySparseArray.
/**
* Test 'axpy' operation for sparse vector and array-based vector.
*/
@Test
public void testAxpySparseArray() {
DenseVector y = new DenseVector(new double[] { 1.0, 2.0 });
double a = 2.0;
SparseVector x = sparseFromArray(new double[] { 1.0, 2.0 });
SparseVector exp = (SparseVector) x.times(a).plus(y);
Blas.axpy(a, x, y);
Assert.assertTrue(elementsEqual(exp, y));
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class BlasTest method testScalDense.
/**
* Test 'scal' operation for dense matrix.
*/
@Test
public void testScalDense() {
double[] data = new double[] { 1.0, 1.0 };
double alpha = 2.0;
DenseVector v = new DenseVector(data);
Vector exp = new DenseVector(data, true).times(alpha);
Blas.scal(alpha, v);
Assert.assertEquals(v, exp);
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class BlasTest method testSprSparseDense2.
/**
* Test 'spr' operation for sparse vector v (sparse in representation, sparse in fact) and dense matrix A.
*/
@Test
public void testSprSparseDense2() {
double alpha = 3.0;
SparseVector v = new SparseVector(2);
v.set(0, 1);
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 }, { 0.0, 0.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 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);
}
use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.
the class DistanceTest method setup.
/**
*/
@Before
public void setup() {
data2 = new double[] { 2.0, 1.0, 0.0 };
v1 = new DenseVector(new double[] { 0.0, 0.0, 0.0 });
v2 = new DenseVector(data2);
}
Aggregations