use of org.nd4j.linalg.api.ops.impl.accum.Max in project nd4j by deeplearning4j.
the class CudaAccumTests method testDimensionMax.
@Test
public void testDimensionMax() {
INDArray linspace = Nd4j.linspace(1, 6, 6).reshape('f', 2, 3);
int axis = 0;
INDArray row = linspace.slice(axis);
System.out.println("Linspace: " + linspace);
System.out.println("Row: " + row);
System.out.println("Row shapeInfo: " + row.shapeInfoDataBuffer());
Max max = new Max(row);
double max2 = Nd4j.getExecutioner().execAndReturn(max).getFinalResult().doubleValue();
assertEquals(5.0, max2, 1e-1);
Min min = new Min(row);
double min2 = Nd4j.getExecutioner().execAndReturn(min).getFinalResult().doubleValue();
assertEquals(1.0, min2, 1e-1);
}
use of org.nd4j.linalg.api.ops.impl.accum.Max in project nd4j by deeplearning4j.
the class GridExecutionerTest method testGridFlow1.
// /////////////////////////////////////////////////////////////////////////
/*/////////////////////////////////////////////////////////////////////////
GridFlow tests are checking how ops are getting queued upon exec() calls
*/
// ///////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
@Test
public void testGridFlow1() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
assertEquals(0, executioner.getQueueLength());
INDArray array = Nd4j.create(10);
ScalarAdd opA = new ScalarAdd(array, 10f);
executioner.exec(opA);
long time1 = System.nanoTime();
Max opB = new Max(array);
executioner.exec(opB);
assertEquals(0, executioner.getQueueLength());
long time2 = System.nanoTime();
opB = new Max(array);
executioner.exec(opB);
long time3 = System.nanoTime();
assertEquals(0, executioner.getQueueLength());
long firstExec = time2 - time1;
long secondExec = time3 - time2;
System.out.println("First exec time: " + firstExec);
System.out.println("Second exec time: " + secondExec);
System.out.println("Array: " + array);
}
use of org.nd4j.linalg.api.ops.impl.accum.Max in project nd4j by deeplearning4j.
the class GridExecutionerTest method isMatchingMetaOp3.
@Test
public void isMatchingMetaOp3() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray array = Nd4j.create(10);
ScalarAdd opA = new ScalarAdd(array, 10f);
Max opB = new Max(array);
executioner.exec(opA);
assertEquals(CudaGridExecutioner.MetaType.NOT_APPLICABLE, executioner.getMetaOpType(opB));
}
use of org.nd4j.linalg.api.ops.impl.accum.Max 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);
}
Aggregations