Search in sources :

Example 16 with ScalarAdd

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

the class GridExecutionerTest method isMatchingMetaOp1.

// /////////////////////////////////////////////////////////////////////////
/*/////////////////////////////////////////////////////////////////////////

    MatchMeta tests are checking, how ops are matching for MetaOp requirements

*/
// ///////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
@Test
public void isMatchingMetaOp1() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray array = Nd4j.create(10);
    ScalarAdd opA = new ScalarAdd(array, 10f);
    ScalarAdd opB = new ScalarAdd(array, 10f);
    executioner.exec(opA);
    assertEquals(CudaGridExecutioner.MetaType.NOT_APPLICABLE, executioner.getMetaOpType(opB));
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 17 with ScalarAdd

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

the class GridExecutionerTest method isMatchingMetaOp2.

@Test
public void isMatchingMetaOp2() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray array = Nd4j.create(10);
    INDArray array2 = Nd4j.create(10);
    ScalarAdd opA = new ScalarAdd(array, 10f);
    ScalarAdd opB = new ScalarAdd(array2, 10f);
    executioner.exec(opA);
    assertEquals(executioner.getMetaOpType(opB), CudaGridExecutioner.MetaType.NOT_APPLICABLE);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 18 with ScalarAdd

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

the class MetaOpTests method testLinearMetaOp1.

@Ignore
@Test
public void testLinearMetaOp1() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray array = Nd4j.create(new float[] { -11f, -12f, -13f, -14f, -15f, -16f, -17f, -18f, -19f, -20f });
    INDArray exp = Nd4j.create(new float[] { 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f });
    INDArray exp2 = Nd4j.create(new float[] { 11f, 12f, 13f, 14f, 15f, 16f, 17f, 18f, 19f, 20f });
    ScalarAdd opA = new ScalarAdd(array, 10f);
    Abs opB = new Abs(array);
    PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
    executioner.prepareGrid(metaOp);
    GridDescriptor descriptor = metaOp.getGridDescriptor();
    assertEquals(2, descriptor.getGridDepth());
    assertEquals(2, descriptor.getGridPointers().size());
    assertEquals(Op.Type.SCALAR, descriptor.getGridPointers().get(0).getType());
    assertEquals(Op.Type.TRANSFORM, descriptor.getGridPointers().get(1).getType());
    long time1 = System.nanoTime();
    executioner.exec(metaOp);
    long time2 = System.nanoTime();
    System.out.println("Execution time Meta: " + ((time2 - time1) / 1));
    assertEquals(exp, array);
    time1 = System.nanoTime();
    Nd4j.getExecutioner().exec(opA);
    Nd4j.getExecutioner().exec(opB);
    time2 = System.nanoTime();
    System.out.println("Execution time Linear: " + ((time2 - time1) / 1));
    assertEquals(exp2, array);
}
Also used : GridDescriptor(org.nd4j.linalg.api.ops.grid.GridDescriptor) ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) Abs(org.nd4j.linalg.api.ops.impl.transforms.Abs) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PredicateMetaOp(org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with ScalarAdd

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

the class MetaOpTests method testLinearMetaOp2.

@Ignore
@Test
public void testLinearMetaOp2() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray array = Nd4j.create(new float[] { -11f, -12f, -13f, -14f, -15f, -16f, -17f, -18f, -19f, -20f });
    INDArray exp = Nd4j.create(new float[] { 21f, 22f, 23f, 24f, 25f, 26f, 27f, 28f, 29f, 30f });
    INDArray exp2 = Nd4j.create(new float[] { 31f, 32f, 33f, 34f, 35f, 36f, 37f, 38f, 39f, 40f });
    Abs opA = new Abs(array);
    ScalarAdd opB = new ScalarAdd(array, 10f);
    PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
    executioner.prepareGrid(metaOp);
    GridDescriptor descriptor = metaOp.getGridDescriptor();
    assertEquals(2, descriptor.getGridDepth());
    assertEquals(2, descriptor.getGridPointers().size());
    assertEquals(Op.Type.TRANSFORM, descriptor.getGridPointers().get(0).getType());
    assertEquals(Op.Type.SCALAR, descriptor.getGridPointers().get(1).getType());
    long time1 = System.nanoTime();
    executioner.exec(metaOp);
    long time2 = System.nanoTime();
    System.out.println("Execution time Meta: " + ((time2 - time1) / 1));
    assertEquals(exp, array);
    time1 = System.nanoTime();
    Nd4j.getExecutioner().exec(opA);
    Nd4j.getExecutioner().exec(opB);
    time2 = System.nanoTime();
    System.out.println("Execution time Linear: " + ((time2 - time1) / 1));
    assertEquals(exp2, array);
}
Also used : GridDescriptor(org.nd4j.linalg.api.ops.grid.GridDescriptor) ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) Abs(org.nd4j.linalg.api.ops.impl.transforms.Abs) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PredicateMetaOp(org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with ScalarAdd

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

the class MetaOpTests method testPredicateReduce2.

/**
 * Predicate test for scalar + reduceScalar
 *
 * @throws Exception
 */
@Ignore
@Test
public void testPredicateReduce2() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray arrayX = Nd4j.create(5, 5);
    ScalarAdd opA = new ScalarAdd(arrayX, 1.0f);
    Sum opB = new Sum(arrayX);
    PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
    executioner.exec(metaOp);
    INDArray result = opB.z();
    assertNotEquals(null, result);
    assertTrue(result.isScalar());
    assertEquals(25f, result.getFloat(0), 0.1f);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PredicateMetaOp(org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp) Sum(org.nd4j.linalg.api.ops.impl.accum.Sum) Ignore(org.junit.Ignore) 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