public static int byteBufferSizeFor ( INDArray arr ) { if ( ! arr . isCompressed ( ) ) { ByteBuffer buffer = arr . data ( ) . pointer ( ) . asByteBuffer ( ) . order ( ByteOrder . nativeOrder ( ) ) ; ByteBuffer shapeBuffer = arr . shapeInfoDataBuffer ( ) . pointer ( ) . asByteBuffer ( ) . order ( ByteOrder . nativeOrder ( ) ) ; //2 four byte ints at the beginning int twoInts = 8 ; return twoInts + buffer . limit ( ) + shapeBuffer . limit ( ) ; } else { 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 ( ) ) ; int twoInts = 2 * 4 ; return twoInts + buffer . limit ( ) + shapeBuffer . limit ( ) + codecByteBuffer . limit ( ) ; } }
Returns the byte buffer size for the given ndarray . This is an auxillary method for determining the size of the buffer size to allocate for sending an ndarray via the aeron media driver .