/** * Creates a bfloat16 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 short indexer backed by the raw memory interface, a buffer, or an array */ public static Bfloat16Indexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) { if (direct) { return Raw.getInstance() != null ? new Bfloat16RawIndexer(pointer, sizes, strides) : new Bfloat16BufferIndexer(pointer.asBuffer(), sizes, strides); } else { final long position = pointer.position(); short[] array = new short[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); return new Bfloat16ArrayIndexer(array, sizes, strides) { @Override public void release() { pointer.position(position).put(array); super.release(); } }; } }