Java Code Examples for org.bytedeco.javacpp.FloatPointer#get()

The following examples show how to use org.bytedeco.javacpp.FloatPointer#get() . 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: FloatIndexer.java    From tapir with MIT License 6 votes vote down vote up
/**
 * Creates a float indexer to access efficiently the data of a pointer.
 *
 * @param pointer data to access via a buffer or to copy to an array
 * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details
 * @return the new float array backed by a buffer or an array
 */
public static FloatIndexer create(final FloatPointer pointer, int[] sizes, int[] strides, boolean direct) {
    if (direct) {
        return new FloatBufferIndexer(pointer.asBuffer(), sizes, strides);
    } else {
        final int position = pointer.position();
        float[] array = new float[pointer.limit() - position];
        pointer.get(array);
        return new FloatArrayIndexer(array, sizes, strides) {
            @Override public void release() {
                pointer.position(position).put(array);
                super.release();
            }
        };
    }
}
 
Example 2
Source File: CpuLapack.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Override
   public int ssyev( char jobz, char uplo, int N, INDArray A, INDArray R ) {
FloatPointer fp = new FloatPointer(1) ;
int status = LAPACKE_ssyev_work( getColumnOrder(A), (byte)jobz, (byte)uplo, 
				N, (FloatPointer)A.data().addressPointer(), getLda(A),
				(FloatPointer)R.data().addressPointer(), fp, -1 ) ;
if( status == 0 ) {
	int lwork = (int)fp.get() ;
	INDArray work = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createFloat(lwork),
	                Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, lwork}).getFirst());

	status = LAPACKE_ssyev( getColumnOrder(A), (byte)jobz, (byte)uplo, N, 
	            (FloatPointer)A.data().addressPointer(), getLda(A),
		    (FloatPointer)work.data().addressPointer() ) ;
	if( status == 0 ) {
		R.assign( work.get( NDArrayIndex.interval(0,N) ) ) ;
	}
}
return status ;
   }
 
Example 3
Source File: CpuLapack.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Override
   public int ssyev( char jobz, char uplo, int N, INDArray A, INDArray R ) {
FloatPointer fp = new FloatPointer(1) ;
int status = LAPACKE_ssyev_work( getColumnOrder(A), (byte)jobz, (byte)uplo, 
				N, (FloatPointer)A.data().addressPointer(), getLda(A),
				(FloatPointer)R.data().addressPointer(), fp, -1 ) ;
if( status == 0 ) {
	int lwork = (int)fp.get() ;
	INDArray work = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createFloat(lwork),
	                Nd4j.getShapeInfoProvider().createShapeInformation(new long[] {lwork}, A.dataType()).getFirst());

	status = LAPACKE_ssyev( getColumnOrder(A), (byte)jobz, (byte)uplo, N, 
	            (FloatPointer)A.data().addressPointer(), getLda(A),
		    (FloatPointer)work.data().addressPointer() ) ;
	if( status == 0 ) {
		R.assign(work.get(NDArrayIndex.interval(0,N))) ;
	}
}
return status ;
   }
 
Example 4
Source File: MatImagePlusConverter.java    From IJ-OpenCV with GNU General Public License v3.0 5 votes vote down vote up
private static FloatProcessor makeFloatProcessor(Mat mat) {
    if (mat.type() != opencv_core.CV_32FC1) {
        throw new IllegalArgumentException("wrong Mat type: " + mat.type());
    }
    final int w = mat.cols();
    final int h = mat.rows();
    FloatProcessor fp = new FloatProcessor(w, h);
    FloatPointer fptr = new FloatPointer(mat.data());
    fptr.get((float[]) fp.getPixels());
    fptr.close();
    return fp;
}
 
Example 5
Source File: JcublasLevel1.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
protected float sdot(long N, INDArray X, int incX, INDArray Y, int incY) {
    if (Nd4j.dataType() != DataBuffer.Type.FLOAT)
        logger.warn("FLOAT dot called");

    DataTypeValidation.assertSameDataType(X, Y);

    Nd4j.getExecutioner().push();

    CudaContext ctx = allocator.getFlowController().prepareAction(null, X, Y);

    float ret = 1f;

    CublasPointer xCPointer = new CublasPointer(X, ctx);
    CublasPointer yCPointer = new CublasPointer(Y, ctx);

    cublasHandle_t handle = ctx.getHandle();
    synchronized (handle) {
        long result = cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream()));
        if (result != 0)
            throw new IllegalStateException("cublasSetStream failed");

        FloatPointer resultPointer = new FloatPointer(0.0f);
        result = cublasSdot_v2(new cublasContext(handle), (int) N, (FloatPointer) xCPointer.getDevicePointer(), incX,
                        (FloatPointer) yCPointer.getDevicePointer(), incY, resultPointer);
        ret = resultPointer.get();
    }

    allocator.registerAction(ctx, null, X, Y);

    return ret;
}
 
Example 6
Source File: JcublasLevel1.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
protected float snrm2(long N, INDArray X, int incX) {
    if (Nd4j.dataType() != DataBuffer.Type.FLOAT)
        logger.warn("FLOAT nrm2 called");

    Nd4j.getExecutioner().push();


    CudaContext ctx = allocator.getFlowController().prepareAction(null, X);
    float ret;

    CublasPointer cAPointer = new CublasPointer(X, ctx);

    cublasHandle_t handle = ctx.getHandle();
    synchronized (handle) {
        cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream()));

        FloatPointer resultPointer = new FloatPointer(0.0f);
        cublasSnrm2_v2(new cublasContext(handle), (int) N, (FloatPointer) cAPointer.getDevicePointer(), incX,
                        resultPointer);
        ret = resultPointer.get();
    }

    allocator.registerAction(ctx, null, X);

    return ret;
}
 
Example 7
Source File: Nd4jMatrix.java    From jstarcraft-ai with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeSave() {
    data = new float[rowSize * columnSize];
    FloatPointer pointer = (FloatPointer) matrix.data().pointer();
    pointer.get(data, 0, data.length);
}
 
Example 8
Source File: Nd4jVector.java    From jstarcraft-ai with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeSave() {
    data = new float[size];
    FloatPointer pointer = (FloatPointer) vector.data().pointer();
    pointer.get(data, 0, data.length);
}