use of org.nd4j.linalg.api.ops.impl.accum.Sum in project nd4j by deeplearning4j.
the class HalfOpsTests method testReduce1.
@Test
public void testReduce1() throws Exception {
INDArray array1 = Nd4j.create(new float[] { 2.01f, 2.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f, 1.01f });
Sum sum = new Sum(array1);
Nd4j.getExecutioner().exec(sum, 1);
Number resu = sum.getFinalResult();
System.out.println("Result: " + resu);
assertEquals(17.15f, resu.floatValue(), 0.01f);
}
use of org.nd4j.linalg.api.ops.impl.accum.Sum in project nd4j by deeplearning4j.
the class GridExecutionerTest method testGridFlow4.
@Test
public void testGridFlow4() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray arrayX = Nd4j.create(new float[] { 1f, 1f, 1f, 1f, 1f });
Sum op = new Sum(arrayX);
executioner.exec(op);
assertEquals(0, executioner.getQueueLength());
assertNotEquals(null, op.getFinalResult());
assertEquals(5, op.getFinalResult().intValue());
}
use of org.nd4j.linalg.api.ops.impl.accum.Sum in project nd4j by deeplearning4j.
the class GridExecutionerTest method testGridFlow5.
@Test
public void testGridFlow5() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray arrayX = Nd4j.create(5, 5);
Sum op = new Sum(arrayX);
executioner.exec(op, 1);
assertEquals(0, executioner.getQueueLength());
assertEquals(0, op.z().getFloat(0), 0.1f);
}
use of org.nd4j.linalg.api.ops.impl.accum.Sum in project nd4j by deeplearning4j.
the class GridExecutionerTest method testOpPointerizeReduce2.
/**
* Reduce along all dimensions
*
* @throws Exception
*/
@Test
public void testOpPointerizeReduce2() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray array = Nd4j.create(10, 10);
Sum opA = new Sum(array);
// we need exec here, to init Op.Z for specific dimension
executioner.exec(opA);
GridPointers pointers = executioner.pointerizeOp(opA, null);
assertEquals(opA.opNum(), pointers.getOpNum());
assertEquals(Op.Type.REDUCE, pointers.getType());
CudaContext context = (CudaContext) AtomicAllocator.getInstance().getDeviceContext().getContext();
Pointer x = AtomicAllocator.getInstance().getPointer(array, context);
Pointer xShapeInfo = AtomicAllocator.getInstance().getPointer(array.shapeInfoDataBuffer(), context);
Pointer z = AtomicAllocator.getInstance().getPointer(opA.z(), context);
Pointer zShapeInfo = AtomicAllocator.getInstance().getPointer(opA.z().shapeInfoDataBuffer(), context);
DataBuffer dimBuff = Nd4j.getConstantHandler().getConstantBuffer(new int[] { 1 });
Pointer ptrBuff = AtomicAllocator.getInstance().getPointer(dimBuff, context);
assertEquals(x, pointers.getX());
assertEquals(null, pointers.getY());
assertNotEquals(null, pointers.getZ());
assertEquals(z, pointers.getZ());
assertEquals(1, opA.z().length());
assertEquals(1, pointers.getZLength());
/* // We dont really care about EWS here, since we're testing TAD-based operation
assertEquals(1, pointers.getXStride());
assertEquals(-1, pointers.getYStride());
assertEquals(1, pointers.getZStride());
*/
assertEquals(xShapeInfo, pointers.getXShapeInfo());
assertEquals(null, pointers.getYShapeInfo());
assertEquals(zShapeInfo, pointers.getZShapeInfo());
assertEquals(null, pointers.getDimensions());
assertEquals(0, pointers.getDimensionsLength());
assertEquals(null, pointers.getTadShape());
assertEquals(null, pointers.getTadOffsets());
assertEquals(null, pointers.getExtraArgs());
}
use of org.nd4j.linalg.api.ops.impl.accum.Sum in project nd4j by deeplearning4j.
the class CudaAccumTests method testPinnedSum2.
@Test
public void testPinnedSum2() throws Exception {
// simple way to stop test if we're not on CUDA backend here
INDArray array1 = Nd4j.linspace(1, 10000, 100000).reshape(100, 1000);
Sum sum = new Sum(array1);
INDArray result;
/* = Nd4j.getExecutioner().exec(sum, 0);
assertEquals(495055.44f, result.getFloat(0), 0.01f);
*/
result = Nd4j.getExecutioner().exec(sum, 1);
result = Nd4j.getExecutioner().exec(sum, 1);
assertEquals(50945.52f, result.getFloat(0), 0.01f);
}
Aggregations