From 9e13085207411f46751b8af81645fea2cb5d4982 Mon Sep 17 00:00:00 2001 From: Matteo Di Giovinazzo Date: Sun, 19 Apr 2020 19:49:32 -0600 Subject: [PATCH] #391 Apply changes to all indexers --- .../javacpp/indexer/Bfloat16ArrayIndexer.java | 27 ++++++-- .../indexer/Bfloat16BufferIndexer.java | 26 +++++-- .../javacpp/indexer/Bfloat16Indexer.java | 63 ++++++++++++----- .../javacpp/indexer/Bfloat16RawIndexer.java | 26 +++++-- .../javacpp/indexer/BooleanArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/BooleanBufferIndexer.java | 26 +++++-- .../javacpp/indexer/BooleanIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/BooleanRawIndexer.java | 24 +++++-- .../javacpp/indexer/ByteArrayIndexer.java | 26 +++++-- .../javacpp/indexer/ByteBufferIndexer.java | 26 +++++-- .../bytedeco/javacpp/indexer/ByteIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/ByteRawIndexer.java | 24 +++++-- .../javacpp/indexer/CharArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/CharBufferIndexer.java | 22 ++++-- .../bytedeco/javacpp/indexer/CharIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/CharRawIndexer.java | 27 ++++++-- .../javacpp/indexer/DoubleArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/DoubleBufferIndexer.java | 26 +++++-- .../javacpp/indexer/DoubleIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/DoubleRawIndexer.java | 26 +++++-- .../javacpp/indexer/FloatArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/FloatBufferIndexer.java | 26 +++++-- .../javacpp/indexer/FloatIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/FloatRawIndexer.java | 26 +++++-- .../javacpp/indexer/HalfArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/HalfBufferIndexer.java | 26 +++++-- .../bytedeco/javacpp/indexer/HalfIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/HalfRawIndexer.java | 26 +++++-- .../javacpp/indexer/IntArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/IntBufferIndexer.java | 26 +++++-- .../bytedeco/javacpp/indexer/IntIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/IntRawIndexer.java | 26 +++++-- .../javacpp/indexer/LongArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/LongBufferIndexer.java | 26 +++++-- .../bytedeco/javacpp/indexer/LongIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/LongRawIndexer.java | 26 +++++-- .../javacpp/indexer/ShortArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/ShortBufferIndexer.java | 26 +++++-- .../javacpp/indexer/ShortIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/ShortRawIndexer.java | 26 +++++-- .../javacpp/indexer/UByteArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/UByteBufferIndexer.java | 22 ++++-- .../javacpp/indexer/UByteIndexer.java | 67 ++++++++++++++----- .../javacpp/indexer/UByteRawIndexer.java | 24 +++++-- .../javacpp/indexer/UIntArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/UIntBufferIndexer.java | 26 +++++-- .../bytedeco/javacpp/indexer/UIntIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/UIntRawIndexer.java | 28 +++++--- .../javacpp/indexer/ULongArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/ULongBufferIndexer.java | 26 +++++-- .../javacpp/indexer/ULongIndexer.java | 59 ++++++++++++---- .../javacpp/indexer/ULongRawIndexer.java | 26 +++++-- .../javacpp/indexer/UShortArrayIndexer.java | 27 ++++++-- .../javacpp/indexer/UShortBufferIndexer.java | 26 +++++-- .../javacpp/indexer/UShortIndexer.java | 63 ++++++++++++----- .../javacpp/indexer/UShortRawIndexer.java | 26 +++++-- 56 files changed, 1464 insertions(+), 512 deletions(-) diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16ArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16ArrayIndexer.java index ee99164d7..74ee580ab 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16ArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16ArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code short[]} array, treated as bfloat16. * @@ -31,19 +34,24 @@ public class Bfloat16ArrayIndexer extends Bfloat16Indexer { /** The backing array. */ protected short[] array; - /** Calls {@code Bfloat16ArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code Bfloat16ArrayIndexer(array, defaultIndex({ array.length }))}. */ public Bfloat16ArrayIndexer(short[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code Bfloat16ArrayIndexer(array, sizes, strides(sizes))}. */ - public Bfloat16ArrayIndexer(short[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code Bfloat16ArrayIndexer(array, sizes)}. */ + @Deprecated public Bfloat16ArrayIndexer(short[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public Bfloat16ArrayIndexer(short[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public Bfloat16ArrayIndexer(short[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public Bfloat16ArrayIndexer(short[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public Bfloat16ArrayIndexer(short[] array, long[] sizes, long[] strides) { return array; } + @Override + public Bfloat16Indexer slice(Index index) { + return new Bfloat16ArrayIndexer(array, index); + } + @Override public float get(long i) { return toFloat(array[(int)index(i)]); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16BufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16BufferIndexer.java index 5ad9d8966..472790522 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16BufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16BufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.ShortBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ShortBuffer}, treated as bfloat16. @@ -34,19 +36,24 @@ public class Bfloat16BufferIndexer extends Bfloat16Indexer { /** The backing buffer. */ protected ShortBuffer buffer; - /** Calls {@code Bfloat16BufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code Bfloat16BufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public Bfloat16BufferIndexer(ShortBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code Bfloat16BufferIndexer(buffer, sizes, strides(sizes))}. */ - public Bfloat16BufferIndexer(ShortBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code Bfloat16BufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public Bfloat16BufferIndexer(ShortBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public Bfloat16BufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public Bfloat16BufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public Bfloat16BufferIndexer(ShortBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public Bfloat16BufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public Bfloat16Indexer slice(Index index) { + return new Bfloat16BufferIndexer(buffer, index); + } + @Override public float get(long i) { return toFloat(buffer.get((int)index(i))); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16Indexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16Indexer.java index 8f659e64b..7369e4e00 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16Indexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16Indexer.java @@ -24,6 +24,7 @@ import java.nio.ShortBuffer; import org.bytedeco.javacpp.ShortPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code short} primitive type, treated as bfloat16. @@ -36,6 +37,11 @@ public abstract class Bfloat16Indexer extends Indexer { /** The number of bytes used to represent a short. */ public static final int VALUE_BYTES = 2; + protected Bfloat16Indexer(Index index) { + super(index); + } + + @Deprecated protected Bfloat16Indexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -48,35 +54,48 @@ public static Bfloat16Indexer create(short[] array) { public static Bfloat16Indexer create(ShortBuffer buffer) { return new Bfloat16BufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new Bfloat16RawIndexer(pointer} */ public static Bfloat16Indexer create(ShortPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new Bfloat16RawIndexer(pointer); + } + + /** Returns {@code new Bfloat16ArrayIndexer(array, index)} */ + public static Bfloat16Indexer create(short[] array, Index index) { + return new Bfloat16ArrayIndexer(array, index); + } + /** Returns {@code new Bfloat16BufferIndexer(buffer, index)} */ + public static Bfloat16Indexer create(ShortBuffer buffer, Index index) { + return new Bfloat16BufferIndexer(buffer, index); + } + /** Returns {@code new Bfloat16RawIndexer(pointer, index)} */ + public static Bfloat16Indexer create(ShortPointer pointer, Index index) { + return new Bfloat16RawIndexer(pointer, index); } /** Returns {@code new Bfloat16ArrayIndexer(array, sizes)} */ - public static Bfloat16Indexer create(short[] array, long... sizes) { + @Deprecated public static Bfloat16Indexer create(short[] array, long... sizes) { return new Bfloat16ArrayIndexer(array, sizes); } /** Returns {@code new Bfloat16BufferIndexer(buffer, sizes)} */ - public static Bfloat16Indexer create(ShortBuffer buffer, long... sizes) { + @Deprecated public static Bfloat16Indexer create(ShortBuffer buffer, long... sizes) { return new Bfloat16BufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static Bfloat16Indexer create(ShortPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new Bfloat16RawIndexer(pointer, sizes)} */ + @Deprecated public static Bfloat16Indexer create(ShortPointer pointer, long... sizes) { + return new Bfloat16RawIndexer(pointer, sizes); } /** Returns {@code new Bfloat16ArrayIndexer(array, sizes, strides)} */ - public static Bfloat16Indexer create(short[] array, long[] sizes, long[] strides) { + @Deprecated public static Bfloat16Indexer create(short[] array, long[] sizes, long[] strides) { return new Bfloat16ArrayIndexer(array, sizes, strides); } /** Returns {@code new Bfloat16BufferIndexer(buffer, sizes, strides)} */ - public static Bfloat16Indexer create(ShortBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static Bfloat16Indexer create(ShortBuffer buffer, long[] sizes, long[] strides) { return new Bfloat16BufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static Bfloat16Indexer create(ShortPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new Bfloat16RawIndexer(pointer, sizes, strides)} */ + @Deprecated public static Bfloat16Indexer create(ShortPointer pointer, long[] sizes, long[] strides) { + return new Bfloat16RawIndexer(pointer, sizes, strides); } /** * Creates a bfloat16 indexer to access efficiently the data of a pointer. @@ -85,15 +104,27 @@ public static Bfloat16Indexer create(ShortPointer pointer, long[] sizes, long[] * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new bfloat16 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) { + @Deprecated public static Bfloat16Indexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * 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 index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new bfloat16 indexer backed by the raw memory interface, a buffer, or an array + */ + public static Bfloat16Indexer create(final ShortPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new Bfloat16RawIndexer(pointer, sizes, strides) - : new Bfloat16BufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new Bfloat16RawIndexer(pointer, index) + : new Bfloat16BufferIndexer(pointer.asBuffer(), index); } 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) { + return new Bfloat16ArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16RawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16RawIndexer.java index 8494ac9f7..6c7b1ee45 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16RawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16RawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.Pointer; import org.bytedeco.javacpp.ShortPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ShortPointer} using the {@link Raw} instance, treated as bfloat16. @@ -38,19 +40,24 @@ public class Bfloat16RawIndexer extends Bfloat16Indexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code Bfloat16RawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code Bfloat16RawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public Bfloat16RawIndexer(ShortPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code Bfloat16RawIndexer(pointer, sizes, strides(sizes))}. */ - public Bfloat16RawIndexer(ShortPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code Bfloat16RawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public Bfloat16RawIndexer(ShortPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public Bfloat16RawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public Bfloat16RawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public Bfloat16RawIndexer(ShortPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public Bfloat16RawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public Bfloat16Indexer slice(Index index) { + return new Bfloat16RawIndexer(pointer, index); + } + public float getRaw(long i) { return toFloat(RAW.getShort(base + checkIndex(i, size) * VALUE_BYTES)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/BooleanArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/BooleanArrayIndexer.java index 696211ac8..491a1e4c8 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/BooleanArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/BooleanArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code boolean[]} array. * @@ -31,19 +34,24 @@ public class BooleanArrayIndexer extends BooleanIndexer { /** The backing array. */ protected boolean[] array; - /** Calls {@code BooleanArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code BooleanArrayIndexer(array, defaultIndex({ array.length }))}. */ public BooleanArrayIndexer(boolean[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code BooleanArrayIndexer(array, sizes, strides(sizes))}. */ - public BooleanArrayIndexer(boolean[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code BooleanArrayIndexer(array, sizes)}. */ + @Deprecated public BooleanArrayIndexer(boolean[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public BooleanArrayIndexer(boolean[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public BooleanArrayIndexer(boolean[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public BooleanArrayIndexer(boolean[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public BooleanArrayIndexer(boolean[] array, long[] sizes, long[] strides) { return array; } + @Override + public BooleanIndexer slice(Index index) { + return new BooleanArrayIndexer(array, index); + } + @Override public boolean get(long i) { return array[(int)index(i)]; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/BooleanBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/BooleanBufferIndexer.java index 603a73407..560532448 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/BooleanBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/BooleanBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.ByteBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ByteBuffer} as {@code boolean} values. @@ -34,19 +36,24 @@ public class BooleanBufferIndexer extends BooleanIndexer { /** The backing buffer. */ protected ByteBuffer buffer; - /** Calls {@code BooleanBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code BooleanBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public BooleanBufferIndexer(ByteBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code BooleanBufferIndexer(buffer, sizes, strides(sizes))}. */ - public BooleanBufferIndexer(ByteBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code BooleanBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public BooleanBufferIndexer(ByteBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public BooleanBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public BooleanBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public BooleanBufferIndexer(ByteBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public BooleanBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public BooleanIndexer slice(Index index) { + return new BooleanBufferIndexer(buffer, index); + } + @Override public boolean get(long i) { return buffer.get((int)index(i)) != 0; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/BooleanIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/BooleanIndexer.java index f6c60fafb..1754dec44 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/BooleanIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/BooleanIndexer.java @@ -24,6 +24,7 @@ import java.nio.ByteBuffer; import org.bytedeco.javacpp.BooleanPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code boolean} primitive type. @@ -34,6 +35,11 @@ public abstract class BooleanIndexer extends Indexer { /** The number of bytes used to represent a boolean. */ public static final int VALUE_BYTES = 1; + protected BooleanIndexer(Index index) { + super(index); + } + + @Deprecated protected BooleanIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static BooleanIndexer create(boolean[] array) { public static BooleanIndexer create(ByteBuffer buffer) { return new BooleanBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new BooleanRawIndexer(pointer} */ public static BooleanIndexer create(BooleanPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new BooleanRawIndexer(pointer); + } + + /** Returns {@code new BooleanArrayIndexer(array, index)} */ + public static BooleanIndexer create(boolean[] array, Index index) { + return new BooleanArrayIndexer(array, index); + } + /** Returns {@code new BooleanBufferIndexer(buffer, index)} */ + public static BooleanIndexer create(ByteBuffer buffer, Index index) { + return new BooleanBufferIndexer(buffer, index); + } + /** Returns {@code new BooleanRawIndexer(pointer, index)} */ + public static BooleanIndexer create(BooleanPointer pointer, Index index) { + return new BooleanRawIndexer(pointer, index); } /** Returns {@code new BooleanArrayIndexer(array, sizes)} */ - public static BooleanIndexer create(boolean[] array, long... sizes) { + @Deprecated public static BooleanIndexer create(boolean[] array, long... sizes) { return new BooleanArrayIndexer(array, sizes); } /** Returns {@code new BooleanBufferIndexer(buffer, sizes)} */ - public static BooleanIndexer create(ByteBuffer buffer, long... sizes) { + @Deprecated public static BooleanIndexer create(ByteBuffer buffer, long... sizes) { return new BooleanBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static BooleanIndexer create(BooleanPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new BooleanRawIndexer(pointer, index)} */ + @Deprecated public static BooleanIndexer create(BooleanPointer pointer, long... sizes) { + return new BooleanRawIndexer(pointer, sizes); } /** Returns {@code new BooleanArrayIndexer(array, sizes, strides)} */ - public static BooleanIndexer create(boolean[] array, long[] sizes, long[] strides) { + @Deprecated public static BooleanIndexer create(boolean[] array, long[] sizes, long[] strides) { return new BooleanArrayIndexer(array, sizes, strides); } /** Returns {@code new BooleanBufferIndexer(buffer, sizes, strides)} */ - public static BooleanIndexer create(ByteBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static BooleanIndexer create(ByteBuffer buffer, long[] sizes, long[] strides) { return new BooleanBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static BooleanIndexer create(BooleanPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new BooleanRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static BooleanIndexer create(BooleanPointer pointer, long[] sizes, long[] strides) { + return new BooleanRawIndexer(pointer, sizes, strides); } /** * Creates a boolean indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static BooleanIndexer create(BooleanPointer pointer, long[] sizes, long[] * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new boolean indexer backed by the raw memory interface, a buffer, or an array */ - public static BooleanIndexer create(final BooleanPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static BooleanIndexer create(final BooleanPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a boolean indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new boolean indexer backed by the raw memory interface, a buffer, or an array + */ + public static BooleanIndexer create(final BooleanPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new BooleanRawIndexer(pointer, sizes, strides) - : new BooleanBufferIndexer(pointer.asByteBuffer(), sizes, strides); + return Raw.getInstance() != null ? new BooleanRawIndexer(pointer, index) + : new BooleanBufferIndexer(pointer.asByteBuffer(), index); } else { final long position = pointer.position(); boolean[] array = new boolean[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new BooleanArrayIndexer(array, sizes, strides) { + return new BooleanArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/BooleanRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/BooleanRawIndexer.java index 9df03702a..a35fc36f6 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/BooleanRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/BooleanRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.BooleanPointer; import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link BooleanPointer} using the {@link Raw} instance. @@ -38,19 +40,24 @@ public class BooleanRawIndexer extends BooleanIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code BooleanRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code BooleanRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public BooleanRawIndexer(BooleanPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code BooleanRawIndexer(pointer, sizes, strides(sizes))}. */ - public BooleanRawIndexer(BooleanPointer pointer, long... sizes) { + /** Calls {@code BooleanRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public BooleanRawIndexer(BooleanPointer pointer, long... sizes) { this(pointer, sizes, strides(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public BooleanRawIndexer(BooleanPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public BooleanRawIndexer(BooleanPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public BooleanRawIndexer(BooleanPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public BooleanRawIndexer(BooleanPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public BooleanIndexer slice(Index index) { + return new BooleanRawIndexer(pointer, index); + } + public boolean getRaw(long i) { return RAW.getBoolean(base + checkIndex(i, size) * VALUE_BYTES); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ByteArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ByteArrayIndexer.java index c190942ed..9c4107f69 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ByteArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ByteArrayIndexer.java @@ -24,6 +24,8 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@code byte[]} array. @@ -38,19 +40,24 @@ public class ByteArrayIndexer extends ByteIndexer { /** The backing array. */ protected byte[] array; - /** Calls {@code ByteArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code ByteArrayIndexer(array, defaultIndex({ array.length }))}. */ public ByteArrayIndexer(byte[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code ByteArrayIndexer(array, sizes, strides(sizes))}. */ - public ByteArrayIndexer(byte[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code ByteArrayIndexer(array, sizes)}. */ + @Deprecated public ByteArrayIndexer(byte[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public ByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public ByteArrayIndexer(byte[] array, Index index) { + super(index); this.array = array; } @@ -58,6 +65,11 @@ public ByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { return array; } + @Override + public ByteIndexer slice(Index index) { + return new ByteArrayIndexer(array, index); + } + @Override public byte get(long i) { return array[(int)index(i)]; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ByteBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ByteBufferIndexer.java index 2cd447895..d015178dd 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ByteBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ByteBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.ByteBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ByteBuffer}. @@ -34,19 +36,24 @@ public class ByteBufferIndexer extends ByteIndexer { /** The backing buffer. */ protected ByteBuffer buffer; - /** Calls {@code ByteBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code ByteBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public ByteBufferIndexer(ByteBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code ByteBufferIndexer(buffer, sizes, strides(sizes))}. */ - public ByteBufferIndexer(ByteBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code ByteBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public ByteBufferIndexer(ByteBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public ByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public ByteBufferIndexer(ByteBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public ByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public ByteIndexer slice(Index index) { + return new ByteBufferIndexer(buffer, index); + } + @Override public byte get(long i) { return buffer.get((int)index(i)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java index b58995890..6c595525c 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java @@ -25,6 +25,7 @@ import java.math.BigInteger; import java.nio.ByteBuffer; import org.bytedeco.javacpp.BytePointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code byte} primitive type. @@ -35,6 +36,11 @@ public abstract class ByteIndexer extends Indexer { /** The number of bytes used to represent a byte. */ public static final int VALUE_BYTES = 1; + protected ByteIndexer(Index index) { + super(index); + } + + @Deprecated protected ByteIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -47,35 +53,48 @@ public static ByteIndexer create(byte[] array) { public static ByteIndexer create(ByteBuffer buffer) { return new ByteBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new ByteRawIndexer(pointer} */ public static ByteIndexer create(BytePointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new ByteRawIndexer(pointer); + } + + /** Returns {@code new ByteArrayIndexer(array, index)} */ + public static ByteIndexer create(byte[] array, Index index) { + return new ByteArrayIndexer(array, index); + } + /** Returns {@code new ByteBufferIndexer(buffer, index)} */ + public static ByteIndexer create(ByteBuffer buffer, Index index) { + return new ByteBufferIndexer(buffer, index); + } + /** Returns {@code new ByteRawIndexer(pointer, index)} */ + public static ByteIndexer create(BytePointer pointer, Index index) { + return new ByteRawIndexer(pointer, index); } /** Returns {@code new ByteArrayIndexer(array, sizes)} */ - public static ByteIndexer create(byte[] array, long... sizes) { + @Deprecated public static ByteIndexer create(byte[] array, long... sizes) { return new ByteArrayIndexer(array, sizes); } /** Returns {@code new ByteBufferIndexer(buffer, sizes)} */ - public static ByteIndexer create(ByteBuffer buffer, long... sizes) { + @Deprecated public static ByteIndexer create(ByteBuffer buffer, long... sizes) { return new ByteBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static ByteIndexer create(BytePointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new ByteRawIndexer(pointer, index)} */ + @Deprecated public static ByteIndexer create(BytePointer pointer, long... sizes) { + return new ByteRawIndexer(pointer, sizes); } /** Returns {@code new ByteArrayIndexer(array, sizes, strides)} */ - public static ByteIndexer create(byte[] array, long[] sizes, long[] strides) { + @Deprecated public static ByteIndexer create(byte[] array, long[] sizes, long[] strides) { return new ByteArrayIndexer(array, sizes, strides); } /** Returns {@code new ByteBufferIndexer(buffer, sizes, strides)} */ - public static ByteIndexer create(ByteBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static ByteIndexer create(ByteBuffer buffer, long[] sizes, long[] strides) { return new ByteBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static ByteIndexer create(BytePointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new ByteRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static ByteIndexer create(BytePointer pointer, long[] sizes, long[] strides) { + return new ByteRawIndexer(pointer, sizes, strides); } /** * Creates a byte indexer to access efficiently the data of a pointer. @@ -84,15 +103,27 @@ public static ByteIndexer create(BytePointer pointer, long[] sizes, long[] strid * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new byte indexer backed by the raw memory interface, a buffer, or an array */ - public static ByteIndexer create(final BytePointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static ByteIndexer create(final BytePointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a byte indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new byte indexer backed by the raw memory interface, a buffer, or an array + */ + public static ByteIndexer create(final BytePointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new ByteRawIndexer(pointer, sizes, strides) - : new ByteBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new ByteRawIndexer(pointer, index) + : new ByteBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); byte[] array = new byte[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new ByteArrayIndexer(array, sizes, strides) { + return new ByteArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ByteRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ByteRawIndexer.java index ff34ba449..233aaf990 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ByteRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ByteRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.BytePointer; import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link BytePointer} using the {@link Raw} instance. @@ -38,19 +40,24 @@ public class ByteRawIndexer extends ByteIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code ByteRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code ByteRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public ByteRawIndexer(BytePointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code ByteRawIndexer(pointer, sizes, strides(sizes))}. */ - public ByteRawIndexer(BytePointer pointer, long... sizes) { + /** Calls {@code ByteRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public ByteRawIndexer(BytePointer pointer, long... sizes) { this(pointer, sizes, strides(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public ByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public ByteRawIndexer(BytePointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position(); size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public ByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public ByteIndexer slice(Index index) { + return new ByteRawIndexer(pointer, index); + } + public byte getRaw(long i) { return RAW.getByte(base + checkIndex(i, size)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/CharArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/CharArrayIndexer.java index f8ab8cd8e..52ab37a6d 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/CharArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/CharArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code char[]} array. * @@ -31,19 +34,24 @@ public class CharArrayIndexer extends CharIndexer { /** The backing array. */ protected char[] array; - /** Calls {@code CharArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code CharArrayIndexer(array, defaultIndex({ array.length }))}. */ public CharArrayIndexer(char[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code CharArrayIndexer(array, sizes, strides(sizes))}. */ - public CharArrayIndexer(char[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code CharArrayIndexer(array, sizes)}. */ + @Deprecated public CharArrayIndexer(char[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public CharArrayIndexer(char[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public CharArrayIndexer(char[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public CharArrayIndexer(char[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public CharArrayIndexer(char[] array, long[] sizes, long[] strides) { return array; } + @Override + public CharIndexer slice(Index index) { + return new CharArrayIndexer(array, index); + } + @Override public char get(long i) { return array[(int)index(i)]; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/CharBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/CharBufferIndexer.java index ae449a90f..4d3e8a8c2 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/CharBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/CharBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.CharBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link CharBuffer}. @@ -34,19 +36,24 @@ public class CharBufferIndexer extends CharIndexer { /** The backing buffer. */ protected CharBuffer buffer; - /** Calls {@code CharBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code CharBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public CharBufferIndexer(CharBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code CharBufferIndexer(buffer, sizes, strides(sizes))}. */ + /** Calls {@code CharBufferIndexer(buffer, defaultIndex(sizes))}. */ public CharBufferIndexer(CharBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ public CharBufferIndexer(CharBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public CharBufferIndexer(CharBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public CharBufferIndexer(CharBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public CharIndexer slice(Index index) { + return new CharBufferIndexer(buffer, index); + } + @Override public char get(long i) { return buffer.get((int)index(i)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/CharIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/CharIndexer.java index 4792fdffc..9d1c76387 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/CharIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/CharIndexer.java @@ -24,6 +24,7 @@ import java.nio.CharBuffer; import org.bytedeco.javacpp.CharPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code char} primitive type. @@ -34,6 +35,11 @@ public abstract class CharIndexer extends Indexer { /** The number of bytes used to represent a char. */ public static final int VALUE_BYTES = 2; + protected CharIndexer(Index index) { + super(index); + } + + @Deprecated protected CharIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static CharIndexer create(char[] array) { public static CharIndexer create(CharBuffer buffer) { return new CharBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new CharRawIndexer(pointer} */ public static CharIndexer create(CharPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new CharRawIndexer(pointer); + } + + /** Returns {@code new CharArrayIndexer(array, index)} */ + public static CharIndexer create(char[] array, Index index) { + return new CharArrayIndexer(array, index); + } + /** Returns {@code new CharBufferIndexer(buffer, index)} */ + public static CharIndexer create(CharBuffer buffer, Index index) { + return new CharBufferIndexer(buffer, index); + } + /** Returns {@code new CharRawIndexer(pointer, index)} */ + public static CharIndexer create(CharPointer pointer, Index index) { + return new CharRawIndexer(pointer, index); } /** Returns {@code new CharArrayIndexer(array, sizes)} */ - public static CharIndexer create(char[] array, long... sizes) { + @Deprecated public static CharIndexer create(char[] array, long... sizes) { return new CharArrayIndexer(array, sizes); } /** Returns {@code new CharBufferIndexer(buffer, sizes)} */ - public static CharIndexer create(CharBuffer buffer, long... sizes) { + @Deprecated public static CharIndexer create(CharBuffer buffer, long... sizes) { return new CharBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static CharIndexer create(CharPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new CharRawIndexer(pointer, sizes)} */ + @Deprecated public static CharIndexer create(CharPointer pointer, long... sizes) { + return new CharRawIndexer(pointer, sizes); } /** Returns {@code new CharArrayIndexer(array, sizes, strides)} */ - public static CharIndexer create(char[] array, long[] sizes, long[] strides) { + @Deprecated public static CharIndexer create(char[] array, long[] sizes, long[] strides) { return new CharArrayIndexer(array, sizes, strides); } /** Returns {@code new CharBufferIndexer(buffer, sizes, strides)} */ - public static CharIndexer create(CharBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static CharIndexer create(CharBuffer buffer, long[] sizes, long[] strides) { return new CharBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static CharIndexer create(CharPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new CharRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static CharIndexer create(CharPointer pointer, long[] sizes, long[] strides) { + return new CharRawIndexer(pointer, sizes, strides); } /** * Creates a char indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static CharIndexer create(CharPointer pointer, long[] sizes, long[] strid * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new char indexer backed by the raw memory interface, a buffer, or an array */ - public static CharIndexer create(final CharPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static CharIndexer create(final CharPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a char indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new char indexer backed by the raw memory interface, a buffer, or an array + */ + public static CharIndexer create(final CharPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new CharRawIndexer(pointer, sizes, strides) - : new CharBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new CharRawIndexer(pointer, index) + : new CharBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); char[] array = new char[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new CharArrayIndexer(array, sizes, strides) { + return new CharArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/CharRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/CharRawIndexer.java index b3885bab6..1edbcb62c 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/CharRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/CharRawIndexer.java @@ -23,7 +23,10 @@ package org.bytedeco.javacpp.indexer; import org.bytedeco.javacpp.CharPointer; +import org.bytedeco.javacpp.IntPointer; import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link CharPointer} using the {@link Raw} instance. @@ -38,19 +41,24 @@ public class CharRawIndexer extends CharIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code CharRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code CharRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public CharRawIndexer(CharPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code CharRawIndexer(pointer, sizes, strides(sizes))}. */ - public CharRawIndexer(CharPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code CharRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public CharRawIndexer(CharPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public CharRawIndexer(CharPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public CharRawIndexer(CharPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public CharRawIndexer(CharPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +68,11 @@ public CharRawIndexer(CharPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public CharIndexer slice(Index index) { + return new CharRawIndexer(pointer, index); + } + public char getRaw(long i) { return RAW.getChar(base + checkIndex(i, size) * VALUE_BYTES); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/DoubleArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/DoubleArrayIndexer.java index d22e2bd95..e9a671572 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/DoubleArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/DoubleArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code double[]} array. * @@ -31,19 +34,24 @@ public class DoubleArrayIndexer extends DoubleIndexer { /** The backing array. */ protected double[] array; - /** Calls {@code DoubleArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code DoubleArrayIndexer(array, defaultIndex({ array.length }))}. */ public DoubleArrayIndexer(double[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code DoubleArrayIndexer(array, sizes, strides(sizes))}. */ - public DoubleArrayIndexer(double[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code DoubleArrayIndexer(array, sizes)}. */ + @Deprecated public DoubleArrayIndexer(double[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public DoubleArrayIndexer(double[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public DoubleArrayIndexer(double[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public DoubleArrayIndexer(double[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public DoubleArrayIndexer(double[] array, long[] sizes, long[] strides) { return array; } + @Override + public DoubleIndexer slice(Index index) { + return new DoubleArrayIndexer(array, index); + } + @Override public double get(long i) { return array[(int)index(i)]; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/DoubleBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/DoubleBufferIndexer.java index e0f17b0d5..30e4cf355 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/DoubleBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/DoubleBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.DoubleBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link DoubleBuffer}. @@ -34,19 +36,24 @@ public class DoubleBufferIndexer extends DoubleIndexer { /** The backing buffer. */ protected DoubleBuffer buffer; - /** Calls {@code DoubleBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code DoubleBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public DoubleBufferIndexer(DoubleBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code DoubleBufferIndexer(buffer, sizes, strides(sizes))}. */ - public DoubleBufferIndexer(DoubleBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code DoubleBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public DoubleBufferIndexer(DoubleBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public DoubleBufferIndexer(DoubleBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public DoubleBufferIndexer(DoubleBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public DoubleBufferIndexer(DoubleBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public DoubleBufferIndexer(DoubleBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public DoubleIndexer slice(Index index) { + return new DoubleBufferIndexer(buffer, index); + } + @Override public double get(long i) { return buffer.get((int)index(i)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/DoubleIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/DoubleIndexer.java index 808278c90..4501421ff 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/DoubleIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/DoubleIndexer.java @@ -24,6 +24,7 @@ import java.nio.DoubleBuffer; import org.bytedeco.javacpp.DoublePointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code double} primitive type. @@ -34,6 +35,11 @@ public abstract class DoubleIndexer extends Indexer { /** The number of bytes used to represent a double. */ public static final int VALUE_BYTES = 8; + protected DoubleIndexer(Index index) { + super(index); + } + + @Deprecated protected DoubleIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static DoubleIndexer create(double[] array) { public static DoubleIndexer create(DoubleBuffer buffer) { return new DoubleBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new DoubleRawIndexer(pointer} */ public static DoubleIndexer create(DoublePointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new DoubleRawIndexer(pointer); + } + + /** Returns {@code new DoubleArrayIndexer(array, index)} */ + public static DoubleIndexer create(double[] array, Index index) { + return new DoubleArrayIndexer(array, index); + } + /** Returns {@code new DoubleBufferIndexer(buffer, index)} */ + public static DoubleIndexer create(DoubleBuffer buffer, Index index) { + return new DoubleBufferIndexer(buffer, index); + } + /** Returns {@code new DoubleRawIndexer(pointer, index)} */ + public static DoubleIndexer create(DoublePointer pointer, Index index) { + return new DoubleRawIndexer(pointer, index); } /** Returns {@code new DoubleArrayIndexer(array, sizes)} */ - public static DoubleIndexer create(double[] array, long... sizes) { + @Deprecated public static DoubleIndexer create(double[] array, long... sizes) { return new DoubleArrayIndexer(array, sizes); } /** Returns {@code new DoubleBufferIndexer(buffer, sizes)} */ - public static DoubleIndexer create(DoubleBuffer buffer, long... sizes) { + @Deprecated public static DoubleIndexer create(DoubleBuffer buffer, long... sizes) { return new DoubleBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static DoubleIndexer create(DoublePointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new DoubleRawIndexer(pointer, index)} */ + @Deprecated public static DoubleIndexer create(DoublePointer pointer, long... sizes) { + return new DoubleRawIndexer(pointer, sizes); } /** Returns {@code new DoubleArrayIndexer(array, sizes, strides)} */ - public static DoubleIndexer create(double[] array, long[] sizes, long[] strides) { + @Deprecated public static DoubleIndexer create(double[] array, long[] sizes, long[] strides) { return new DoubleArrayIndexer(array, sizes, strides); } /** Returns {@code new DoubleBufferIndexer(buffer, sizes, strides)} */ - public static DoubleIndexer create(DoubleBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static DoubleIndexer create(DoubleBuffer buffer, long[] sizes, long[] strides) { return new DoubleBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static DoubleIndexer create(DoublePointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new DoubleRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static DoubleIndexer create(DoublePointer pointer, long[] sizes, long[] strides) { + return new DoubleRawIndexer(pointer, sizes, strides); } /** * Creates a double indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static DoubleIndexer create(DoublePointer pointer, long[] sizes, long[] s * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new double indexer backed by the raw memory interface, a buffer, or an array */ - public static DoubleIndexer create(final DoublePointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static DoubleIndexer create(final DoublePointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a double indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new float indexer backed by the raw memory interface, a buffer, or an array + */ + public static DoubleIndexer create(final DoublePointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new DoubleRawIndexer(pointer, sizes, strides) - : new DoubleBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new DoubleRawIndexer(pointer, index) + : new DoubleBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); double[] array = new double[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new DoubleArrayIndexer(array, sizes, strides) { + return new DoubleArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/DoubleRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/DoubleRawIndexer.java index 2dd8ab45e..50b1cff8f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/DoubleRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/DoubleRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.DoublePointer; import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link DoublePointer} using the {@link Raw} instance. @@ -38,19 +40,24 @@ public class DoubleRawIndexer extends DoubleIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code DoubleRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code DoubleRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public DoubleRawIndexer(DoublePointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code DoubleRawIndexer(pointer, sizes, strides(sizes))}. */ - public DoubleRawIndexer(DoublePointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code DoubleRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public DoubleRawIndexer(DoublePointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public DoubleRawIndexer(DoublePointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public DoubleRawIndexer(DoublePointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public DoubleRawIndexer(DoublePointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public DoubleRawIndexer(DoublePointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public DoubleIndexer slice(Index index) { + return new DoubleRawIndexer(pointer, index); + } + public double getRaw(long i) { return RAW.getDouble(base + checkIndex(i, size) * VALUE_BYTES); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/FloatArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/FloatArrayIndexer.java index 9751fcc84..7abbb688b 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/FloatArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/FloatArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code float[]} array. * @@ -31,19 +34,24 @@ public class FloatArrayIndexer extends FloatIndexer { /** The backing array. */ protected float[] array; - /** Calls {@code FloatArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code FloatArrayIndexer(array, defaultIndex({ array.length }))}. */ public FloatArrayIndexer(float[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code FloatArrayIndexer(array, sizes, strides(sizes))}. */ - public FloatArrayIndexer(float[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code FloatArrayIndexer(array, sizes)}. */ + @Deprecated public FloatArrayIndexer(float[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public FloatArrayIndexer(float[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public FloatArrayIndexer(float[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public FloatArrayIndexer(float[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public FloatArrayIndexer(float[] array, long[] sizes, long[] strides) { return array; } + @Override + public FloatIndexer slice(Index index) { + return new FloatArrayIndexer(array, index); + } + @Override public float get(long i) { return array[(int)index(i)]; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/FloatBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/FloatBufferIndexer.java index 50dcb5bc9..9b1550035 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/FloatBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/FloatBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.FloatBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link FloatBuffer}. @@ -34,19 +36,24 @@ public class FloatBufferIndexer extends FloatIndexer { /** The backing buffer. */ protected FloatBuffer buffer; - /** Calls {@code FloatBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code FloatBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public FloatBufferIndexer(FloatBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code FloatBufferIndexer(buffer, sizes, strides(sizes))}. */ - public FloatBufferIndexer(FloatBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code FloatBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public FloatBufferIndexer(FloatBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public FloatBufferIndexer(FloatBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public FloatBufferIndexer(FloatBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public FloatBufferIndexer(FloatBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public FloatBufferIndexer(FloatBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public FloatIndexer slice(Index index) { + return new FloatBufferIndexer(buffer, index); + } + @Override public float get(long i) { return buffer.get((int)index(i)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/FloatIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/FloatIndexer.java index a367ca427..e5a26c14e 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/FloatIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/FloatIndexer.java @@ -24,6 +24,7 @@ import java.nio.FloatBuffer; import org.bytedeco.javacpp.FloatPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code float} primitive type. @@ -34,6 +35,11 @@ public abstract class FloatIndexer extends Indexer { /** The number of bytes used to represent a float. */ public static final int VALUE_BYTES = 4; + protected FloatIndexer(Index index) { + super(index); + } + + @Deprecated protected FloatIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static FloatIndexer create(float[] array) { public static FloatIndexer create(FloatBuffer buffer) { return new FloatBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new FloatRawIndexer(pointer} */ public static FloatIndexer create(FloatPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new FloatRawIndexer(pointer); + } + + /** Returns {@code new FloatArrayIndexer(array, index)} */ + public static FloatIndexer create(float[] array, Index index) { + return new FloatArrayIndexer(array, index); + } + /** Returns {@code new FloatBufferIndexer(buffer, index)} */ + public static FloatIndexer create(FloatBuffer buffer, Index index) { + return new FloatBufferIndexer(buffer, index); + } + /** Returns {@code new FloatRawIndexer(pointer, index)} */ + public static FloatIndexer create(FloatPointer pointer, Index index) { + return new FloatRawIndexer(pointer, index); } /** Returns {@code new FloatArrayIndexer(array, sizes)} */ - public static FloatIndexer create(float[] array, long... sizes) { + @Deprecated public static FloatIndexer create(float[] array, long... sizes) { return new FloatArrayIndexer(array, sizes); } /** Returns {@code new FloatBufferIndexer(buffer, sizes)} */ - public static FloatIndexer create(FloatBuffer buffer, long... sizes) { + @Deprecated public static FloatIndexer create(FloatBuffer buffer, long... sizes) { return new FloatBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static FloatIndexer create(FloatPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new FloatRawIndexer(pointer, sizes)} */ + @Deprecated public static FloatIndexer create(FloatPointer pointer, long... sizes) { + return new FloatRawIndexer(pointer, sizes); } /** Returns {@code new FloatArrayIndexer(array, sizes, strides)} */ - public static FloatIndexer create(float[] array, long[] sizes, long[] strides) { + @Deprecated public static FloatIndexer create(float[] array, long[] sizes, long[] strides) { return new FloatArrayIndexer(array, sizes, strides); } /** Returns {@code new FloatBufferIndexer(buffer, sizes, strides)} */ - public static FloatIndexer create(FloatBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static FloatIndexer create(FloatBuffer buffer, long[] sizes, long[] strides) { return new FloatBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static FloatIndexer create(FloatPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new FloatRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static FloatIndexer create(FloatPointer pointer, long[] sizes, long[] strides) { + return new FloatRawIndexer(pointer, sizes, strides); } /** * Creates a float indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static FloatIndexer create(FloatPointer pointer, long[] sizes, long[] str * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new float indexer backed by the raw memory interface, a buffer, or an array */ - public static FloatIndexer create(final FloatPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static FloatIndexer create(final FloatPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a float indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new float indexer backed by the raw memory interface, a buffer, or an array + */ + public static FloatIndexer create(final FloatPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new FloatRawIndexer(pointer, sizes, strides) - : new FloatBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new FloatRawIndexer(pointer, index) + : new FloatBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); float[] array = new float[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new FloatArrayIndexer(array, sizes, strides) { + return new FloatArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/FloatRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/FloatRawIndexer.java index 31ebbcba8..ffc04af71 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/FloatRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/FloatRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.FloatPointer; import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link FloatPointer} using the {@link Raw} instance. @@ -38,19 +40,24 @@ public class FloatRawIndexer extends FloatIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code FloatRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code FloatRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public FloatRawIndexer(FloatPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code FloatRawIndexer(pointer, sizes, strides(sizes))}. */ - public FloatRawIndexer(FloatPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code FloatRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public FloatRawIndexer(FloatPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public FloatRawIndexer(FloatPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public FloatRawIndexer(FloatPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public FloatRawIndexer(FloatPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -59,6 +66,11 @@ public FloatRawIndexer(FloatPointer pointer, long[] sizes, long[] strides) { @Override public Pointer pointer() { return pointer; } + + @Override + public FloatIndexer slice(Index index) { + return new FloatRawIndexer(pointer, index); + } public float getRaw(long i) { return RAW.getFloat(base + checkIndex(i, size) * VALUE_BYTES); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/HalfArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/HalfArrayIndexer.java index a5204ad10..af3f9528f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/HalfArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/HalfArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code short[]} array, treated as half-precision float. * @@ -31,19 +34,24 @@ public class HalfArrayIndexer extends HalfIndexer { /** The backing array. */ protected short[] array; - /** Calls {@code HalfArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code HalfArrayIndexer(array, defaultIndex({ array.length }))}. */ public HalfArrayIndexer(short[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code HalfArrayIndexer(array, sizes, strides(sizes))}. */ - public HalfArrayIndexer(short[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code HalfArrayIndexer(array, sizes)}. */ + @Deprecated public HalfArrayIndexer(short[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public HalfArrayIndexer(short[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public HalfArrayIndexer(short[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public HalfArrayIndexer(short[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public HalfArrayIndexer(short[] array, long[] sizes, long[] strides) { return array; } + @Override + public HalfIndexer slice(Index index) { + return new HalfArrayIndexer(array, index); + } + @Override public float get(long i) { return toFloat(array[(int)index(i)]); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/HalfBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/HalfBufferIndexer.java index fb2e7bcf4..e5c3e630e 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/HalfBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/HalfBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.ShortBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ShortBuffer}, treated as half-precision float. @@ -34,19 +36,24 @@ public class HalfBufferIndexer extends HalfIndexer { /** The backing buffer. */ protected ShortBuffer buffer; - /** Calls {@code HalfBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code HalfBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public HalfBufferIndexer(ShortBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code HalfBufferIndexer(buffer, sizes, strides(sizes))}. */ - public HalfBufferIndexer(ShortBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code HalfBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public HalfBufferIndexer(ShortBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public HalfBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public HalfBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public HalfBufferIndexer(ShortBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public HalfBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public HalfIndexer slice(Index index) { + return new HalfBufferIndexer(buffer, index); + } + @Override public float get(long i) { return toFloat(buffer.get((int)index(i))); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/HalfIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/HalfIndexer.java index fbb6950e0..109bed3ef 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/HalfIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/HalfIndexer.java @@ -24,6 +24,7 @@ import java.nio.ShortBuffer; import org.bytedeco.javacpp.ShortPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code short} primitive type, treated as half-precision float. @@ -34,6 +35,11 @@ public abstract class HalfIndexer extends Indexer { /** The number of bytes used to represent a short. */ public static final int VALUE_BYTES = 2; + protected HalfIndexer(Index index) { + super(index); + } + + @Deprecated protected HalfIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static HalfIndexer create(short[] array) { public static HalfIndexer create(ShortBuffer buffer) { return new HalfBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new HalfRawIndexer(pointer} */ public static HalfIndexer create(ShortPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new HalfRawIndexer(pointer); + } + + /** Returns {@code new HalfArrayIndexer(array, index)} */ + public static HalfIndexer create(short[] array, Index index) { + return new HalfArrayIndexer(array, index); + } + /** Returns {@code new HalfBufferIndexer(buffer, index)} */ + public static HalfIndexer create(ShortBuffer buffer, Index index) { + return new HalfBufferIndexer(buffer, index); + } + /** Returns {@code new HalfRawIndexer(pointer, index)} */ + public static HalfIndexer create(ShortPointer pointer, Index index) { + return new HalfRawIndexer(pointer, index); } /** Returns {@code new HalfArrayIndexer(array, sizes)} */ - public static HalfIndexer create(short[] array, long... sizes) { + @Deprecated public static HalfIndexer create(short[] array, long... sizes) { return new HalfArrayIndexer(array, sizes); } /** Returns {@code new HalfBufferIndexer(buffer, sizes)} */ - public static HalfIndexer create(ShortBuffer buffer, long... sizes) { + @Deprecated public static HalfIndexer create(ShortBuffer buffer, long... sizes) { return new HalfBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static HalfIndexer create(ShortPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new HalfRawIndexer(pointer, sizes)} */ + @Deprecated public static HalfIndexer create(ShortPointer pointer, long... sizes) { + return new HalfRawIndexer(pointer, sizes); } /** Returns {@code new HalfArrayIndexer(array, sizes, strides)} */ - public static HalfIndexer create(short[] array, long[] sizes, long[] strides) { + @Deprecated public static HalfIndexer create(short[] array, long[] sizes, long[] strides) { return new HalfArrayIndexer(array, sizes, strides); } /** Returns {@code new HalfBufferIndexer(buffer, sizes, strides)} */ - public static HalfIndexer create(ShortBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static HalfIndexer create(ShortBuffer buffer, long[] sizes, long[] strides) { return new HalfBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static HalfIndexer create(ShortPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new HalfRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static HalfIndexer create(ShortPointer pointer, long[] sizes, long[] strides) { + return new HalfRawIndexer(pointer, sizes, strides); } /** * Creates a half float indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static HalfIndexer create(ShortPointer pointer, long[] sizes, long[] stri * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new half indexer backed by the raw memory interface, a buffer, or an array */ - public static HalfIndexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static HalfIndexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a half float indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new half indexer backed by the raw memory interface, a buffer, or an array + */ + public static HalfIndexer create(final ShortPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new HalfRawIndexer(pointer, sizes, strides) - : new HalfBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new HalfRawIndexer(pointer, index) + : new HalfBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); short[] array = new short[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new HalfArrayIndexer(array, sizes, strides) { + return new HalfArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/HalfRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/HalfRawIndexer.java index 5ba0e0dd7..fee01c4fe 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/HalfRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/HalfRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.Pointer; import org.bytedeco.javacpp.ShortPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ShortPointer} using the {@link Raw} instance, treated as half-precision float. @@ -38,19 +40,24 @@ public class HalfRawIndexer extends HalfIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code HalfRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code HalfRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public HalfRawIndexer(ShortPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code HalfRawIndexer(pointer, sizes, strides(sizes))}. */ - public HalfRawIndexer(ShortPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code HalfRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public HalfRawIndexer(ShortPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public HalfRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public HalfRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public HalfRawIndexer(ShortPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public HalfRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public HalfIndexer slice(Index index) { + return new HalfRawIndexer(pointer, index); + } + public float getRaw(long i) { return toFloat(RAW.getShort(base + checkIndex(i, size) * VALUE_BYTES)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/IntArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/IntArrayIndexer.java index 4b3e4c1d6..9f02cfe22 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/IntArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/IntArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for an {@code int[]} array. * @@ -31,19 +34,24 @@ public class IntArrayIndexer extends IntIndexer { /** The backing array. */ protected int[] array; - /** Calls {@code IntArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code IntArrayIndexer(array, defaultIndex({ array.length }))}. */ public IntArrayIndexer(int[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code IntArrayIndexer(array, sizes, strides(sizes))}. */ - public IntArrayIndexer(int[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code IntArrayIndexer(array, sizes)}. */ + @Deprecated public IntArrayIndexer(int[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public IntArrayIndexer(int[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public IntArrayIndexer(int[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public IntArrayIndexer(int[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public IntArrayIndexer(int[] array, long[] sizes, long[] strides) { return array; } + @Override + public IntIndexer slice(Index index) { + return new IntArrayIndexer(array, index); + } + @Override public int get(long i) { return array[(int)index(i)]; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/IntBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/IntBufferIndexer.java index 8328f5c49..47b9eaa6e 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/IntBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/IntBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.IntBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for an {@link IntBuffer}. @@ -34,19 +36,24 @@ public class IntBufferIndexer extends IntIndexer { /** The backing buffer. */ protected IntBuffer buffer; - /** Calls {@code IntBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code IntBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public IntBufferIndexer(IntBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code IntBufferIndexer(buffer, sizes, strides(sizes))}. */ - public IntBufferIndexer(IntBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code IntBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public IntBufferIndexer(IntBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public IntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public IntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public IntBufferIndexer(IntBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public IntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public IntIndexer slice(Index index) { + return new IntBufferIndexer(buffer, index); + } + @Override public int get(long i) { return buffer.get((int)index(i)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/IntIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/IntIndexer.java index b62b1c018..d2e1670bf 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/IntIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/IntIndexer.java @@ -24,6 +24,7 @@ import java.nio.IntBuffer; import org.bytedeco.javacpp.IntPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code int} primitive type. @@ -34,6 +35,11 @@ public abstract class IntIndexer extends Indexer { /** The number of bytes used to represent an int. */ public static final int VALUE_BYTES = 4; + protected IntIndexer(Index index) { + super(index); + } + + @Deprecated protected IntIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static IntIndexer create(int[] array) { public static IntIndexer create(IntBuffer buffer) { return new IntBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new IntRawIndexer(pointer} */ public static IntIndexer create(IntPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new IntRawIndexer(pointer); + } + + /** Returns {@code new IntArrayIndexer(array, index)} */ + public static IntIndexer create(int[] array, Index index) { + return new IntArrayIndexer(array, index); + } + /** Returns {@code new IntBufferIndexer(buffer, index)} */ + public static IntIndexer create(IntBuffer buffer, Index index) { + return new IntBufferIndexer(buffer, index); + } + /** Returns {@code new IntRawIndexer(pointer, index)} */ + public static IntIndexer create(IntPointer pointer, Index index) { + return new IntRawIndexer(pointer, index); } /** Returns {@code new IntArrayIndexer(array, sizes)} */ - public static IntIndexer create(int[] array, long... sizes) { + @Deprecated public static IntIndexer create(int[] array, long... sizes) { return new IntArrayIndexer(array, sizes); } /** Returns {@code new IntBufferIndexer(buffer, sizes)} */ - public static IntIndexer create(IntBuffer buffer, long... sizes) { + @Deprecated public static IntIndexer create(IntBuffer buffer, long... sizes) { return new IntBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static IntIndexer create(IntPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new IntRawIndexer(pointer, sizes)} */ + @Deprecated public static IntIndexer create(IntPointer pointer, long... sizes) { + return new IntRawIndexer(pointer, sizes); } /** Returns {@code new IntArrayIndexer(array, sizes, strides)} */ - public static IntIndexer create(int[] array, long[] sizes, long[] strides) { + @Deprecated public static IntIndexer create(int[] array, long[] sizes, long[] strides) { return new IntArrayIndexer(array, sizes, strides); } /** Returns {@code new IntBufferIndexer(buffer, sizes, strides)} */ - public static IntIndexer create(IntBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static IntIndexer create(IntBuffer buffer, long[] sizes, long[] strides) { return new IntBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static IntIndexer create(IntPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new IntRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static IntIndexer create(IntPointer pointer, long[] sizes, long[] strides) { + return new IntRawIndexer(pointer, sizes, strides); } /** * Creates a int indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static IntIndexer create(IntPointer pointer, long[] sizes, long[] strides * @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) { + @Deprecated public static IntIndexer create(final IntPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * 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 index TODO + * @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, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new IntRawIndexer(pointer, sizes, strides) - : new IntBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new IntRawIndexer(pointer, index) + : new IntBufferIndexer(pointer.asBuffer(), index); } 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) { + return new IntArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/IntRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/IntRawIndexer.java index fe2d58e08..1018adb55 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/IntRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/IntRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.IntPointer; import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for an {@link IntPointer} using the {@link Raw} instance. @@ -38,19 +40,24 @@ public class IntRawIndexer extends IntIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code IntRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code IntRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public IntRawIndexer(IntPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code IntRawIndexer(pointer, sizes, strides(sizes))}. */ - public IntRawIndexer(IntPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code IntRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public IntRawIndexer(IntPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public IntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public IntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public IntRawIndexer(IntPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public IntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public IntIndexer slice(Index index) { + return new IntRawIndexer(pointer, index); + } + public int getRaw(long i) { return RAW.getInt(base + checkIndex(i, size) * VALUE_BYTES); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/LongArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/LongArrayIndexer.java index 899052cca..82dfd0a2f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/LongArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/LongArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code long[]} array. * @@ -31,19 +34,24 @@ public class LongArrayIndexer extends LongIndexer { /** The backing array. */ protected long[] array; - /** Calls {@code LongArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code LongArrayIndexer(array, defaultIndex({ array.length }))}. */ public LongArrayIndexer(long[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code LongArrayIndexer(array, sizes, strides(sizes))}. */ - public LongArrayIndexer(long[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code LongArrayIndexer(array, sizes)}. */ + @Deprecated public LongArrayIndexer(long[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public LongArrayIndexer(long[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public LongArrayIndexer(long[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public LongArrayIndexer(long[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public LongArrayIndexer(long[] array, long[] sizes, long[] strides) { return array; } + @Override + public LongIndexer slice(Index index) { + return new LongArrayIndexer(array, index); + } + @Override public long get(long i) { return array[(int)index(i)]; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/LongBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/LongBufferIndexer.java index eeab25a2d..5d87f432f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/LongBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/LongBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.LongBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link LongBuffer}. @@ -34,19 +36,24 @@ public class LongBufferIndexer extends LongIndexer { /** The backing buffer. */ protected LongBuffer buffer; - /** Calls {@code LongBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code LongBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public LongBufferIndexer(LongBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code LongBufferIndexer(buffer, sizes, strides(sizes))}. */ - public LongBufferIndexer(LongBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code LongBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public LongBufferIndexer(LongBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public LongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public LongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public LongBufferIndexer(LongBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public LongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public LongIndexer slice(Index index) { + return new LongBufferIndexer(buffer, index); + } + @Override public long get(long i) { return buffer.get((int)index(i)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/LongIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/LongIndexer.java index 8ac57e2ea..1d5f8b0a6 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/LongIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/LongIndexer.java @@ -24,6 +24,7 @@ import java.nio.LongBuffer; import org.bytedeco.javacpp.LongPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code long} primitive type. @@ -34,6 +35,11 @@ public abstract class LongIndexer extends Indexer { /** The number of bytes used to represent a long. */ public static final int VALUE_BYTES = 8; + protected LongIndexer(Index index) { + super(index); + } + + @Deprecated protected LongIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static LongIndexer create(long[] array) { public static LongIndexer create(LongBuffer buffer) { return new LongBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new LongRawIndexer(pointer} */ public static LongIndexer create(LongPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new LongRawIndexer(pointer); + } + + /** Returns {@code new LongArrayIndexer(array, index)} */ + public static LongIndexer create(long[] array, Index index) { + return new LongArrayIndexer(array, index); + } + /** Returns {@code new LongBufferIndexer(buffer, index)} */ + public static LongIndexer create(LongBuffer buffer, Index index) { + return new LongBufferIndexer(buffer, index); + } + /** Returns {@code new LongRawIndexer(pointer, index)} */ + public static LongIndexer create(LongPointer pointer, Index index) { + return new LongRawIndexer(pointer, index); } /** Returns {@code new LongArrayIndexer(array, sizes)} */ - public static LongIndexer create(long[] array, long... sizes) { + @Deprecated public static LongIndexer create(long[] array, long... sizes) { return new LongArrayIndexer(array, sizes); } /** Returns {@code new LongBufferIndexer(buffer, sizes)} */ - public static LongIndexer create(LongBuffer buffer, long... sizes) { + @Deprecated public static LongIndexer create(LongBuffer buffer, long... sizes) { return new LongBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static LongIndexer create(LongPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new LongRawIndexer(pointer, sizes)} */ + @Deprecated public static LongIndexer create(LongPointer pointer, long... sizes) { + return new LongRawIndexer(pointer, sizes); } /** Returns {@code new LongArrayIndexer(array, sizes, strides)} */ - public static LongIndexer create(long[] array, long[] sizes, long[] strides) { + @Deprecated public static LongIndexer create(long[] array, long[] sizes, long[] strides) { return new LongArrayIndexer(array, sizes, strides); } /** Returns {@code new LongBufferIndexer(buffer, sizes, strides)} */ - public static LongIndexer create(LongBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static LongIndexer create(LongBuffer buffer, long[] sizes, long[] strides) { return new LongBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static LongIndexer create(LongPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new LongRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static LongIndexer create(LongPointer pointer, long[] sizes, long[] strides) { + return new LongRawIndexer(pointer, sizes, strides); } /** * Creates a long indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static LongIndexer create(LongPointer pointer, long[] sizes, long[] strid * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new long indexer backed by the raw memory interface, a buffer, or an array */ - public static LongIndexer create(final LongPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static LongIndexer create(final LongPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a long indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new long indexer backed by the raw memory interface, a buffer, or an array + */ + public static LongIndexer create(final LongPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new LongRawIndexer(pointer, sizes, strides) - : new LongBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new LongRawIndexer(pointer, index) + : new LongBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); long[] array = new long[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new LongArrayIndexer(array, sizes, strides) { + return new LongArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/LongRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/LongRawIndexer.java index a53daecfa..b970355b4 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/LongRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/LongRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.LongPointer; import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link LongPointer} using the {@link Raw} instance. @@ -38,19 +40,24 @@ public class LongRawIndexer extends LongIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code LongRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code LongRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public LongRawIndexer(LongPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code LongRawIndexer(pointer, sizes, strides(sizes))}. */ - public LongRawIndexer(LongPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code LongRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public LongRawIndexer(LongPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public LongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public LongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public LongRawIndexer(LongPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public LongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public LongIndexer slice(Index index) { + return new LongRawIndexer(pointer, index); + } + public long getRaw(long i) { return RAW.getLong(base + checkIndex(i, size) * VALUE_BYTES); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ShortArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ShortArrayIndexer.java index 32e383a84..cc6d94481 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ShortArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ShortArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code short[]} array. * @@ -31,19 +34,24 @@ public class ShortArrayIndexer extends ShortIndexer { /** The backing array. */ protected short[] array; - /** Calls {@code ShortArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code ShortArrayIndexer(array, defaultIndex({ array.length }))}. */ public ShortArrayIndexer(short[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code ShortArrayIndexer(array, sizes, strides(sizes))}. */ - public ShortArrayIndexer(short[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code ShortArrayIndexer(array, sizes)}. */ + @Deprecated public ShortArrayIndexer(short[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public ShortArrayIndexer(short[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ShortArrayIndexer(short[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public ShortArrayIndexer(short[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public ShortArrayIndexer(short[] array, long[] sizes, long[] strides) { return array; } + @Override + public ShortIndexer slice(Index index) { + return new ShortArrayIndexer(array, index); + } + @Override public short get(long i) { return array[(int)index(i)]; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ShortBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ShortBufferIndexer.java index 739f4752f..22342ab0f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ShortBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ShortBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.ShortBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ShortBuffer}. @@ -34,19 +36,24 @@ public class ShortBufferIndexer extends ShortIndexer { /** The backing buffer. */ protected ShortBuffer buffer; - /** Calls {@code ShortBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code ShortBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public ShortBufferIndexer(ShortBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code ShortBufferIndexer(buffer, sizes, strides(sizes))}. */ - public ShortBufferIndexer(ShortBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code ShortBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public ShortBufferIndexer(ShortBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public ShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public ShortBufferIndexer(ShortBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public ShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public ShortIndexer slice(Index index) { + return new ShortBufferIndexer(buffer, index); + } + @Override public short get(long i) { return buffer.get((int)index(i)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ShortIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ShortIndexer.java index b93300c4f..fce52b94e 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ShortIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ShortIndexer.java @@ -24,6 +24,7 @@ import java.nio.ShortBuffer; import org.bytedeco.javacpp.ShortPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code short} primitive type. @@ -34,6 +35,11 @@ public abstract class ShortIndexer extends Indexer { /** The number of bytes used to represent a short. */ public static final int VALUE_BYTES = 2; + protected ShortIndexer(Index index) { + super(index); + } + + @Deprecated protected ShortIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static ShortIndexer create(short[] array) { public static ShortIndexer create(ShortBuffer buffer) { return new ShortBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new ShortRawIndexer(pointer} */ public static ShortIndexer create(ShortPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new ShortRawIndexer(pointer); + } + + /** Returns {@code new ShortArrayIndexer(array, index)} */ + public static ShortIndexer create(short[] array, Index index) { + return new ShortArrayIndexer(array, index); + } + /** Returns {@code new ShortBufferIndexer(buffer, index)} */ + public static ShortIndexer create(ShortBuffer buffer, Index index) { + return new ShortBufferIndexer(buffer, index); + } + /** Returns {@code new ShortRawIndexer(pointer, index)} */ + public static ShortIndexer create(ShortPointer pointer, Index index) { + return new ShortRawIndexer(pointer, index); } /** Returns {@code new ShortArrayIndexer(array, sizes)} */ - public static ShortIndexer create(short[] array, long... sizes) { + @Deprecated public static ShortIndexer create(short[] array, long... sizes) { return new ShortArrayIndexer(array, sizes); } /** Returns {@code new ShortBufferIndexer(buffer, sizes)} */ - public static ShortIndexer create(ShortBuffer buffer, long... sizes) { + @Deprecated public static ShortIndexer create(ShortBuffer buffer, long... sizes) { return new ShortBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static ShortIndexer create(ShortPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new ShortRawIndexer(pointer, sizes)} */ + @Deprecated public static ShortIndexer create(ShortPointer pointer, long... sizes) { + return new ShortRawIndexer(pointer, sizes); } /** Returns {@code new ShortArrayIndexer(array, sizes, strides)} */ - public static ShortIndexer create(short[] array, long[] sizes, long[] strides) { + @Deprecated public static ShortIndexer create(short[] array, long[] sizes, long[] strides) { return new ShortArrayIndexer(array, sizes, strides); } /** Returns {@code new ShortBufferIndexer(buffer, sizes, strides)} */ - public static ShortIndexer create(ShortBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static ShortIndexer create(ShortBuffer buffer, long[] sizes, long[] strides) { return new ShortBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static ShortIndexer create(ShortPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new ShortRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static ShortIndexer create(ShortPointer pointer, long[] sizes, long[] strides) { + return new ShortRawIndexer(pointer, sizes, strides); } /** * Creates a short indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static ShortIndexer create(ShortPointer pointer, long[] sizes, long[] str * @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 ShortIndexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static ShortIndexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a short indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @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 ShortIndexer create(final ShortPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new ShortRawIndexer(pointer, sizes, strides) - : new ShortBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new ShortRawIndexer(pointer, index) + : new ShortBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); short[] array = new short[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new ShortArrayIndexer(array, sizes, strides) { + return new ShortArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ShortRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ShortRawIndexer.java index 4e8c683e3..481839452 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ShortRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ShortRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.Pointer; import org.bytedeco.javacpp.ShortPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ShortPointer} using the {@link Raw} instance. @@ -38,19 +40,24 @@ public class ShortRawIndexer extends ShortIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code ShortRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code ShortRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public ShortRawIndexer(ShortPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code ShortRawIndexer(pointer, sizes, strides(sizes))}. */ - public ShortRawIndexer(ShortPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code ShortRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public ShortRawIndexer(ShortPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public ShortRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ShortRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public ShortRawIndexer(ShortPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public ShortRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public ShortIndexer slice(Index index) { + return new ShortRawIndexer(pointer, index); + } + public short getRaw(long i) { return RAW.getShort(base + checkIndex(i, size) * VALUE_BYTES); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UByteArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UByteArrayIndexer.java index 8613487b5..a7200a8b6 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UByteArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UByteArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code byte[]} array, treated as unsigned. * @@ -31,19 +34,24 @@ public class UByteArrayIndexer extends UByteIndexer { /** The backing array. */ protected byte[] array; - /** Calls {@code UByteArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code UByteArrayIndexer(array, defaultIndex({ array.length }))}. */ public UByteArrayIndexer(byte[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code UByteArrayIndexer(array, sizes, strides(sizes))}. */ - public UByteArrayIndexer(byte[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code UByteArrayIndexer(array, sizes)}. */ + @Deprecated public UByteArrayIndexer(byte[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public UByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public UByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public UByteArrayIndexer(byte[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public UByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { return array; } + @Override + public UByteIndexer slice(Index index) { + return new UByteArrayIndexer(array, index); + } + @Override public int get(long i) { return array[(int)index(i)] & 0xFF; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UByteBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UByteBufferIndexer.java index 4b6e857fa..09aa23bba 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UByteBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UByteBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.ByteBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ByteBuffer}, treated as unsigned. @@ -34,19 +36,24 @@ public class UByteBufferIndexer extends UByteIndexer { /** The backing buffer. */ protected ByteBuffer buffer; - /** Calls {@code UByteBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code UByteBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public UByteBufferIndexer(ByteBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code UByteBufferIndexer(buffer, sizes, strides(sizes))}. */ + /** Calls {@code UByteBufferIndexer(buffer, defaultIndex(sizes))}. */ public UByteBufferIndexer(ByteBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ public UByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public UByteBufferIndexer(ByteBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public UByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public UByteIndexer slice(Index index) { + return new UByteBufferIndexer(buffer, index); + } + @Override public int get(long i) { return buffer.get((int)index(i)) & 0xFF; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UByteIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UByteIndexer.java index 573e9b8d8..7c3ea06f1 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UByteIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UByteIndexer.java @@ -24,6 +24,7 @@ import java.nio.ByteBuffer; import org.bytedeco.javacpp.BytePointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code byte} primitive type, treated as unsigned. @@ -34,47 +35,65 @@ public abstract class UByteIndexer extends Indexer { /** The number of bytes used to represent a byte. */ public static final int VALUE_BYTES = 1; + protected UByteIndexer(Index index) { + super(index); + } + + @Deprecated protected UByteIndexer(long[] sizes, long[] strides) { super(sizes, strides); } - /** Returns {@code new ByteArrayIndexer(array)} */ + /** Returns {@code new UByteArrayIndexer(array)} */ public static UByteIndexer create(byte[] array) { return new UByteArrayIndexer(array); } - /** Returns {@code new ByteBufferIndexer(buffer)} */ + /** Returns {@code new UByteBufferIndexer(buffer)} */ public static UByteIndexer create(ByteBuffer buffer) { return new UByteBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new UByteRawIndexer(pointer} */ public static UByteIndexer create(BytePointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new UByteRawIndexer(pointer); + } + + /** Returns {@code new UByteArrayIndexer(array, index)} */ + public static UByteIndexer create(byte[] array, Index index) { + return new UByteArrayIndexer(array, index); + } + /** Returns {@code new UByteBufferIndexer(buffer, index)} */ + public static UByteIndexer create(ByteBuffer buffer, Index index) { + return new UByteBufferIndexer(buffer, index); + } + /** Returns {@code new UByteRawIndexer(pointer, index)} */ + public static UByteIndexer create(BytePointer pointer, Index index) { + return new UByteRawIndexer(pointer, index); } /** Returns {@code new UByteArrayIndexer(array, sizes)} */ - public static UByteIndexer create(byte[] array, long... sizes) { + @Deprecated public static UByteIndexer create(byte[] array, long... sizes) { return new UByteArrayIndexer(array, sizes); } /** Returns {@code new UByteBufferIndexer(buffer, sizes)} */ - public static UByteIndexer create(ByteBuffer buffer, long... sizes) { + @Deprecated public static UByteIndexer create(ByteBuffer buffer, long... sizes) { return new UByteBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static UByteIndexer create(BytePointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new UByteRawIndexer(pointer, index)} */ + @Deprecated public static UByteIndexer create(BytePointer pointer, long... sizes) { + return new UByteRawIndexer(pointer, sizes); } /** Returns {@code new ByteArrayIndexer(array, sizes, strides)} */ - public static UByteIndexer create(byte[] array, long[] sizes, long[] strides) { + @Deprecated public static UByteIndexer create(byte[] array, long[] sizes, long[] strides) { return new UByteArrayIndexer(array, sizes, strides); } /** Returns {@code new ByteBufferIndexer(buffer, sizes, strides)} */ - public static UByteIndexer create(ByteBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static UByteIndexer create(ByteBuffer buffer, long[] sizes, long[] strides) { return new UByteBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static UByteIndexer create(BytePointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new UByteRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static UByteIndexer create(BytePointer pointer, long[] sizes, long[] strides) { + return new UByteRawIndexer(pointer, sizes, strides); } /** * Creates a byte indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static UByteIndexer create(BytePointer pointer, long[] sizes, long[] stri * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new byte indexer backed by the raw memory interface, a buffer, or an array */ - public static UByteIndexer create(final BytePointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static UByteIndexer create(final BytePointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a byte indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new byte indexer backed by the raw memory interface, a buffer, or an array + */ + public static UByteIndexer create(final BytePointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new UByteRawIndexer(pointer, sizes, strides) - : new UByteBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new UByteRawIndexer(pointer, index) + : new UByteBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); byte[] array = new byte[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new UByteArrayIndexer(array, sizes, strides) { + return new UByteArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UByteRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UByteRawIndexer.java index daadaf0d3..4f7cfe628 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UByteRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UByteRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.BytePointer; import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link BytePointer} using the {@link Raw} instance, treated as unsigned. @@ -38,19 +40,24 @@ public class UByteRawIndexer extends UByteIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code UByteRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code UByteRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public UByteRawIndexer(BytePointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code UByteRawIndexer(pointer, sizes, strides(sizes))}. */ - public UByteRawIndexer(BytePointer pointer, long... sizes) { + /** Calls {@code UByteRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public UByteRawIndexer(BytePointer pointer, long... sizes) { this(pointer, sizes, strides(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public UByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public UByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public UByteRawIndexer(BytePointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position(); size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public UByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public UByteIndexer slice(Index index) { + return new UByteRawIndexer(pointer, index); + } + public int getRaw(long i) { return RAW.getByte(base + checkIndex(i, size)) & 0xFF; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UIntArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UIntArrayIndexer.java index 8e3a2c906..01f87ce53 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UIntArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UIntArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code int[]} array, treated as unsigned. * @@ -31,19 +34,24 @@ public class UIntArrayIndexer extends UIntIndexer { /** The backing array. */ protected int[] array; - /** Calls {@code UIntArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code UIntArrayIndexer(array, defaultIndex({ array.length }))}. */ public UIntArrayIndexer(int[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code UIntArrayIndexer(array, sizes, strides(sizes))}. */ - public UIntArrayIndexer(int[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code UIntArrayIndexer(array, sizes)}. */ + @Deprecated public UIntArrayIndexer(int[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public UIntArrayIndexer(int[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public UIntArrayIndexer(int[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public UIntArrayIndexer(int[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public UIntArrayIndexer(int[] array, long[] sizes, long[] strides) { return array; } + @Override + public UIntIndexer slice(Index index) { + return new UIntArrayIndexer(array, index); + } + @Override public long get(long i) { return array[(int)index(i)] & 0xFFFFFFFFL; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UIntBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UIntBufferIndexer.java index b6497a2df..8a19122df 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UIntBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UIntBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.IntBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link IntBuffer}, treated as unsigned. @@ -34,19 +36,24 @@ public class UIntBufferIndexer extends UIntIndexer { /** The backing buffer. */ protected IntBuffer buffer; - /** Calls {@code UIntBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code UIntBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public UIntBufferIndexer(IntBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code UIntBufferIndexer(buffer, sizes, strides(sizes))}. */ - public UIntBufferIndexer(IntBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code UIntBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public UIntBufferIndexer(IntBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public UIntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public UIntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public UIntBufferIndexer(IntBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public UIntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public UIntIndexer slice(Index index) { + return new UIntBufferIndexer(buffer, index); + } + @Override public long get(long i) { return buffer.get((int)index(i)) & 0xFFFFFFFFL; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UIntIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UIntIndexer.java index e93b610c7..2b2b4d97b 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UIntIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UIntIndexer.java @@ -24,6 +24,7 @@ import java.nio.IntBuffer; import org.bytedeco.javacpp.IntPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code int} primitive type, treated as unsigned. @@ -34,6 +35,11 @@ public abstract class UIntIndexer extends Indexer { /** The number of bytes used to represent an int. */ public static final int VALUE_BYTES = 4; + protected UIntIndexer(Index index) { + super(index); + } + + @Deprecated protected UIntIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static UIntIndexer create(int[] array) { public static UIntIndexer create(IntBuffer buffer) { return new UIntBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new UIntRawIndexer(pointer} */ public static UIntIndexer create(IntPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new UIntRawIndexer(pointer); + } + + /** Returns {@code new UIntArrayIndexer(array, index)} */ + public static UIntIndexer create(int[] array, Index index) { + return new UIntArrayIndexer(array, index); + } + /** Returns {@code new UIntBufferIndexer(buffer, index)} */ + public static UIntIndexer create(IntBuffer buffer, Index index) { + return new UIntBufferIndexer(buffer, index); + } + /** Returns {@code new UIntRawIndexer(pointer, index)} */ + public static UIntIndexer create(IntPointer pointer, Index index) { + return new UIntRawIndexer(pointer, index); } /** Returns {@code new UIntArrayIndexer(array, sizes)} */ - public static UIntIndexer create(int[] array, long... sizes) { + @Deprecated public static UIntIndexer create(int[] array, long... sizes) { return new UIntArrayIndexer(array, sizes); } /** Returns {@code new UIntBufferIndexer(buffer, sizes)} */ - public static UIntIndexer create(IntBuffer buffer, long... sizes) { + @Deprecated public static UIntIndexer create(IntBuffer buffer, long... sizes) { return new UIntBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static UIntIndexer create(IntPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new UIntRawIndexer(pointer, sizes)} */ + @Deprecated public static UIntIndexer create(IntPointer pointer, long... sizes) { + return new UIntRawIndexer(pointer, sizes); } /** Returns {@code new UIntArrayIndexer(array, sizes, strides)} */ - public static UIntIndexer create(int[] array, long[] sizes, long[] strides) { + @Deprecated public static UIntIndexer create(int[] array, long[] sizes, long[] strides) { return new UIntArrayIndexer(array, sizes, strides); } /** Returns {@code new UIntBufferIndexer(buffer, sizes, strides)} */ - public static UIntIndexer create(IntBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static UIntIndexer create(IntBuffer buffer, long[] sizes, long[] strides) { return new UIntBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static UIntIndexer create(IntPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new UIntRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static UIntIndexer create(IntPointer pointer, long[] sizes, long[] strides) { + return new UIntRawIndexer(pointer, sizes, strides); } /** * Creates a int indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static UIntIndexer create(IntPointer pointer, long[] sizes, long[] stride * @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 UIntIndexer create(final IntPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static UIntIndexer create(final IntPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * 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 index TODO + * @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 UIntIndexer create(final IntPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new UIntRawIndexer(pointer, sizes, strides) - : new UIntBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new UIntRawIndexer(pointer, index) + : new UIntBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); int[] array = new int[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new UIntArrayIndexer(array, sizes, strides) { + return new UIntArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UIntRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UIntRawIndexer.java index cff6325f0..f8c2e1252 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UIntRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UIntRawIndexer.java @@ -22,8 +22,10 @@ package org.bytedeco.javacpp.indexer; -import org.bytedeco.javacpp.Pointer; import org.bytedeco.javacpp.IntPointer; +import org.bytedeco.javacpp.Pointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link IntPointer} using the {@link Raw} instance, treated as unsigned. @@ -38,19 +40,24 @@ public class UIntRawIndexer extends UIntIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code UIntRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code UIntRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public UIntRawIndexer(IntPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code UIntRawIndexer(pointer, sizes, strides(sizes))}. */ - public UIntRawIndexer(IntPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code UIntRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public UIntRawIndexer(IntPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public UIntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public UIntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public UIntRawIndexer(IntPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public UIntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public UIntIndexer slice(Index index) { + return new UIntRawIndexer(pointer, index); + } + public long getRaw(long i) { return RAW.getInt(base + checkIndex(i, size) * VALUE_BYTES) & 0xFFFFFFFFL; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ULongArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ULongArrayIndexer.java index 59e8cc45d..426d4d2ff 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ULongArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ULongArrayIndexer.java @@ -24,6 +24,9 @@ import java.math.BigInteger; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code long[]} array, treated as unsigned. * @@ -33,19 +36,24 @@ public class ULongArrayIndexer extends ULongIndexer { /** The backing array. */ protected long[] array; - /** Calls {@code ULongArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code ULongArrayIndexer(array, defaultIndex({ array.length }))}. */ public ULongArrayIndexer(long[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code ULongArrayIndexer(array, sizes, strides(sizes))}. */ - public ULongArrayIndexer(long[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code ULongArrayIndexer(array, sizes)}. */ + @Deprecated public ULongArrayIndexer(long[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public ULongArrayIndexer(long[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ULongArrayIndexer(long[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public ULongArrayIndexer(long[] array, Index index) { + super(index); this.array = array; } @@ -53,6 +61,11 @@ public ULongArrayIndexer(long[] array, long[] sizes, long[] strides) { return array; } + @Override + public ULongIndexer slice(Index index) { + return new ULongArrayIndexer(array, index); + } + @Override public BigInteger get(long i) { return toBigInteger(array[(int)index(i)]); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ULongBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ULongBufferIndexer.java index 19dc0adb6..1862f353c 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ULongBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ULongBufferIndexer.java @@ -25,6 +25,8 @@ import java.math.BigInteger; import java.nio.Buffer; import java.nio.LongBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link LongBuffer}, treated as unsigned. @@ -35,19 +37,24 @@ public class ULongBufferIndexer extends ULongIndexer { /** The backing buffer. */ protected LongBuffer buffer; - /** Calls {@code ULongBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code ULongBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public ULongBufferIndexer(LongBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code ULongBufferIndexer(buffer, sizes, strides(sizes))}. */ - public ULongBufferIndexer(LongBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code ULongBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public ULongBufferIndexer(LongBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public ULongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ULongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public ULongBufferIndexer(LongBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -55,6 +62,11 @@ public ULongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public ULongIndexer slice(Index index) { + return new ULongBufferIndexer(buffer, index); + } + @Override public BigInteger get(long i) { return toBigInteger(buffer.get((int)index(i))); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ULongIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ULongIndexer.java index 49faa49e3..e9166b188 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ULongIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ULongIndexer.java @@ -26,6 +26,7 @@ import java.math.BigInteger; import java.nio.LongBuffer; import org.bytedeco.javacpp.LongPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code long} primitive type, treated as unsigned. @@ -36,6 +37,11 @@ public abstract class ULongIndexer extends Indexer { /** The number of bytes used to represent a long. */ public static final int VALUE_BYTES = 8; + protected ULongIndexer(Index index) { + super(index); + } + + @Deprecated protected ULongIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -48,34 +54,47 @@ public static ULongIndexer create(long[] array) { public static ULongIndexer create(LongBuffer buffer) { return new ULongBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new ULongRawIndexer(pointer} */ public static ULongIndexer create(LongPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new ULongRawIndexer(pointer); + } + + /** Returns {@code new ULongArrayIndexer(array, index)} */ + public static ULongIndexer create(long[] array, Index index) { + return new ULongArrayIndexer(array, index); + } + /** Returns {@code new ULongBufferIndexer(buffer, index)} */ + public static ULongIndexer create(LongBuffer buffer, Index index) { + return new ULongBufferIndexer(buffer, index); + } + /** Returns {@code new ULongRawIndexer(pointer, index)} */ + public static ULongIndexer create(LongPointer pointer, Index index) { + return new ULongRawIndexer(pointer, index); } /** Returns {@code new ULongArrayIndexer(array, sizes)} */ - public static ULongIndexer create(long[] array, long... sizes) { + @Deprecated public static ULongIndexer create(long[] array, long... sizes) { return new ULongArrayIndexer(array, sizes); } /** Returns {@code new ULongBufferIndexer(buffer, sizes)} */ - public static ULongIndexer create(LongBuffer buffer, long... sizes) { + @Deprecated public static ULongIndexer create(LongBuffer buffer, long... sizes) { return new ULongBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static ULongIndexer create(LongPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new ULongRawIndexer(pointer, sizes)} */ + @Deprecated public static ULongIndexer create(LongPointer pointer, long... sizes) { + return new ULongRawIndexer(pointer, sizes); } /** Returns {@code new ULongArrayIndexer(array, sizes, strides)} */ - public static ULongIndexer create(long[] array, long[] sizes, long[] strides) { + @Deprecated public static ULongIndexer create(long[] array, long[] sizes, long[] strides) { return new ULongArrayIndexer(array, sizes, strides); } /** Returns {@code new ULongBufferIndexer(buffer, sizes, strides)} */ - public static ULongIndexer create(LongBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static ULongIndexer create(LongBuffer buffer, long[] sizes, long[] strides) { return new ULongBufferIndexer(buffer, sizes, strides); } /** Returns {@code create(pointer, sizes, strides, true)} */ - public static ULongIndexer create(LongPointer pointer, long[] sizes, long[] strides) { + @Deprecated public static ULongIndexer create(LongPointer pointer, long[] sizes, long[] strides) { return create(pointer, sizes, strides, true); } /** @@ -85,15 +104,27 @@ public static ULongIndexer create(LongPointer pointer, long[] sizes, long[] stri * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new long indexer backed by the raw memory interface, a buffer, or an array */ - public static ULongIndexer create(final LongPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static ULongIndexer create(final LongPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a long indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details + * @return the new long indexer backed by the raw memory interface, a buffer, or an array + */ + public static ULongIndexer create(final LongPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new ULongRawIndexer(pointer, sizes, strides) - : new ULongBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new ULongRawIndexer(pointer, index) + : new ULongBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); long[] array = new long[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new ULongArrayIndexer(array, sizes, strides) { + return new ULongArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ULongRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ULongRawIndexer.java index 22323c2da..83ad2596b 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ULongRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ULongRawIndexer.java @@ -25,6 +25,8 @@ import java.math.BigInteger; import org.bytedeco.javacpp.Pointer; import org.bytedeco.javacpp.LongPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link LongPointer} using the {@link Raw} instance, treated as unsigned. @@ -39,19 +41,24 @@ public class ULongRawIndexer extends ULongIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code ULongRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code ULongRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public ULongRawIndexer(LongPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code ULongRawIndexer(pointer, sizes, strides(sizes))}. */ - public ULongRawIndexer(LongPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code ULongRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public ULongRawIndexer(LongPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public ULongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public ULongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public ULongRawIndexer(LongPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -61,6 +68,11 @@ public ULongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public ULongIndexer slice(Index index) { + return new ULongRawIndexer(pointer, index); + } + public BigInteger getRaw(long i) { return toBigInteger(RAW.getLong(base + checkIndex(i, size) * VALUE_BYTES)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UShortArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UShortArrayIndexer.java index e6743c3e8..8e8769b7f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UShortArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UShortArrayIndexer.java @@ -22,6 +22,9 @@ package org.bytedeco.javacpp.indexer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; + /** * An indexer for a {@code short[]} array, treated as unsigned. * @@ -31,19 +34,24 @@ public class UShortArrayIndexer extends UShortIndexer { /** The backing array. */ protected short[] array; - /** Calls {@code UShortArrayIndexer(array, { array.length }, { 1 })}. */ + /** Calls {@code UShortArrayIndexer(array, defaultIndex({ array.length }))}. */ public UShortArrayIndexer(short[] array) { - this(array, new long[] { array.length }, ONE_STRIDE); + this(array, defaultIndex(array.length)); } - /** Calls {@code UShortArrayIndexer(array, sizes, strides(sizes))}. */ - public UShortArrayIndexer(short[] array, long... sizes) { - this(array, sizes, strides(sizes)); + /** Calls {@code UShortArrayIndexer(array, sizes)}. */ + @Deprecated public UShortArrayIndexer(short[] array, long... sizes) { + this(array, defaultIndex(sizes)); } /** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */ - public UShortArrayIndexer(short[] array, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public UShortArrayIndexer(short[] array, long[] sizes, long[] strides) { + this(array, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #array} and {@link #index}. */ + public UShortArrayIndexer(short[] array, Index index) { + super(index); this.array = array; } @@ -51,6 +59,11 @@ public UShortArrayIndexer(short[] array, long[] sizes, long[] strides) { return array; } + @Override + public UShortIndexer slice(Index index) { + return new UShortArrayIndexer(array, index); + } + @Override public int get(long i) { return array[(int)index(i)] & 0xFFFF; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UShortBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UShortBufferIndexer.java index 100e6dabb..8f6bfad42 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UShortBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UShortBufferIndexer.java @@ -24,6 +24,8 @@ import java.nio.Buffer; import java.nio.ShortBuffer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ShortBuffer}, treated as unsigned. @@ -34,19 +36,24 @@ public class UShortBufferIndexer extends UShortIndexer { /** The backing buffer. */ protected ShortBuffer buffer; - /** Calls {@code UShortBufferIndexer(buffer, { buffer.limit() }, { 1 })}. */ + /** Calls {@code UShortBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */ public UShortBufferIndexer(ShortBuffer buffer) { - this(buffer, new long[] { buffer.limit() }, ONE_STRIDE); + this(buffer, defaultIndex(buffer.limit())); } - /** Calls {@code UShortBufferIndexer(buffer, sizes, strides(sizes))}. */ - public UShortBufferIndexer(ShortBuffer buffer, long... sizes) { - this(buffer, sizes, strides(sizes)); + /** Calls {@code UShortBufferIndexer(buffer, defaultIndex(sizes))}. */ + @Deprecated public UShortBufferIndexer(ShortBuffer buffer, long... sizes) { + this(buffer, defaultIndex(sizes)); } /** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */ - public UShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public UShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { + this(buffer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #buffer} and {@link #index}. */ + public UShortBufferIndexer(ShortBuffer buffer, Index index) { + super(index); this.buffer = buffer; } @@ -54,6 +61,11 @@ public UShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { return buffer; } + @Override + public UShortIndexer slice(Index index) { + return new UShortBufferIndexer(buffer, index); + } + @Override public int get(long i) { return buffer.get((int)index(i)) & 0xFFFF; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UShortIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UShortIndexer.java index c7fcbee62..96e155e41 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UShortIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UShortIndexer.java @@ -24,6 +24,7 @@ import java.nio.ShortBuffer; import org.bytedeco.javacpp.ShortPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; /** * Abstract indexer for the {@code short} primitive type, treated as unsigned. @@ -34,6 +35,11 @@ public abstract class UShortIndexer extends Indexer { /** The number of bytes used to represent a short. */ public static final int VALUE_BYTES = 2; + protected UShortIndexer(Index index) { + super(index); + } + + @Deprecated protected UShortIndexer(long[] sizes, long[] strides) { super(sizes, strides); } @@ -46,35 +52,48 @@ public static UShortIndexer create(short[] array) { public static UShortIndexer create(ShortBuffer buffer) { return new UShortBufferIndexer(buffer); } - /** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ + /** Returns {@code new UShortRawIndexer(pointer} */ public static UShortIndexer create(ShortPointer pointer) { - return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + return new UShortRawIndexer(pointer); + } + + /** Returns {@code new UShortArrayIndexer(array, index)} */ + public static UShortIndexer create(short[] array, Index index) { + return new UShortArrayIndexer(array, index); + } + /** Returns {@code new UShortBufferIndexer(buffer, index)} */ + public static UShortIndexer create(ShortBuffer buffer, Index index) { + return new UShortBufferIndexer(buffer, index); + } + /** Returns {@code new UShortRawIndexer(pointer, index)} */ + public static UShortIndexer create(ShortPointer pointer, Index index) { + return new UShortRawIndexer(pointer, index); } /** Returns {@code new UShortArrayIndexer(array, sizes)} */ - public static UShortIndexer create(short[] array, long... sizes) { + @Deprecated public static UShortIndexer create(short[] array, long... sizes) { return new UShortArrayIndexer(array, sizes); } /** Returns {@code new UShortBufferIndexer(buffer, sizes)} */ - public static UShortIndexer create(ShortBuffer buffer, long... sizes) { + @Deprecated public static UShortIndexer create(ShortBuffer buffer, long... sizes) { return new UShortBufferIndexer(buffer, sizes); } - /** Returns {@code create(pointer, sizes, strides(sizes))} */ - public static UShortIndexer create(ShortPointer pointer, long... sizes) { - return create(pointer, sizes, strides(sizes)); + /** Returns {@code new UShortRawIndexer(pointer, sizes)} */ + @Deprecated public static UShortIndexer create(ShortPointer pointer, long... sizes) { + return new UShortRawIndexer(pointer, sizes); } /** Returns {@code new UShortArrayIndexer(array, sizes, strides)} */ - public static UShortIndexer create(short[] array, long[] sizes, long[] strides) { + @Deprecated public static UShortIndexer create(short[] array, long[] sizes, long[] strides) { return new UShortArrayIndexer(array, sizes, strides); } /** Returns {@code new UShortBufferIndexer(buffer, sizes, strides)} */ - public static UShortIndexer create(ShortBuffer buffer, long[] sizes, long[] strides) { + @Deprecated public static UShortIndexer create(ShortBuffer buffer, long[] sizes, long[] strides) { return new UShortBufferIndexer(buffer, sizes, strides); } - /** Returns {@code create(pointer, sizes, strides, true)} */ - public static UShortIndexer create(ShortPointer pointer, long[] sizes, long[] strides) { - return create(pointer, sizes, strides, true); + /** Returns {@code new UShortRawIndexer(pointer, sizes, strides)} */ + @Deprecated public static UShortIndexer create(ShortPointer pointer, long[] sizes, long[] strides) { + return new UShortRawIndexer(pointer, sizes, strides); } /** * Creates a short indexer to access efficiently the data of a pointer. @@ -83,15 +102,27 @@ public static UShortIndexer create(ShortPointer pointer, long[] sizes, long[] st * @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 UShortIndexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) { + @Deprecated public static UShortIndexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) { + return create(pointer, customStrides(sizes, strides), direct); + } + + /** + * Creates a short indexer to access efficiently the data of a pointer. + * + * @param pointer data to access via a buffer or to copy to an array + * @param index TODO + * @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 UShortIndexer create(final ShortPointer pointer, Index index, boolean direct) { if (direct) { - return Raw.getInstance() != null ? new UShortRawIndexer(pointer, sizes, strides) - : new UShortBufferIndexer(pointer.asBuffer(), sizes, strides); + return Raw.getInstance() != null ? new UShortRawIndexer(pointer, index) + : new UShortBufferIndexer(pointer.asBuffer(), index); } else { final long position = pointer.position(); short[] array = new short[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); - return new UShortArrayIndexer(array, sizes, strides) { + return new UShortArrayIndexer(array, index) { @Override public void release() { pointer.position(position).put(array); super.release(); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UShortRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UShortRawIndexer.java index 151353fdc..8a9d3ef21 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UShortRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UShortRawIndexer.java @@ -24,6 +24,8 @@ import org.bytedeco.javacpp.Pointer; import org.bytedeco.javacpp.ShortPointer; +import static org.bytedeco.javacpp.indexer.CustomStridesIndex.customStrides; +import static org.bytedeco.javacpp.indexer.DefaultIndex.defaultIndex; /** * An indexer for a {@link ShortPointer} using the {@link Raw} instance, treated as unsigned. @@ -38,19 +40,24 @@ public class UShortRawIndexer extends UShortIndexer { /** Base address and number of elements accessible. */ final long base, size; - /** Calls {@code UShortRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ + /** Calls {@code UShortRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */ public UShortRawIndexer(ShortPointer pointer) { - this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); + this(pointer, defaultIndex( pointer.limit() - pointer.position() )); } - /** Calls {@code UShortRawIndexer(pointer, sizes, strides(sizes))}. */ - public UShortRawIndexer(ShortPointer pointer, long... sizes) { - this(pointer, sizes, strides(sizes)); + /** Calls {@code UShortRawIndexer(pointer, defaultIndex(sizes))}. */ + @Deprecated public UShortRawIndexer(ShortPointer pointer, long... sizes) { + this(pointer, defaultIndex(sizes)); } /** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ - public UShortRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { - super(sizes, strides); + @Deprecated public UShortRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { + this(pointer, customStrides(sizes, strides)); + } + + /** Constructor to set the {@link #pointer} and {@link #index}. */ + public UShortRawIndexer(ShortPointer pointer, Index index) { + super(index); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); @@ -60,6 +67,11 @@ public UShortRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { return pointer; } + @Override + public UShortIndexer slice(Index index) { + return new UShortRawIndexer(pointer, index); + } + public int getRaw(long i) { return RAW.getShort(base + checkIndex(i, size) * VALUE_BYTES) & 0xFFFF; }