/** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ public IntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { super(sizes, strides); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); }
/** Calls {@code IntRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ public IntRawIndexer(IntPointer pointer) { this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); }
@Override public void release() { pointer.position(position).put(array); super.release(); } };
/** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ public static IntIndexer create(IntPointer pointer) { return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); }
/** * @param intPointer * @param length * @return */ @Override public DataBuffer create(IntPointer intPointer, long length) { intPointer.capacity(length); intPointer.limit(length); intPointer.position(0); return new IntBuffer(intPointer, IntIndexer.create(intPointer), length); }
/** * Creates a int indexer to access efficiently the data of a pointer. * * @param pointer data to access via a buffer or to copy to an array * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new int indexer backed by the raw memory interface, a buffer, or an array */ public static IntIndexer create(final IntPointer pointer, long[] sizes, long[] strides, boolean direct) { if (direct) { return Raw.getInstance() != null ? new IntRawIndexer(pointer, sizes, strides) : new IntBufferIndexer(pointer.asBuffer(), sizes, strides); } else { final long position = pointer.position(); int[] array = new int[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); return new IntArrayIndexer(array, sizes, strides) { @Override public void release() { pointer.position(position).put(array); super.release(); } }; } }
/** * For direct buffers, calls {@link Pointer#Pointer(Buffer)}, while for buffers * backed with an array, allocates enough memory for the array and copies it. * * @param buffer the Buffer to reference or copy * @see #put(int[]) */ public IntPointer(IntBuffer buffer) { super(buffer); if (buffer != null && !buffer.isDirect() && buffer.hasArray()) { int[] array = buffer.array(); allocateArray(array.length - buffer.arrayOffset()); put(array, buffer.arrayOffset(), array.length - buffer.arrayOffset()); position(buffer.position()); limit(buffer.limit()); } } /**
IntBuffer b = (IntBuffer)samples[i]; if (samples_in[i] instanceof IntPointer && samples_in[i].capacity() >= inputSize && b.hasArray()) { ((IntPointer)samples_in[i]).position(0).put(b.array(), samples[i].position(), inputSize); } else { samples_in[i] = new IntPointer(b);
IntBuffer b = (IntBuffer)samples[i]; if (samples_in[i] instanceof IntPointer && samples_in[i].capacity() >= inputSize && b.hasArray()) { ((IntPointer)samples_in[i]).position(0).put(b.array(), samples[i].position(), inputSize); } else { samples_in[i] = new IntPointer(b);
/** 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; }