Search in sources :

Example 1 with Max

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);
}
Also used : Min(org.nd4j.linalg.api.ops.impl.accum.Min) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Max(org.nd4j.linalg.api.ops.impl.accum.Max) Test(org.junit.Test)

Example 2 with Max

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);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Max(org.nd4j.linalg.api.ops.impl.accum.Max) Test(org.junit.Test)

Example 3 with Max

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));
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Max(org.nd4j.linalg.api.ops.impl.accum.Max) Test(org.junit.Test)

Example 4 with Max

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);
}
Also used : ReduceMetaOp(org.nd4j.linalg.api.ops.impl.meta.ReduceMetaOp) ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Max(org.nd4j.linalg.api.ops.impl.accum.Max) OpDescriptor(org.nd4j.linalg.api.ops.grid.OpDescriptor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 INDArray (org.nd4j.linalg.api.ndarray.INDArray)4 Max (org.nd4j.linalg.api.ops.impl.accum.Max)4 ScalarAdd (org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd)3 OpDescriptor (org.nd4j.linalg.api.ops.grid.OpDescriptor)1 Min (org.nd4j.linalg.api.ops.impl.accum.Min)1 ReduceMetaOp (org.nd4j.linalg.api.ops.impl.meta.ReduceMetaOp)1