Search in sources :

Example 21 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class MetaOpTests method testPredicateReduce1.

/**
 * Scalar + reduce along dimension
 *
 * @throws Exception
 */
@Test
public void testPredicateReduce1() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray arrayX = Nd4j.create(5, 5);
    INDArray exp = Nd4j.create(new float[] { 2f, 2f, 2f, 2f, 2f });
    ScalarAdd opA = new ScalarAdd(arrayX, 2.0f);
    Max opB = new Max(arrayX);
    OpDescriptor a = new OpDescriptor(opA);
    OpDescriptor b = new OpDescriptor(opB, new int[] { 1 });
    executioner.buildZ(opB, b.getDimensions());
    ReduceMetaOp metaOp = new ReduceMetaOp(a, b);
    executioner.prepareGrid(metaOp);
    executioner.exec(metaOp);
    INDArray result = opB.z();
    assertNotEquals(null, result);
    assertEquals(exp, result);
}
Also used : ReduceMetaOp(org.nd4j.linalg.api.ops.impl.meta.ReduceMetaOp) ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Max(org.nd4j.linalg.api.ops.impl.accum.Max) OpDescriptor(org.nd4j.linalg.api.ops.grid.OpDescriptor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 INDArray (org.nd4j.linalg.api.ndarray.INDArray)21 ScalarAdd (org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd)21 ScalarSet (org.nd4j.linalg.api.ops.impl.scalar.ScalarSet)4 Set (org.nd4j.linalg.api.ops.impl.transforms.Set)4 Ignore (org.junit.Ignore)3 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)3 Max (org.nd4j.linalg.api.ops.impl.accum.Max)3 PredicateMetaOp (org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp)3 GridDescriptor (org.nd4j.linalg.api.ops.grid.GridDescriptor)2 Abs (org.nd4j.linalg.api.ops.impl.transforms.Abs)2 AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)1 OpDescriptor (org.nd4j.linalg.api.ops.grid.OpDescriptor)1 Sum (org.nd4j.linalg.api.ops.impl.accum.Sum)1 ReduceMetaOp (org.nd4j.linalg.api.ops.impl.meta.ReduceMetaOp)1