Search in sources :

Example 21 with CompressedDataBuffer

use of org.nd4j.linalg.compression.CompressedDataBuffer in project nd4j by deeplearning4j.

the class Int16 method compressPointer.

@Override
protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length, int elementSize) {
    BytePointer ptr = new BytePointer(length * 2);
    CompressionDescriptor descriptor = new CompressionDescriptor();
    descriptor.setCompressedLength(length * 2);
    descriptor.setOriginalLength(length * elementSize);
    descriptor.setOriginalElementSize(elementSize);
    descriptor.setNumberOfElements(length);
    descriptor.setCompressionAlgorithm(getDescriptor());
    descriptor.setCompressionType(getCompressionType());
    CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor);
    Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.INT16, ptr, length);
    return buffer;
}
Also used : CompressionDescriptor(org.nd4j.linalg.compression.CompressionDescriptor) CompressedDataBuffer(org.nd4j.linalg.compression.CompressedDataBuffer) BytePointer(org.bytedeco.javacpp.BytePointer)

Example 22 with CompressedDataBuffer

use of org.nd4j.linalg.compression.CompressedDataBuffer in project nd4j by deeplearning4j.

the class BinarySerde method doByteBufferPutCompressed.

/**
 * Setup the given byte buffer
 * for serialization (note that this is for compressed INDArrays)
 * 4 bytes for rank
 * 4 bytes for data opType
 * shape information
 * codec information
 * data opType
 *
 * @param arr the array to setup
 * @param allocated the byte buffer to setup
 * @param rewind whether to rewind the byte buffer or not
 */
public static void doByteBufferPutCompressed(INDArray arr, ByteBuffer allocated, boolean rewind) {
    CompressedDataBuffer compressedDataBuffer = (CompressedDataBuffer) arr.data();
    CompressionDescriptor descriptor = compressedDataBuffer.getCompressionDescriptor();
    ByteBuffer codecByteBuffer = descriptor.toByteBuffer();
    ByteBuffer buffer = arr.data().pointer().asByteBuffer().order(ByteOrder.nativeOrder());
    ByteBuffer shapeBuffer = arr.shapeInfoDataBuffer().pointer().asByteBuffer().order(ByteOrder.nativeOrder());
    allocated.putInt(arr.rank());
    // put data opType next so its self describing
    allocated.putInt(arr.data().dataType().ordinal());
    // put shape next
    allocated.put(shapeBuffer);
    // put codec information next
    allocated.put(codecByteBuffer);
    // finally put the data
    allocated.put(buffer);
    if (rewind)
        allocated.rewind();
}
Also used : CompressionDescriptor(org.nd4j.linalg.compression.CompressionDescriptor) CompressedDataBuffer(org.nd4j.linalg.compression.CompressedDataBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

CompressedDataBuffer (org.nd4j.linalg.compression.CompressedDataBuffer)22 CompressionDescriptor (org.nd4j.linalg.compression.CompressionDescriptor)17 BytePointer (org.bytedeco.javacpp.BytePointer)10 DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)8 INDArray (org.nd4j.linalg.api.ndarray.INDArray)4 ByteBuffer (java.nio.ByteBuffer)3 IntPointer (org.bytedeco.javacpp.IntPointer)3 CudaDoubleDataBuffer (org.nd4j.linalg.jcublas.buffer.CudaDoubleDataBuffer)3 AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)2 CudaIntDataBuffer (org.nd4j.linalg.jcublas.buffer.CudaIntDataBuffer)2 CudaContext (org.nd4j.linalg.jcublas.context.CudaContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 Pointer (org.bytedeco.javacpp.Pointer)1 MatchCondition (org.nd4j.linalg.api.ops.impl.accum.MatchCondition)1