Search in sources :

Example 1 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class OpExecutionerTests method testScalarArithmetic.

@Test
public void testScalarArithmetic() {
    INDArray linspace = Nd4j.linspace(1, 6, 6);
    INDArray plusOne = Nd4j.linspace(2, 7, 6);
    Nd4j.getExecutioner().exec(new ScalarAdd(linspace, 1));
    assertEquals(plusOne, linspace);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest) Test(org.junit.Test)

Example 2 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class OpExecutionerTestsC method testScalarArithmetic.

@Test
public void testScalarArithmetic() {
    INDArray linspace = Nd4j.linspace(1, 6, 6);
    INDArray plusOne = Nd4j.linspace(2, 7, 6);
    Nd4j.getExecutioner().exec(new ScalarAdd(linspace, 1));
    assertEquals(plusOne, linspace);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest) Test(org.junit.Test)

Example 3 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class IndexingTestsC method testExecSubArray.

@Test
public void testExecSubArray() {
    INDArray nd = Nd4j.create(new double[] { 1, 2, 3, 4, 5, 6 }, new int[] { 2, 3 });
    INDArray sub = nd.get(NDArrayIndex.all(), NDArrayIndex.interval(0, 2));
    Nd4j.getExecutioner().exec(new ScalarAdd(sub, 2));
    assertEquals(getFailureMessage(), Nd4j.create(new double[][] { { 3, 4 }, { 6, 7 } }), sub);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 4 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class GridRunningTests method testScalarPassing1.

@Test
public void testScalarPassing1() throws Exception {
    INDArray array = Nd4j.create(5);
    INDArray exp = Nd4j.create(new float[] { 6f, 6f, 6f, 6f, 6f });
    CudaGridExecutioner executioner = (CudaGridExecutioner) Nd4j.getExecutioner();
    ScalarAdd opA = new ScalarAdd(array, 1f);
    ScalarAdd opB = new ScalarAdd(array, 2f);
    ScalarAdd opC = new ScalarAdd(array, 3f);
    Nd4j.getExecutioner().exec(opA);
    assertEquals(1, executioner.getQueueLength());
    Nd4j.getExecutioner().exec(opB);
    assertEquals(1, executioner.getQueueLength());
    Nd4j.getExecutioner().exec(opC);
    assertEquals(1, executioner.getQueueLength());
    assertEquals(exp, array);
    assertEquals(0, executioner.getQueueLength());
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 5 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class GridExecutionerTest method testGridFlow2.

@Test
public void testGridFlow2() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray arrayX = Nd4j.create(10);
    INDArray arrayY = Nd4j.create(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f });
    INDArray exp = Nd4j.create(new float[] { 3f, 3f, 3f, 3f, 3f, 3f, 3f, 3f, 3f, 3f });
    Set opA = new Set(arrayX, arrayY, arrayX, arrayX.length());
    executioner.exec(opA);
    assertEquals(1, executioner.getQueueLength());
    long time1 = System.nanoTime();
    ScalarAdd opB = new ScalarAdd(arrayX, 2f);
    executioner.exec(opB);
    assertEquals(0, executioner.getQueueLength());
    long time2 = System.nanoTime();
    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);
    assertEquals(exp, arrayX);
    System.out.println("ArrayX: " + arrayX);
    System.out.println("ArrayExp: " + exp);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) ScalarSet(org.nd4j.linalg.api.ops.impl.scalar.ScalarSet) Set(org.nd4j.linalg.api.ops.impl.transforms.Set) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 INDArray (org.nd4j.linalg.api.ndarray.INDArray)21 ScalarAdd (org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd)21 ScalarSet (org.nd4j.linalg.api.ops.impl.scalar.ScalarSet)4 Set (org.nd4j.linalg.api.ops.impl.transforms.Set)4 Ignore (org.junit.Ignore)3 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)3 Max (org.nd4j.linalg.api.ops.impl.accum.Max)3 PredicateMetaOp (org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp)3 GridDescriptor (org.nd4j.linalg.api.ops.grid.GridDescriptor)2 Abs (org.nd4j.linalg.api.ops.impl.transforms.Abs)2 AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)1 OpDescriptor (org.nd4j.linalg.api.ops.grid.OpDescriptor)1 Sum (org.nd4j.linalg.api.ops.impl.accum.Sum)1 ReduceMetaOp (org.nd4j.linalg.api.ops.impl.meta.ReduceMetaOp)1