use of org.nd4j.linalg.api.ops.Accumulation in project nd4j by deeplearning4j.
the class Nd4jTestsC method testScalarReduction1.
@Test
public void testScalarReduction1() {
Accumulation op = new Norm2(Nd4j.create(1).assign(1.0));
double norm2 = Nd4j.getExecutioner().execAndReturn(op).getFinalResult().doubleValue();
double norm1 = Nd4j.getExecutioner().execAndReturn(new Norm1(Nd4j.create(1).assign(1.0))).getFinalResult().doubleValue();
double sum = Nd4j.getExecutioner().execAndReturn(new Sum(Nd4j.create(1).assign(1.0))).getFinalResult().doubleValue();
assertEquals(1.0, norm2, 0.001);
assertEquals(1.0, norm1, 0.001);
assertEquals(1.0, sum, 0.001);
}
use of org.nd4j.linalg.api.ops.Accumulation in project nd4j by deeplearning4j.
the class Nd4jTestsC method testLength.
@Test
public void testLength() {
INDArray values = Nd4j.create(2, 2);
INDArray values2 = Nd4j.create(2, 2);
values.put(0, 0, 0);
values2.put(0, 0, 2);
values.put(1, 0, 0);
values2.put(1, 0, 2);
values.put(0, 1, 0);
values2.put(0, 1, 0);
values.put(1, 1, 2);
values2.put(1, 1, 2);
INDArray expected = Nd4j.repeat(Nd4j.scalar(2), 2).reshape(2, 1);
Accumulation accum = Nd4j.getOpFactory().createAccum("euclidean", values, values2);
INDArray results = Nd4j.getExecutioner().exec(accum, 1);
assertEquals(expected, results);
}