Search in sources :

Example 6 with PredicateMetaOp

use of org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp in project nd4j by deeplearning4j.

the class MetaOpTests method testPredicateScalarPairwise3.

/*
    @Ignore
    @Test
    public void testPredicateScalarPairwise1() throws Exception {
        CudaGridExecutioner executioner = new CudaGridExecutioner();

        INDArray arrayX = Nd4j.create(new float[]{0f, 0f, 0f, 0f, 0f, 0f});
        INDArray arrayY = Nd4j.create(new float[]{2f, 2f, 2f, 2f, 2f, 2f});
        INDArray exp = Nd4j.create(new float[]{3f, 3f, 3f, 3f, 3f, 3f});

        ScalarAdd opA = new ScalarAdd(arrayX, 1.0f);

        AddOp opB = new AddOp(arrayX, arrayY, arrayX);

        PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);

        executioner.prepareGrid(metaOp);

        long time1 = System.nanoTime();
        executioner.exec(metaOp);
        long time2 = System.nanoTime();

        System.out.println("Execution time Meta: " + ((time2 - time1) / 1));

        assertEquals(exp, arrayX);
    }

    @Ignore
    @Test
    public void testPredicateScalarPairwise2() throws Exception {
        CudaGridExecutioner executioner = new CudaGridExecutioner();

        INDArray arrayX = Nd4j.create(new float[]{0f, 0f, 0f, 0f, 0f, 0f});
        INDArray arrayY = Nd4j.create(new float[]{2f, 2f, 2f, 2f, 2f, 2f});
        INDArray exp = Nd4j.create(new float[]{1f, 1f, 1f, 1f, 1f, 1f});

        ScalarSubtraction opA = new ScalarSubtraction(arrayX, 1.0f);

        AddOp opB = new AddOp(arrayX, arrayY, arrayX);

        PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);

        executioner.prepareGrid(metaOp);

        long time1 = System.nanoTime();
        executioner.exec(metaOp);
        long time2 = System.nanoTime();

        System.out.println("Execution time Meta: " + ((time2 - time1) / 1));

        assertEquals(exp, arrayX);
    }
*/
/**
 * This is the MOST crucial test, basically it's test for dup() + following linear op
 *
 * @throws Exception
 */
@Test
public void testPredicateScalarPairwise3() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray arrayX = Nd4j.create(new float[] { 0f, 0f, 0f, 0f, 0f, 0f });
    INDArray arrayY = Nd4j.create(new float[] { 1f, 2f, 3f, 4f, 5f, 6f });
    INDArray exp = Nd4j.create(new float[] { 2f, 4f, 6f, 8f, 10f, 12f });
    Set opA = new Set(arrayX, arrayY, arrayX, arrayX.length());
    ScalarMultiplication opB = new ScalarMultiplication(arrayX, 2.0f);
    // ScalarAdd opB = new ScalarAdd(arrayX, 3.0f);
    PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
    executioner.prepareGrid(metaOp);
    long time1 = System.nanoTime();
    executioner.exec(metaOp);
    long time2 = System.nanoTime();
    System.out.println("Execution time Meta: " + ((time2 - time1) / 1));
    assertEquals(exp, arrayX);
}
Also used : Set(org.nd4j.linalg.api.ops.impl.transforms.Set) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PredicateMetaOp(org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp) ScalarMultiplication(org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication) Test(org.junit.Test)

Example 7 with PredicateMetaOp

use of org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp 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 8 with PredicateMetaOp

use of org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp 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

PredicateMetaOp (org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp)8 Test (org.junit.Test)6 INDArray (org.nd4j.linalg.api.ndarray.INDArray)6 GridDescriptor (org.nd4j.linalg.api.ops.grid.GridDescriptor)4 Ignore (org.junit.Ignore)3 ScalarAdd (org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd)3 ScalarMultiplication (org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication)3 Set (org.nd4j.linalg.api.ops.impl.transforms.Set)3 InvertedPredicateMetaOp (org.nd4j.linalg.api.ops.impl.meta.InvertedPredicateMetaOp)2 ReduceMetaOp (org.nd4j.linalg.api.ops.impl.meta.ReduceMetaOp)2 Abs (org.nd4j.linalg.api.ops.impl.transforms.Abs)2 GridPointers (org.nd4j.linalg.api.ops.grid.GridPointers)1 OpDescriptor (org.nd4j.linalg.api.ops.grid.OpDescriptor)1 Sum (org.nd4j.linalg.api.ops.impl.accum.Sum)1 PostulateMetaOp (org.nd4j.linalg.api.ops.impl.meta.PostulateMetaOp)1 CudaContext (org.nd4j.linalg.jcublas.context.CudaContext)1 LongPointerWrapper (org.nd4j.nativeblas.LongPointerWrapper)1