Search in sources :

Example 1 with Accumulation

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);
}
Also used : Norm2(org.nd4j.linalg.api.ops.impl.accum.Norm2) Norm1(org.nd4j.linalg.api.ops.impl.accum.Norm1) Sum(org.nd4j.linalg.api.ops.impl.accum.Sum) Accumulation(org.nd4j.linalg.api.ops.Accumulation) Test(org.junit.Test)

Example 2 with Accumulation

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);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Accumulation(org.nd4j.linalg.api.ops.Accumulation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Accumulation (org.nd4j.linalg.api.ops.Accumulation)2 INDArray (org.nd4j.linalg.api.ndarray.INDArray)1 Norm1 (org.nd4j.linalg.api.ops.impl.accum.Norm1)1 Norm2 (org.nd4j.linalg.api.ops.impl.accum.Norm2)1 Sum (org.nd4j.linalg.api.ops.impl.accum.Sum)1