org.bytedeco.javacpp.DoublePointer Java Examples
The following examples show how to use
org.bytedeco.javacpp.DoublePointer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DoubleDataBufferTest.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Test public void testAddressPointer(){ if( Nd4j.getExecutioner().type() != OpExecutioner.ExecutionerType.NATIVE_CPU ){ return; } DataBuffer buffer = Nd4j.createBuffer(new double[] {1, 2, 3, 4}); DataBuffer wrappedBuffer = Nd4j.createBuffer(buffer, 1, 2); DoublePointer pointer = (DoublePointer) wrappedBuffer.addressPointer(); Assert.assertEquals(buffer.getDouble(1), pointer.get(0), 1e-1); Assert.assertEquals(buffer.getDouble(2), pointer.get(1), 1e-1); try { pointer.asBuffer().get(3); // Try to access element outside pointer capacity. Assert.fail("Accessing this address should not be allowed!"); } catch (IndexOutOfBoundsException e) { // do nothing } }
Example #2
Source File: JcublasLevel1.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected void dscal(long N, double alpha, INDArray X, int incX) { if (Nd4j.dataType() != DataBuffer.Type.DOUBLE) logger.warn("DOUBLE scal called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(X); CublasPointer xCPointer = new CublasPointer(X, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasDscal_v2(new cublasContext(handle), (int) N, new DoublePointer(alpha), (DoublePointer) xCPointer.getDevicePointer(), incX); } allocator.registerAction(ctx, X); OpExecutionerUtil.checkForAny(X); }
Example #3
Source File: JcublasLevel1.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected int idamax(long N, INDArray X, int incX) { if (Nd4j.dataType() != DataBuffer.Type.DOUBLE) logger.warn("DOUBLE imax called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(null, X); int ret2; CublasPointer xCPointer = new CublasPointer(X, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); IntPointer resultPointer = new IntPointer(new int[] {0}); cublasIdamax_v2(new cublasContext(handle), (int) N, (DoublePointer) xCPointer.getDevicePointer(), incX, resultPointer); ret2 = resultPointer.get(); } allocator.registerAction(ctx, null, X); return ret2 - 1; }
Example #4
Source File: JcublasLevel3.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected void dsyrk(char Order, char Uplo, char Trans, int N, int K, double alpha, INDArray A, int lda, double beta, INDArray C, int ldc) { if (Nd4j.dataType() != DataBuffer.Type.DOUBLE) logger.warn("DOUBLE syrk called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(C, A); CublasPointer aPointer = new CublasPointer(A, ctx); CublasPointer cPointer = new CublasPointer(C, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasDsyrk_v2(new cublasContext(handle), convertUplo(Uplo), Trans, N, K, new DoublePointer(alpha), (DoublePointer) aPointer.getDevicePointer(), lda, new DoublePointer(beta), (DoublePointer) cPointer.getDevicePointer(), ldc); } allocator.registerAction(ctx, C, A); OpExecutionerUtil.checkForAny(C); }
Example #5
Source File: CpuLapack.java From nd4j with Apache License 2.0 | 6 votes |
public int dsyev( char jobz, char uplo, int N, INDArray A, INDArray R ) { DoublePointer dp = new DoublePointer(1) ; int status = LAPACKE_dsyev_work( getColumnOrder(A), (byte)jobz, (byte)uplo, N, (DoublePointer)A.data().addressPointer(), getLda(A), (DoublePointer)R.data().addressPointer(), dp, -1 ) ; if( status == 0 ) { int lwork = (int)dp.get() ; INDArray work = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createDouble(lwork), Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, lwork}).getFirst()); status = LAPACKE_dsyev( getColumnOrder(A), (byte)jobz, (byte)uplo, N, (DoublePointer)A.data().addressPointer(), getLda(A), (DoublePointer)work.data().addressPointer() ) ; if( status == 0 ) { R.assign( work.get( NDArrayIndex.interval(0,N) ) ) ; } } return status ; }
Example #6
Source File: GymEnv.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override public OBSERVATION reset() { int gstate = PyGILState_Ensure(); try { Py_DecRef(PyRun_StringFlags("state = env.reset()", Py_single_input, globals, locals, null)); checkPythonError(); PyArrayObject state = new PyArrayObject(PyDict_GetItemString(locals, "state")); DoublePointer stateData = new DoublePointer(PyArray_BYTES(state)).capacity(PyArray_Size(state)); SizeTPointer stateDims = PyArray_DIMS(state).capacity(PyArray_NDIM(state)); checkPythonError(); done = false; double[] data = new double[(int)stateData.capacity()]; stateData.get(data); return (OBSERVATION) new Box(data); } finally { PyGILState_Release(gstate); } }
Example #7
Source File: JcublasLevel3.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected void dtrsm(char Order, char Side, char Uplo, char TransA, char Diag, int M, int N, double alpha, INDArray A, int lda, INDArray B, int ldb) { if (Nd4j.dataType() != DataBuffer.Type.DOUBLE) logger.warn("DOUBLE trsm called"); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(B, A); CublasPointer aPointer = new CublasPointer(A, ctx); CublasPointer bPointer = new CublasPointer(B, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); cublasDtrsm_v2(new cublasContext(handle), convertSideMode(Side), convertUplo(Uplo), convertTranspose(TransA), convertDiag(Diag), M, N, new DoublePointer(alpha), (DoublePointer) aPointer.getDevicePointer(), lda, (DoublePointer) bPointer.getDevicePointer(), ldb); } allocator.registerAction(ctx, B, A); OpExecutionerUtil.checkForAny(B); }
Example #8
Source File: JcublasLevel3.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override protected void dtrmm(char Order, char Side, char Uplo, char TransA, char Diag, int M, int N, double alpha, INDArray A, int lda, INDArray B, int ldb) { Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(B, A); CublasPointer aPointer = new CublasPointer(A, ctx); CublasPointer bPointer = new CublasPointer(B, ctx); cublasHandle_t handle = ctx.getCublasHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getCublasStream())); cublasDtrmm_v2(new cublasContext(handle), convertSideMode(Side), convertUplo(Uplo), convertTranspose(TransA), convertDiag(Diag), M, N, new DoublePointer(alpha), (DoublePointer) aPointer.getDevicePointer(), lda, (DoublePointer) bPointer.getDevicePointer(), ldb, (DoublePointer) bPointer.getDevicePointer(), ldb); } allocator.registerAction(ctx, B, A); OpExecutionerUtil.checkForAny(B); }
Example #9
Source File: JcublasLevel3.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override protected void dsyrk(char Order, char Uplo, char Trans, int N, int K, double alpha, INDArray A, int lda, double beta, INDArray C, int ldc) { Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(C, A); CublasPointer aPointer = new CublasPointer(A, ctx); CublasPointer cPointer = new CublasPointer(C, ctx); cublasHandle_t handle = ctx.getCublasHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getCublasStream())); cublasDsyrk_v2(new cublasContext(handle), convertUplo(Uplo), Trans, N, K, new DoublePointer(alpha), (DoublePointer) aPointer.getDevicePointer(), lda, new DoublePointer(beta), (DoublePointer) cPointer.getDevicePointer(), ldc); } allocator.registerAction(ctx, C, A); OpExecutionerUtil.checkForAny(C); }
Example #10
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dsbmv(char order, char Uplo, int N, int K, double alpha, INDArray A, int lda, INDArray X, int incX, double beta, INDArray Y, int incY) { cblas_dsbmv(convertOrder('f'), convertUplo(Uplo), N, K, alpha, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) X.data().addressPointer(), incX, beta, (DoublePointer) Y.data().addressPointer(), incY); }
Example #11
Source File: GymEnv.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public StepReply<OBSERVATION> step(A action) { int gstate = PyGILState_Ensure(); try { if (render) { Py_DecRef(PyRun_StringFlags("env.render()", Py_single_input, globals, locals, null)); checkPythonError(); } Py_DecRef(PyRun_StringFlags("state, reward, done, info = env.step(" + (Integer)action +")", Py_single_input, globals, locals, null)); checkPythonError(); PyArrayObject state = new PyArrayObject(PyDict_GetItemString(locals, "state")); DoublePointer stateData = new DoublePointer(PyArray_BYTES(state)).capacity(PyArray_Size(state)); SizeTPointer stateDims = PyArray_DIMS(state).capacity(PyArray_NDIM(state)); double reward = PyFloat_AsDouble(PyDict_GetItemString(locals, "reward")); done = PyLong_AsLong(PyDict_GetItemString(locals, "done")) != 0; checkPythonError(); double[] data = new double[(int)stateData.capacity()]; stateData.get(data); return new StepReply(new Box(data), reward, done, null); } finally { PyGILState_Release(gstate); } }
Example #12
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dspmv(char order, char Uplo, int N, double alpha, INDArray Ap, INDArray X, int incX, double beta, INDArray Y, int incY) { cblas_dspmv(convertOrder('f'), convertUplo(Uplo), N, alpha, (DoublePointer) Ap.data().addressPointer(), (DoublePointer) X.data().addressPointer(), incX, beta, (DoublePointer) Y.data().addressPointer(), incY); }
Example #13
Source File: DefaultDataBufferFactory.java From nd4j with Apache License 2.0 | 5 votes |
/** * @param doublePointer * @param length * @return */ @Override public DataBuffer create(DoublePointer doublePointer, long length) { doublePointer.capacity(length); doublePointer.limit(length); doublePointer.position(0); return new DoubleBuffer(doublePointer, DoubleIndexer.create(doublePointer), length); }
Example #14
Source File: JcublasLevel3.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected void dgemm(char Order, char TransA, char TransB, int M, int N, int K, double alpha, INDArray A, int lda, INDArray B, int ldb, double beta, INDArray C, int ldc) { //A = Shape.toOffsetZero(A); //B = Shape.toOffsetZero(B); Nd4j.getExecutioner().push(); val ctx = allocator.getFlowController().prepareAction(C, A, B); DataTypeValidation.assertDouble(A, B, C); val cAPointer = new CublasPointer(A, ctx); val cBPointer = new CublasPointer(B, ctx); val cCPointer = new CublasPointer(C, ctx); val handle = ctx.getCublasHandle(); synchronized (handle) { cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getCublasStream())); cublasDgemm_v2(new cublasContext(handle), convertTranspose(TransA), convertTranspose(TransB), M, N, K, new DoublePointer(alpha), (DoublePointer) cAPointer.getDevicePointer(), lda, (DoublePointer) cBPointer.getDevicePointer(), ldb, new DoublePointer(beta), (DoublePointer) cCPointer.getDevicePointer(), ldc); ctx.getOldStream().synchronize(); } allocator.registerAction(ctx, C, A, B); OpExecutionerUtil.checkForAny(C); }
Example #15
Source File: DoubleDataBufferTest.java From nd4j with Apache License 2.0 | 5 votes |
@Test public void testPointerCreation() { DoublePointer floatPointer = new DoublePointer(1, 2, 3, 4); Indexer indexer = DoubleIndexer.create(floatPointer); DataBuffer buffer = Nd4j.createBuffer(floatPointer, DataBuffer.Type.DOUBLE, 4, indexer); DataBuffer other = Nd4j.createBuffer(new double[] {1, 2, 3, 4}); assertArrayEquals(other.asDouble(), buffer.asDouble(), 0.001); }
Example #16
Source File: AbstractCompressor.java From nd4j with Apache License 2.0 | 5 votes |
/** * This method creates compressed INDArray from Java double array, skipping usual INDArray instantiation routines * * @param data * @param shape * @param order * @return */ @Override public INDArray compress(double[] data, int[] shape, char order) { DoublePointer pointer = new DoublePointer(data); DataBuffer shapeInfo = Nd4j.getShapeInfoProvider().createShapeInformation(shape, order).getFirst(); DataBuffer buffer = compressPointer(DataBuffer.TypeEx.DOUBLE, pointer, data.length, 8); return Nd4j.createArrayFromShapeBuffer(buffer, shapeInfo); }
Example #17
Source File: CpuLapack.java From nd4j with Apache License 2.0 | 5 votes |
@Override public void dgesvd(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_dgesvd(getColumnOrder(A), jobu, jobvt, M, N, (DoublePointer)A.data().addressPointer(), getLda(A), (DoublePointer)S.data().addressPointer(), U == null ? null : (DoublePointer)U.data().addressPointer(), U == null ? 1 : getLda(U), VT == null ? null : (DoublePointer)VT.data().addressPointer(), VT == null ? 1 : getLda(VT), (DoublePointer)superb.data().addressPointer() ) ; if( status != 0 ) { throw new BlasException( "Failed to execute dgesvd", status ) ; } }
Example #18
Source File: CpuLevel1.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected double ddot(long N, INDArray X, int incX, INDArray Y, int incY) { if (incX >= 1 && incY >= 1) { return cblas_ddot((int) N, (DoublePointer) X.data().addressPointer(), incX, (DoublePointer) Y.data().addressPointer(), incY); } else { // non-EWS dot variant Dot dot = new Dot(X, Y); Nd4j.getExecutioner().exec(dot); return dot.getFinalResult().doubleValue(); } }
Example #19
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dsymv(char order, char Uplo, int N, double alpha, INDArray A, int lda, INDArray X, int incX, double beta, INDArray Y, int incY) { cblas_dsymv(convertOrder('f'), convertUplo(Uplo), N, alpha, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) X.data().addressPointer(), incX, beta, (DoublePointer) Y.data().addressPointer(), incY); }
Example #20
Source File: AbstractCompressor.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * This method creates compressed INDArray from Java double array, skipping usual INDArray instantiation routines * * @param data * @param shape * @param order * @return */ @Override public INDArray compress(double[] data, int[] shape, char order) { DoublePointer pointer = new DoublePointer(data); DataBuffer shapeInfo = Nd4j.getShapeInfoProvider().createShapeInformation(ArrayUtil.toLongArray(shape), order, DataType.DOUBLE).getFirst(); DataBuffer buffer = compressPointer(DataTypeEx.DOUBLE, pointer, data.length, 8); return Nd4j.createArrayFromShapeBuffer(buffer, shapeInfo); }
Example #21
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dtbmv(char order, char Uplo, char TransA, char Diag, int N, int K, INDArray A, int lda, INDArray X, int incX) { cblas_dtbmv(convertOrder('f'), convertUplo(Uplo), convertTranspose(TransA), convertDiag(Diag), N, K, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) X.data().addressPointer(), incX); }
Example #22
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dtrmv(char order, char Uplo, char TransA, char Diag, int N, INDArray A, int lda, INDArray X, int incX) { cblas_dtrmv(convertOrder('f'), convertUplo(Uplo), convertTranspose(TransA), convertDiag(Diag), N, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) X.data().addressPointer(), incX); }
Example #23
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dgbmv(char order, char TransA, int M, int N, int KL, int KU, double alpha, INDArray A, int lda, INDArray X, int incX, double beta, INDArray Y, int incY) { cblas_dgbmv(convertOrder('f'), convertTranspose(TransA), M, N, KL, KU, alpha, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) X.data().addressPointer(), incX, beta, (DoublePointer) Y.data().addressPointer(), incY); }
Example #24
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dgemv(char order, char TransA, int M, int N, double alpha, INDArray A, int lda, INDArray X, int incX, double beta, INDArray Y, int incY) { cblas_dgemv(convertOrder('f'), convertTranspose(TransA), M, N, alpha, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) X.data().addressPointer(), incX, beta, (DoublePointer) Y.data().addressPointer(), incY); }
Example #25
Source File: CpuLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dtrmm(char Order, char Side, char Uplo, char TransA, char Diag, int M, int N, double alpha, INDArray A, int lda, INDArray B, int ldb) { cblas_dtrmm(convertOrder('f'), convertSide(Side), convertUplo(Uplo), convertTranspose(TransA), Diag, M, N, alpha, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) B.data().addressPointer(), ldb); }
Example #26
Source File: CpuLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dsyr2k(char Order, char Uplo, char Trans, int N, int K, double alpha, INDArray A, int lda, INDArray B, int ldb, double beta, INDArray C, int ldc) { cblas_dsyr2k(convertOrder('f'), convertUplo(Uplo), convertTranspose(Trans), N, K, alpha, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) B.data().addressPointer(), ldb, beta, (DoublePointer) C.data().addressPointer(), ldc); }
Example #27
Source File: CpuLevel3.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override protected void dgemm(char Order, char TransA, char TransB, int M, int N, int K, double alpha, INDArray A, int lda, INDArray B, int ldb, double beta, INDArray C, int ldc) { if (!Nd4j.isFallbackModeEnabled()) { cblas_dgemm(convertOrder('f'), convertTranspose(TransA), convertTranspose(TransB), M, N, K, alpha, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) B.data().addressPointer(), ldb, beta, (DoublePointer) C.data().addressPointer(), ldc); } else { Nd4j.getExecutioner() .exec(new AggregateGEMM('f', TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc)); } }
Example #28
Source File: CpuLevel3.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dgemm(char Order, char TransA, char TransB, int M, int N, int K, double alpha, INDArray A, int lda, INDArray B, int ldb, double beta, INDArray C, int ldc) { if (!Nd4j.isFallbackModeEnabled()) { cblas_dgemm(convertOrder('f'), convertTranspose(TransA), convertTranspose(TransB), M, N, K, alpha, (DoublePointer) A.data().addressPointer(), lda, (DoublePointer) B.data().addressPointer(), ldb, beta, (DoublePointer) C.data().addressPointer(), ldc); } else { Nd4j.getExecutioner() .exec(new AggregateGEMM('f', TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc)); } }
Example #29
Source File: DefaultDataBufferFactory.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * @param doublePointer * @param length * @return */ @Override public DataBuffer create(DoublePointer doublePointer, long length) { doublePointer.capacity(length); doublePointer.limit(length); doublePointer.position(0); return new DoubleBuffer(doublePointer, DoubleIndexer.create(doublePointer), length); }
Example #30
Source File: CpuLevel2.java From nd4j with Apache License 2.0 | 5 votes |
@Override protected void dger(char order, int M, int N, double alpha, INDArray X, int incX, INDArray Y, int incY, INDArray A, int lda) { cblas_dger(convertOrder('f'), M, N, alpha, (DoublePointer) X.data().addressPointer(), incX, (DoublePointer) Y.data().addressPointer(), incY, (DoublePointer) A.data().addressPointer(), lda); }