use of org.bytedeco.javacpp.FloatPointer in project nd4j by deeplearning4j.
the class MetaOpTests method testPooling2D.
@Test
public void testPooling2D() {
Nd4j.create(1);
val input = Nd4j.linspace(1, 600, 600).reshape(2, 10, 10, 3);
val permuted = input.permute(0, 3, 1, 2);
val nativeOps = NativeOpsHolder.getInstance().getDeviceNativeOps();
val output = Nd4j.create(2, 3, 4, 4);
val context = AtomicAllocator.getInstance().getFlowController().prepareAction(output, permuted);
val ptrBIn = (FloatPointer) AtomicAllocator.getInstance().getPointer(permuted, context);
val ptrBOut = (FloatPointer) AtomicAllocator.getInstance().getPointer(output, context);
val ptrSIn = (IntPointer) AtomicAllocator.getInstance().getPointer(permuted.shapeInfoDataBuffer());
val ptrSOut = (IntPointer) AtomicAllocator.getInstance().getPointer(output.shapeInfoDataBuffer());
// kY kX sY sX pY pX dY dX N M P
val bufParams = Nd4j.getConstantHandler().getConstantBuffer(new float[] { 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2 });
val ptrBParams = (FloatPointer) AtomicAllocator.getInstance().getPointer(bufParams, context);
PointerPointer xShapeInfoHostPointer = // 0
new PointerPointer(32).put(// 0
AddressRetriever.retrieveHostPointer(permuted.shapeInfoDataBuffer()), // 1
context.getOldStream(), // 2
AtomicAllocator.getInstance().getDeviceIdPointer(), // 3
context.getBufferAllocation(), // 4
context.getBufferReduction(), // 5
context.getBufferScalar(), // 6
context.getBufferSpecial(), // 7
null, // 8
AddressRetriever.retrieveHostPointer(output.shapeInfoDataBuffer()));
nativeOps.execTransformFloat(xShapeInfoHostPointer, 71, ptrBIn, ptrSIn, ptrBOut, ptrSOut, ptrBParams);
AtomicAllocator.getInstance().getFlowController().registerAction(context, output, permuted);
nativeOps.streamSynchronize(context.getOldStream());
nativeOps.streamSynchronize(context.getOldStream());
val reverted = output.permute(0, 2, 3, 1);
System.out.println("Result: " + reverted.toString());
}
use of org.bytedeco.javacpp.FloatPointer in project nd4j by deeplearning4j.
the class CpuLapack method sgeqrf.
// =========================
// Q R DECOMP
@Override
public void sgeqrf(int M, int N, INDArray A, INDArray R, INDArray INFO) {
INDArray tau = Nd4j.create(N);
int status = LAPACKE_sgeqrf(getColumnOrder(A), M, N, (FloatPointer) A.data().addressPointer(), getLda(A), (FloatPointer) tau.data().addressPointer());
if (status != 0) {
throw new BlasException("Failed to execute sgeqrf", status);
}
// Copy R ( upper part of Q ) into result
if (R != null) {
R.assign(A.get(NDArrayIndex.interval(0, A.columns()), NDArrayIndex.all()));
INDArrayIndex[] ix = new INDArrayIndex[2];
for (int i = 1; i < Math.min(A.rows(), A.columns()); i++) {
ix[0] = NDArrayIndex.point(i);
ix[1] = NDArrayIndex.interval(0, i);
R.put(ix, 0);
}
}
status = LAPACKE_sorgqr(getColumnOrder(A), M, N, N, (FloatPointer) A.data().addressPointer(), getLda(A), (FloatPointer) tau.data().addressPointer());
if (status != 0) {
throw new BlasException("Failed to execute sorgqr", status);
}
}
use of org.bytedeco.javacpp.FloatPointer in project nd4j by deeplearning4j.
the class CpuLapack method sgesvd.
// =========================
// U S V' DECOMP (aka SVD)
@Override
public void sgesvd(byte jobu, byte jobvt, int M, int N, INDArray A, INDArray S, INDArray U, INDArray VT, INDArray INFO) {
INDArray superb = Nd4j.create(M < N ? M : N);
int status = LAPACKE_sgesvd(getColumnOrder(A), jobu, jobvt, M, N, (FloatPointer) A.data().addressPointer(), getLda(A), (FloatPointer) S.data().addressPointer(), U == null ? null : (FloatPointer) U.data().addressPointer(), U == null ? 1 : getLda(U), VT == null ? null : (FloatPointer) VT.data().addressPointer(), VT == null ? 1 : getLda(VT), (FloatPointer) superb.data().addressPointer());
if (status != 0) {
throw new BlasException("Failed to execute sgesvd", status);
}
}
use of org.bytedeco.javacpp.FloatPointer in project nd4j by deeplearning4j.
the class FloatDataBufferTest method testPointerCreation.
@Test
public void testPointerCreation() {
FloatPointer floatPointer = new FloatPointer(1, 2, 3, 4);
Indexer indexer = FloatIndexer.create(floatPointer);
DataBuffer buffer = Nd4j.createBuffer(floatPointer, DataBuffer.Type.FLOAT, 4, indexer);
DataBuffer other = Nd4j.createBuffer(new float[] { 1, 2, 3, 4 });
assertArrayEquals(other.asFloat(), buffer.asFloat(), 0.001f);
}
use of org.bytedeco.javacpp.FloatPointer in project nd4j by deeplearning4j.
the class TestNDArrayCreation method testBufferCreation.
@Test
public void testBufferCreation() {
DataBuffer dataBuffer = Nd4j.createBuffer(new double[] { 1, 2 });
Pointer pointer = dataBuffer.pointer();
FloatPointer floatPointer = new FloatPointer(pointer);
DataBuffer dataBuffer1 = Nd4j.createBuffer(floatPointer, 2);
assertEquals(2, dataBuffer1.length());
assertEquals(1.0, dataBuffer1.getDouble(0), 1e-1);
assertEquals(2.0, dataBuffer1.getDouble(1), 1e-1);
INDArray arr = Nd4j.create(dataBuffer1);
System.out.println(arr);
}
Aggregations