use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class SparseBlockDistributedVectorTest method testCopy.
/**
*/
public void testCopy() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
sparseBlockDistributedVector = new SparseBlockDistributedVector(size);
Vector cp = sparseBlockDistributedVector.copy();
assertNotNull(cp);
for (int i = 0; i < size; i++) assertEquals(UNEXPECTED_VAL, cp.get(i), sparseBlockDistributedVector.get(i), PRECISION);
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class VectorFoldMapTest method operatorTest.
/**
*/
private void operatorTest(Vector v, String desc, Function<Vector, Vector> op, Function<Double, Double> refOp) {
final int size = v.size();
final double[] ref = new double[size];
VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc);
Vector actual = op.apply(v);
for (int idx = 0; idx < size; idx++) ref[idx] = refOp.apply(ref[idx]);
checker.assertCloseEnough(actual, ref);
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class VectorFoldMapTest method operationVectorTest.
/**
*/
private void operationVectorTest(BiFunction<Double, Double, Double> operation, BiFunction<Vector, Vector, Vector> vecOperation) {
consumeSampleVectors((v, desc) -> {
// TODO: IGNTIE-5723, find out if more elaborate testing scenario is needed or it's okay as is.
final int size = v.size();
final double[] ref = new double[size];
final VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc);
final Vector operand = v.copy();
for (int idx = 0; idx < size; idx++) ref[idx] = operation.apply(ref[idx], ref[idx]);
checker.assertCloseEnough(vecOperation.apply(v, operand), ref);
});
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class VectorImplementationsTest method operationVectorTest.
/**
*/
private void operationVectorTest(BiFunction<Double, Double, Double> operation, BiFunction<Vector, Vector, Vector> vecOperation) {
consumeSampleVectors((v, desc) -> {
// TODO : IGNTIE-5723, find out if more elaborate testing scenario is needed or it's okay as is.
final int size = v.size();
final double[] ref = new double[size];
final ElementsChecker checker = new ElementsChecker(v, ref, desc);
final Vector operand = v.copy();
for (int idx = 0; idx < size; idx++) ref[idx] = operation.apply(ref[idx], ref[idx]);
checker.assertCloseEnough(vecOperation.apply(v, operand), ref);
assertWrongCardinality(v, desc, vecOperation);
});
}
use of org.apache.ignite.ml.math.Vector in project ignite by apache.
the class VectorNormTest method getDistanceSquaredTest.
/**
*/
@Test
public void getDistanceSquaredTest() {
consumeSampleVectors((v, desc) -> {
// IMPL NOTE this initialises vector
new VectorImplementationsTest.ElementsChecker(v, desc);
final int size = v.size();
final Vector vOnHeap = new DenseLocalOnHeapVector(size);
final Vector vOffHeap = new DenseLocalOffHeapVector(size);
invertValues(v, vOnHeap);
invertValues(v, vOffHeap);
for (int idx = 0; idx < size; idx++) {
final double exp = v.get(idx);
final int idxMirror = size - 1 - idx;
assertTrue("On heap vector difference at " + desc + ", idx " + idx, exp - vOnHeap.get(idxMirror) == 0);
assertTrue("Off heap vector difference at " + desc + ", idx " + idx, exp - vOffHeap.get(idxMirror) == 0);
}
// IMPL NOTE this won't mutate vOnHeap
final double exp = vOnHeap.minus(v).getLengthSquared();
final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(exp, v.getDistanceSquared(vOnHeap));
assertTrue("On heap vector not close enough at " + desc + ", " + metric, metric.closeEnough());
final VectorImplementationsTest.Metric metric1 = new VectorImplementationsTest.Metric(exp, v.getDistanceSquared(vOffHeap));
assertTrue("Off heap vector not close enough at " + desc + ", " + metric1, metric1.closeEnough());
});
}
Aggregations