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