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);
}
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);
}
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);
}
Aggregations