/** * @param doublePointer * @param length * @return */ @Override public DataBuffer create(DoublePointer doublePointer, long length) { doublePointer.capacity(length); doublePointer.limit(length); doublePointer.position(0); return new DoubleBuffer(doublePointer, DoubleIndexer.create(doublePointer), length); }
@Override public DoubleIndexer createIndexer(boolean direct) { int[] w = {0}, h = {0}; dpixGetDimensions((DPIX)this, w, h); int wpl = dpixGetWpl((DPIX)this); long[] sizes = {h[0], w[0], wpl / w[0]}; long[] strides = {wpl, wpl / w[0], 1}; DoublePointer data = new DoublePointer(dpixGetData((DPIX)this)).capacity(h[0] * wpl); return DoubleIndexer.create(data, sizes, strides, direct); }
/** @return {@link DPIX#data()} wrapped in a {@link DoubleBuffer} starting at given byte index. */ public DoubleBuffer createBuffer(int index) { int[] w = {0}, h = {0}; dpixGetDimensions((DPIX)this, w, h); int wpl = dpixGetWpl((DPIX)this); DoublePointer data = new DoublePointer(dpixGetData((DPIX)this)).position(index).capacity(h[0] * wpl); return data.asBuffer(); }
/** Returns {@link #tensor_data()} wrapped in a {@link Buffer} of appropriate type starting at given index. */ public <B extends Buffer> B createBuffer(long index) { BytePointer ptr = tensor_data(); long size = TotalBytes(); switch (dtype()) { case DT_COMPLEX64: case DT_FLOAT: return (B)new FloatPointer(ptr).position(index).capacity(size/4).asBuffer(); case DT_DOUBLE: return (B)new DoublePointer(ptr).position(index).capacity(size/8).asBuffer(); case DT_QINT32: case DT_INT32: return (B)new IntPointer(ptr).position(index).capacity(size/4).asBuffer(); case DT_BOOL: case DT_QUINT8: case DT_UINT8: case DT_QINT8: case DT_INT8: return (B)ptr.position(index).capacity(size).asBuffer(); case DT_BFLOAT16: case DT_INT16: return (B)new ShortPointer(ptr).position(index).capacity(size/2).asBuffer(); case DT_INT64: return (B)new LongPointer(ptr).position(index).capacity(size/8).asBuffer(); case DT_STRING: default: assert false; } return null; }
case DT_COMPLEX64: case DT_FLOAT: return (I)FloatIndexer.create(new FloatPointer(ptr).capacity(size/4), sizes, strides, direct).indexable(this); case DT_DOUBLE: return (I)DoubleIndexer.create(new DoublePointer(ptr).capacity(size/8), sizes, strides, direct).indexable(this); case DT_QINT32: case DT_INT32: return (I)IntIndexer.create(new IntPointer(ptr).capacity(size/4), sizes, strides, direct).indexable(this);