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