Search in sources :

Example 6 with ScalarAdd

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

the class SporadicTests method testBroadcastEquality2.

@Test
public void testBroadcastEquality2() {
    INDArray array = Nd4j.zeros(new int[] { 4, 5 }, 'c');
    INDArray array2 = Nd4j.zeros(new int[] { 4, 5 }, 'c');
    INDArray column = Nd4j.create(new float[] { 1, 2, 3, 4 }).reshape(4, 1);
    array.addiColumnVector(column);
    System.out.println(array);
    System.out.println("-------");
    ScalarAdd add = new ScalarAdd(array2, column, array2, array2.length(), 0.0f);
    add.setDimension(1);
    Nd4j.getExecutioner().exec(add);
    System.out.println(array2);
    assertEquals(array, array2);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 7 with ScalarAdd

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

the class SporadicTests method testBroadcastEquality1.

@Test
public void testBroadcastEquality1() {
    INDArray array = Nd4j.zeros(new int[] { 4, 5 }, 'f');
    INDArray array2 = Nd4j.zeros(new int[] { 4, 5 }, 'f');
    INDArray row = Nd4j.create(new float[] { 1, 2, 3, 4, 5 });
    array.addiRowVector(row);
    System.out.println(array);
    System.out.println("-------");
    ScalarAdd add = new ScalarAdd(array2, row, array2, array2.length(), 0.0f);
    add.setDimension(0);
    Nd4j.getExecutioner().exec(add);
    System.out.println(array2);
    assertEquals(array, array2);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 8 with ScalarAdd

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

the class NativeOpExecutionerTest method testBroadcastEquality2.

@Test
public void testBroadcastEquality2() {
    INDArray array = Nd4j.zeros(new int[] { 4, 5 }, 'c');
    INDArray array2 = Nd4j.zeros(new int[] { 4, 5 }, 'c');
    INDArray column = Nd4j.create(new float[] { 1, 2, 3, 4 }).reshape(4, 1);
    array.addiColumnVector(column);
    System.out.println(array);
    System.out.println("-------");
    ScalarAdd add = new ScalarAdd(array2, column, array2, array2.length(), 0.0f);
    add.setDimension(1);
    Nd4j.getExecutioner().exec(add);
    System.out.println(array2);
    assertEquals(array, array2);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 9 with ScalarAdd

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

the class NativeOpExecutionerTest method testBroadcastEquality1.

@Test
public void testBroadcastEquality1() {
    INDArray array = Nd4j.zeros(new int[] { 4, 5 }, 'f');
    INDArray array2 = Nd4j.zeros(new int[] { 4, 5 }, 'f');
    INDArray row = Nd4j.create(new float[] { 1, 2, 3, 4, 5 });
    array.addiRowVector(row);
    System.out.println(array);
    System.out.println("-------");
    ScalarAdd add = new ScalarAdd(array2, row, array2, array2.length(), 0.0f);
    add.setDimension(0);
    Nd4j.getExecutioner().exec(add);
    System.out.println(array2);
    assertEquals(array, array2);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 10 with ScalarAdd

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

the class GridRunningTests method testScalarPassing2.

@Test
public void testScalarPassing2() 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);
    INDArray res1 = Nd4j.getExecutioner().execAndReturn(opA);
    assertEquals(1, executioner.getQueueLength());
    INDArray res2 = Nd4j.getExecutioner().execAndReturn(opB);
    assertEquals(1, executioner.getQueueLength());
    INDArray res3 = Nd4j.getExecutioner().execAndReturn(opC);
    assertEquals(1, executioner.getQueueLength());
    assertEquals(exp, array);
    assertEquals(0, executioner.getQueueLength());
    assertTrue(res1 == res2);
    assertTrue(res3 == res2);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) 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