Search in sources :

Example 56 with Pointer

use of org.bytedeco.javacpp.Pointer in project nd4j by deeplearning4j.

the class CompressedDataBuffer method dup.

@Override
public DataBuffer dup() {
    Pointer nPtr = new BytePointer(compressionDescriptor.getCompressedLength());
    Pointer.memcpy(nPtr, pointer, compressionDescriptor.getCompressedLength());
    CompressionDescriptor nDesc = compressionDescriptor.clone();
    CompressedDataBuffer nBuf = new CompressedDataBuffer(nPtr, nDesc);
    return nBuf;
}
Also used : BytePointer(org.bytedeco.javacpp.BytePointer) BytePointer(org.bytedeco.javacpp.BytePointer) Pointer(org.bytedeco.javacpp.Pointer)

Example 57 with Pointer

use of org.bytedeco.javacpp.Pointer in project nd4j by deeplearning4j.

the class CompressedDataBuffer method readUnknown.

/**
 * Drop-in replacement wrapper for BaseDataBuffer.read() method, aware of CompressedDataBuffer
 * @param s
 * @return
 */
public static DataBuffer readUnknown(DataInputStream s, long length) {
    DataBuffer buffer = Nd4j.createBuffer(length);
    buffer.read(s);
    // if buffer is uncompressed, it'll be valid buffer, so we'll just return it
    if (buffer.dataType() != Type.COMPRESSED)
        return buffer;
    else {
        try {
            // if buffer is compressed one, we''ll restore and decompress it here
            String compressionAlgorithm = s.readUTF();
            long compressedLength = s.readLong();
            long originalLength = s.readLong();
            long numberOfElements = s.readLong();
            byte[] temp = new byte[(int) compressedLength];
            for (int i = 0; i < compressedLength; i++) {
                temp[i] = s.readByte();
            }
            try (Pointer pointer = new BytePointer(temp)) {
                CompressionDescriptor descriptor = new CompressionDescriptor();
                descriptor.setCompressedLength(compressedLength);
                descriptor.setCompressionAlgorithm(compressionAlgorithm);
                descriptor.setOriginalLength(originalLength);
                descriptor.setNumberOfElements(numberOfElements);
                CompressedDataBuffer compressedBuffer = new CompressedDataBuffer(pointer, descriptor);
                return Nd4j.getCompressor().decompress(compressedBuffer);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : BytePointer(org.bytedeco.javacpp.BytePointer) BytePointer(org.bytedeco.javacpp.BytePointer) Pointer(org.bytedeco.javacpp.Pointer) IOException(java.io.IOException) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) BaseDataBuffer(org.nd4j.linalg.api.buffer.BaseDataBuffer)

Example 58 with Pointer

use of org.bytedeco.javacpp.Pointer in project javacv by bytedeco.

the class CameraDevice method read.

public static CameraDevice[] read(CvFileStorage fs) throws Exception {
    CvFileNode node = cvGetFileNodeByName(fs, null, "Cameras");
    CvSeq seq = node.data_seq();
    int count = seq.total();
    CameraDevice[] devices = new CameraDevice[count];
    for (int i = 0; i < count; i++) {
        Pointer p = cvGetSeqElem(seq, i);
        if (p == null)
            continue;
        String name = cvReadString(new CvFileNode(p), (String) null);
        devices[i] = new CameraDevice(name, fs);
    }
    return devices;
}
Also used : Pointer(org.bytedeco.javacpp.Pointer)

Example 59 with Pointer

use of org.bytedeco.javacpp.Pointer in project javacv by bytedeco.

the class ProjectiveDevice method readParameters.

public void readParameters(CvFileStorage fs) throws Exception {
    if (fs == null) {
        throw new Exception("Error: CvFileStorage is null, cannot read parameters for device " + getSettings().getName() + ". Is the parametersFile correct?");
    }
    CvAttrList a = cvAttrList();
    CvFileNode fn = cvGetFileNodeByName(fs, null, getSettings().getName());
    if (fn == null) {
        throw new Exception("Error: CvFileNode is null, cannot read parameters for device " + getSettings().getName() + ". Is the name correct?");
    }
    imageWidth = cvReadIntByName(fs, fn, "imageWidth", imageWidth);
    imageHeight = cvReadIntByName(fs, fn, "imageHeight", imageHeight);
    getSettings().setResponseGamma(cvReadRealByName(fs, fn, "gamma", getSettings().getResponseGamma()));
    // getSettings().initAspectRatio = cvReadRealByName(fs, fn, "initAspectRatio", getSettings().initAspectRatio);
    // getSettings().flags = cvReadIntByName(fs, fn, "flags", getSettings().flags);
    Pointer p = cvReadByName(fs, fn, "cameraMatrix", a);
    cameraMatrix = p == null ? null : new CvMat(p);
    p = cvReadByName(fs, fn, "distortionCoeffs", a);
    distortionCoeffs = p == null ? null : new CvMat(p);
    p = cvReadByName(fs, fn, "extrParams", a);
    extrParams = p == null ? null : new CvMat(p);
    p = cvReadByName(fs, fn, "reprojErrs", a);
    reprojErrs = p == null ? null : new CvMat(p);
    avgReprojErr = cvReadRealByName(fs, fn, "avgReprojErr", avgReprojErr);
    maxReprojErr = cvReadRealByName(fs, fn, "maxReprojErr", maxReprojErr);
    // nominalDistance = cvReadRealByName(fs, fn, "nominalDistance", nominalDistance);
    p = cvReadByName(fs, fn, "R", a);
    R = p == null ? null : new CvMat(p);
    p = cvReadByName(fs, fn, "T", a);
    T = p == null ? null : new CvMat(p);
    p = cvReadByName(fs, fn, "E", a);
    E = p == null ? null : new CvMat(p);
    p = cvReadByName(fs, fn, "F", a);
    F = p == null ? null : new CvMat(p);
    avgEpipolarErr = cvReadRealByName(fs, fn, "avgEpipolarErr", avgEpipolarErr);
    maxEpipolarErr = cvReadRealByName(fs, fn, "maxEpipolarErr", maxEpipolarErr);
    colorOrder = cvReadStringByName(fs, fn, "colorOrder", colorOrder);
    p = cvReadByName(fs, fn, "colorMixingMatrix", a);
    colorMixingMatrix = p == null ? null : new CvMat(p);
    p = cvReadByName(fs, fn, "additiveLight", a);
    additiveLight = p == null ? null : new CvMat(p);
    avgColorErr = cvReadRealByName(fs, fn, "avgColorErr", avgColorErr);
    colorR2 = cvReadRealByName(fs, fn, "colorR2", colorR2);
}
Also used : Pointer(org.bytedeco.javacpp.Pointer)

Example 60 with Pointer

use of org.bytedeco.javacpp.Pointer in project javacv by bytedeco.

the class ProjectorDevice method read.

public static ProjectorDevice[] read(CvFileStorage fs) throws Exception {
    CvFileNode node = cvGetFileNodeByName(fs, null, "Projectors");
    CvSeq seq = node.data_seq();
    int count = seq.total();
    ProjectorDevice[] devices = new ProjectorDevice[count];
    for (int i = 0; i < count; i++) {
        Pointer p = cvGetSeqElem(seq, i);
        if (p == null)
            continue;
        String name = cvReadString(new CvFileNode(p), (String) null);
        devices[i] = new ProjectorDevice(name, fs);
    }
    return devices;
}
Also used : Pointer(org.bytedeco.javacpp.Pointer)

Aggregations

Pointer (org.bytedeco.javacpp.Pointer)68 FloatPointer (org.bytedeco.javacpp.FloatPointer)33 DoublePointer (org.bytedeco.javacpp.DoublePointer)31 IntPointer (org.bytedeco.javacpp.IntPointer)29 BytePointer (org.bytedeco.javacpp.BytePointer)23 CudaContext (org.nd4j.linalg.jcublas.context.CudaContext)23 INDArray (org.nd4j.linalg.api.ndarray.INDArray)21 ShortPointer (org.bytedeco.javacpp.ShortPointer)20 CudaPointer (org.nd4j.jita.allocator.pointers.CudaPointer)19 DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)18 GridExecutioner (org.nd4j.linalg.api.ops.executioner.GridExecutioner)16 ByteBuffer (java.nio.ByteBuffer)13 PointerPointer (org.bytedeco.javacpp.PointerPointer)12 LongPointer (org.bytedeco.javacpp.LongPointer)10 CUstream_st (org.bytedeco.javacpp.cuda.CUstream_st)10 org.nd4j.jita.allocator.pointers.cuda.cusolverDnHandle_t (org.nd4j.jita.allocator.pointers.cuda.cusolverDnHandle_t)10 CublasPointer (org.nd4j.linalg.jcublas.CublasPointer)10 FunctionPointer (org.bytedeco.javacpp.FunctionPointer)9 BoolPointer (org.bytedeco.javacpp.BoolPointer)8 CLongPointer (org.bytedeco.javacpp.CLongPointer)8