Search in sources :

Example 1 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project deeplearning4j by deeplearning4j.

the class NDArrayHDF5Reader method readFromPath.

/**
     * Reads an HDF5 file into an NDArray.
     *
     * @param inputFilePath Path of the HDF5 file
     * @return NDArray with data and a correct shape
     */
public INDArray readFromPath(Path inputFilePath) {
    try (hdf5.H5File h5File = new hdf5.H5File()) {
        h5File.openFile(inputFilePath.toString(), H5F_ACC_RDONLY);
        hdf5.DataSet dataSet = h5File.asCommonFG().openDataSet("data");
        int[] shape = extractShape(dataSet);
        long totalSize = ArrayUtil.prodLong(shape);
        DataBuffer dataBuffer = readFromDataSet(dataSet, (int) totalSize);
        INDArray input = Nd4j.create(shape);
        input.setData(dataBuffer);
        return input;
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) org.bytedeco.javacpp.hdf5(org.bytedeco.javacpp.hdf5) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer)

Example 2 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class DefaultRandom method nextGaussian.

@Override
public INDArray nextGaussian(char order, int[] shape) {
    int length = ArrayUtil.prod(shape);
    INDArray ret = Nd4j.create(shape, order);
    DataBuffer data = ret.data();
    for (int i = 0; i < length; i++) {
        data.put(i, nextGaussian());
    }
    return ret;
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer)

Example 3 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class DefaultRandom method nextInt.

@Override
public INDArray nextInt(int[] shape) {
    int length = ArrayUtil.prod(shape);
    INDArray ret = Nd4j.create(shape);
    DataBuffer data = ret.data();
    for (int i = 0; i < length; i++) {
        data.put(i, nextInt());
    }
    return ret;
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer)

Example 4 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class DefaultRandom method nextFloat.

@Override
public INDArray nextFloat(char order, int[] shape) {
    int length = ArrayUtil.prod(shape);
    INDArray ret = Nd4j.create(shape, order);
    DataBuffer data = ret.data();
    for (int i = 0; i < length; i++) {
        data.put(i, nextFloat());
    }
    return ret;
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer)

Example 5 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class DefaultRandom method nextDouble.

@Override
public INDArray nextDouble(char order, int[] shape) {
    int length = ArrayUtil.prod(shape);
    INDArray ret = Nd4j.create(shape, order);
    DataBuffer data = ret.data();
    for (int i = 0; i < length; i++) {
        data.put(i, nextDouble());
    }
    return ret;
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer)

Aggregations

DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)186 INDArray (org.nd4j.linalg.api.ndarray.INDArray)79 Test (org.junit.Test)47 CompressedDataBuffer (org.nd4j.linalg.compression.CompressedDataBuffer)44 CudaContext (org.nd4j.linalg.jcublas.context.CudaContext)39 CudaPointer (org.nd4j.jita.allocator.pointers.CudaPointer)30 AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)25 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)23 BaseDataBuffer (org.nd4j.linalg.api.buffer.BaseDataBuffer)19 Pointer (org.bytedeco.javacpp.Pointer)18 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)16 CudaDoubleDataBuffer (org.nd4j.linalg.jcublas.buffer.CudaDoubleDataBuffer)16 IntPointer (org.bytedeco.javacpp.IntPointer)13 PagedPointer (org.nd4j.linalg.api.memory.pointers.PagedPointer)13 CudaIntDataBuffer (org.nd4j.linalg.jcublas.buffer.CudaIntDataBuffer)13 DoublePointer (org.bytedeco.javacpp.DoublePointer)12 FloatPointer (org.bytedeco.javacpp.FloatPointer)12 GridExecutioner (org.nd4j.linalg.api.ops.executioner.GridExecutioner)12 LongPointerWrapper (org.nd4j.nativeblas.LongPointerWrapper)11 CUstream_st (org.bytedeco.javacpp.cuda.CUstream_st)10