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