From 01b234a98c0b67f482e43200c856327ea5ea639b Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Sat, 18 Apr 2020 23:20:29 +0900 Subject: [PATCH] * Add `Indexer.Index` nested class to allow overriding how the index is calculated (issue #391) --- CHANGELOG.md | 2 + .../javacpp/indexer/Bfloat16ArrayIndexer.java | 20 +- .../indexer/Bfloat16BufferIndexer.java | 20 +- .../javacpp/indexer/Bfloat16Indexer.java | 40 ++-- .../javacpp/indexer/Bfloat16RawIndexer.java | 34 +-- .../javacpp/indexer/BooleanArrayIndexer.java | 20 +- .../javacpp/indexer/BooleanBufferIndexer.java | 20 +- .../javacpp/indexer/BooleanIndexer.java | 28 +-- .../javacpp/indexer/BooleanRawIndexer.java | 34 +-- .../javacpp/indexer/ByteArrayIndexer.java | 28 ++- .../javacpp/indexer/ByteBufferIndexer.java | 28 ++- .../bytedeco/javacpp/indexer/ByteIndexer.java | 37 ++-- .../javacpp/indexer/ByteRawIndexer.java | 42 ++-- .../javacpp/indexer/CharArrayIndexer.java | 20 +- .../javacpp/indexer/CharBufferIndexer.java | 20 +- .../bytedeco/javacpp/indexer/CharIndexer.java | 28 +-- .../javacpp/indexer/CharRawIndexer.java | 34 +-- .../javacpp/indexer/DoubleArrayIndexer.java | 20 +- .../javacpp/indexer/DoubleBufferIndexer.java | 20 +- .../javacpp/indexer/DoubleIndexer.java | 28 +-- .../javacpp/indexer/DoubleRawIndexer.java | 34 +-- .../javacpp/indexer/FloatArrayIndexer.java | 20 +- .../javacpp/indexer/FloatBufferIndexer.java | 20 +- .../javacpp/indexer/FloatIndexer.java | 28 +-- .../javacpp/indexer/FloatRawIndexer.java | 34 +-- .../javacpp/indexer/HalfArrayIndexer.java | 20 +- .../javacpp/indexer/HalfBufferIndexer.java | 20 +- .../bytedeco/javacpp/indexer/HalfIndexer.java | 40 ++-- .../javacpp/indexer/HalfRawIndexer.java | 34 +-- .../org/bytedeco/javacpp/indexer/Indexer.java | 58 ++++- .../javacpp/indexer/IntArrayIndexer.java | 20 +- .../javacpp/indexer/IntBufferIndexer.java | 20 +- .../bytedeco/javacpp/indexer/IntIndexer.java | 28 +-- .../javacpp/indexer/IntRawIndexer.java | 34 +-- .../javacpp/indexer/LongArrayIndexer.java | 20 +- .../javacpp/indexer/LongBufferIndexer.java | 20 +- .../bytedeco/javacpp/indexer/LongIndexer.java | 28 +-- .../javacpp/indexer/LongRawIndexer.java | 34 +-- .../javacpp/indexer/ShortArrayIndexer.java | 20 +- .../javacpp/indexer/ShortBufferIndexer.java | 20 +- .../javacpp/indexer/ShortIndexer.java | 28 +-- .../javacpp/indexer/ShortRawIndexer.java | 34 +-- .../javacpp/indexer/UByteArrayIndexer.java | 20 +- .../javacpp/indexer/UByteBufferIndexer.java | 20 +- .../javacpp/indexer/UByteIndexer.java | 28 +-- .../javacpp/indexer/UByteRawIndexer.java | 33 +-- .../javacpp/indexer/UIntArrayIndexer.java | 20 +- .../javacpp/indexer/UIntBufferIndexer.java | 20 +- .../bytedeco/javacpp/indexer/UIntIndexer.java | 28 +-- .../javacpp/indexer/UIntRawIndexer.java | 34 +-- .../javacpp/indexer/ULongArrayIndexer.java | 20 +- .../javacpp/indexer/ULongBufferIndexer.java | 20 +- .../javacpp/indexer/ULongIndexer.java | 28 +-- .../javacpp/indexer/ULongRawIndexer.java | 34 +-- .../javacpp/indexer/UShortArrayIndexer.java | 20 +- .../javacpp/indexer/UShortBufferIndexer.java | 20 +- .../javacpp/indexer/UShortIndexer.java | 28 +-- .../javacpp/indexer/UShortRawIndexer.java | 34 +-- .../org/bytedeco/javacpp/IndexerTest.java | 202 +++++++++--------- 59 files changed, 949 insertions(+), 797 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14d40f34a..b0b5a025b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ + * Add `Indexer.Index` nested class to allow overriding how the index is calculated ([issue #391](https://github.com/bytedeco/javacpp/issues/391)) + ### April 14, 2020 version 1.5.3 * Deprecate but also fix `Indexer.rows()`, `cols()`, `width()`, `height()`, and `channels()` ([pull #390](https://github.com/bytedeco/javacpp/pull/390)) * Fix `Parser` producing invalid wrappers for basic containers like `std::set >` diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16ArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16ArrayIndexer.java index 411d44836..ee99164d7 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16ArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16ArrayIndexer.java @@ -52,25 +52,25 @@ public Bfloat16ArrayIndexer(short[] array, long[] sizes, long[] strides) { } @Override public float get(long i) { - return toFloat(array[(int)i]); + return toFloat(array[(int)index(i)]); } @Override public Bfloat16Indexer get(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = toFloat(array[(int)i * (int)strides[0] + n]); + h[offset + n] = toFloat(array[(int)index(i) + n]); } return this; } @Override public float get(long i, long j) { - return toFloat(array[(int)i * (int)strides[0] + (int)j]); + return toFloat(array[(int)index(i, j)]); } @Override public Bfloat16Indexer get(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = toFloat(array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]); + h[offset + n] = toFloat(array[(int)index(i, j) + n]); } return this; } @Override public float get(long i, long j, long k) { - return toFloat(array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]); + return toFloat(array[(int)index(i, j, k)]); } @Override public float get(long... indices) { return toFloat(array[(int)index(indices)]); @@ -83,27 +83,27 @@ public Bfloat16ArrayIndexer(short[] array, long[] sizes, long[] strides) { } @Override public Bfloat16Indexer put(long i, float h) { - array[(int)i] = (short)fromFloat(h); + array[(int)index(i)] = (short)fromFloat(h); return this; } @Override public Bfloat16Indexer put(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = (short)fromFloat(h[offset + n]); + array[(int)index(i) + n] = (short)fromFloat(h[offset + n]); } return this; } @Override public Bfloat16Indexer put(long i, long j, float h) { - array[(int)i * (int)strides[0] + (int)j] = (short)fromFloat(h); + array[(int)index(i, j)] = (short)fromFloat(h); return this; } @Override public Bfloat16Indexer put(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = (short)fromFloat(h[offset + n]); + array[(int)index(i, j) + n] = (short)fromFloat(h[offset + n]); } return this; } @Override public Bfloat16Indexer put(long i, long j, long k, float h) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = (short)fromFloat(h); + array[(int)index(i, j, k)] = (short)fromFloat(h); return this; } @Override public Bfloat16Indexer put(long[] indices, float h) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16BufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16BufferIndexer.java index 70f9f3b83..5ad9d8966 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16BufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16BufferIndexer.java @@ -55,25 +55,25 @@ public Bfloat16BufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { } @Override public float get(long i) { - return toFloat(buffer.get((int)i)); + return toFloat(buffer.get((int)index(i))); } @Override public Bfloat16Indexer get(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = toFloat(buffer.get((int)i * (int)strides[0] + n)); + h[offset + n] = toFloat(buffer.get((int)index(i) + n)); } return this; } @Override public float get(long i, long j) { - return toFloat(buffer.get((int)i * (int)strides[0] + (int)j)); + return toFloat(buffer.get((int)index(i, j))); } @Override public Bfloat16Indexer get(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = toFloat(buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n)); + h[offset + n] = toFloat(buffer.get((int)index(i, j) + n)); } return this; } @Override public float get(long i, long j, long k) { - return toFloat(buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k)); + return toFloat(buffer.get((int)index(i, j, k))); } @Override public float get(long... indices) { return toFloat(buffer.get((int)index(indices))); @@ -86,27 +86,27 @@ public Bfloat16BufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { } @Override public Bfloat16Indexer put(long i, float h) { - buffer.put((int)i, (short)fromFloat(h)); + buffer.put((int)index(i), (short)fromFloat(h)); return this; } @Override public Bfloat16Indexer put(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, (short)fromFloat(h[offset + n])); + buffer.put((int)index(i) + n, (short)fromFloat(h[offset + n])); } return this; } @Override public Bfloat16Indexer put(long i, long j, float h) { - buffer.put((int)i * (int)strides[0] + (int)j, (short)fromFloat(h)); + buffer.put((int)index(i, j), (short)fromFloat(h)); return this; } @Override public Bfloat16Indexer put(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, (short)fromFloat(h[offset + n])); + buffer.put((int)index(i, j) + n, (short)fromFloat(h[offset + n])); } return this; } @Override public Bfloat16Indexer put(long i, long j, long k, float h) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, (short)fromFloat(h)); + buffer.put((int)index(i, j, k), (short)fromFloat(h)); return this; } @Override public Bfloat16Indexer put(long[] indices, float h) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16Indexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16Indexer.java index 2ea22998f..8f659e64b 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16Indexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16Indexer.java @@ -112,48 +112,48 @@ public static int fromFloat(float h) { return Float.floatToIntBits(h) >>> 16; } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract float get(long i); - /** Returns {@code this} where {@code s = array/buffer[i]} */ + /** Returns {@code this} where {@code h = array/buffer[index(i)]} */ public Bfloat16Indexer get(long i, float[] h) { return get(i, h, 0, h.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code h[offset:offset + length] = array/buffer[index(i)]} */ public abstract Bfloat16Indexer get(long i, float[] h, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract float get(long i, long j); - /** Returns {@code this} where {@code s = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code h = array/buffer[index(i, j)]} */ public Bfloat16Indexer get(long i, long j, float[] h) { return get(i, j, h, 0, h.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code h[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract Bfloat16Indexer get(long i, long j, float[] h, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract float get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract float get(long... indices); - /** Returns {@code this} where {@code s = array/buffer[index(indices)]} */ + /** Returns {@code this} where {@code h = array/buffer[index(indices)]} */ public Bfloat16Indexer get(long[] indices, float[] h) { return get(indices, h, 0, h.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[index(indices)]} */ + /** Returns {@code this} where {@code h[offset:offset + length] = array/buffer[index(indices)]} */ public abstract Bfloat16Indexer get(long[] indices, float[] h, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = h} */ public abstract Bfloat16Indexer put(long i, float h); - /** Returns {@code this} where {@code array/buffer[i] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = h} */ public Bfloat16Indexer put(long i, float... h) { return put(i, h, 0, h.length); } - /** Returns {@code this} where {@code array/buffer[i] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = h[offset:offset + length]} */ public abstract Bfloat16Indexer put(long i, float[] h, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = h} */ public abstract Bfloat16Indexer put(long i, long j, float h); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = h} */ public Bfloat16Indexer put(long i, long j, float... h) { return put(i, j, h, 0, h.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = h[offset:offset + length]} */ public abstract Bfloat16Indexer put(long i, long j, float[] h, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = h} */ public abstract Bfloat16Indexer put(long i, long j, long k, float h); - /** Returns {@code this} where {@code array/buffer[index(indices)] = s} */ + /** Returns {@code this} where {@code array/buffer[index(indices)] = h} */ public abstract Bfloat16Indexer put(long[] indices, float h); - /** Returns {@code this} where {@code array/buffer[index(indices)] = s} */ + /** Returns {@code this} where {@code array/buffer[index(indices)] = h} */ public Bfloat16Indexer put(long[] indices, float... h) { return put(indices, h, 0, h.length); } - /** Returns {@code this} where {@code array/buffer[index(indices)] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(indices)] = h[offset:offset + length]} */ public abstract Bfloat16Indexer put(long[] indices, float[] h, int offset, int length); @Override public double getDouble(long... indices) { return get(indices); } - @Override public Bfloat16Indexer putDouble(long[] indices, double s) { return put(indices, (float)s); } + @Override public Bfloat16Indexer putDouble(long[] indices, double h) { return put(indices, (float)h); } } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16RawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16RawIndexer.java index 39bb85641..8494ac9f7 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16RawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Bfloat16RawIndexer.java @@ -60,68 +60,74 @@ public Bfloat16RawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public float get(long i) { + public float getRaw(long i) { return toFloat(RAW.getShort(base + checkIndex(i, size) * VALUE_BYTES)); } + @Override public float get(long i) { + return getRaw(index(i)); + } @Override public Bfloat16Indexer get(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = get(i * strides[0] + n); + h[offset + n] = getRaw(index(i) + n); } return this; } @Override public float get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public Bfloat16Indexer get(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = get(i * strides[0] + j * strides[1] + n); + h[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public float get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public float get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public Bfloat16Indexer get(long[] indices, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = get(index(indices) + n); + h[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public Bfloat16Indexer put(long i, float h) { + public Bfloat16Indexer putRaw(long i, float h) { RAW.putShort(base + checkIndex(i, size) * VALUE_BYTES, (short)fromFloat(h)); return this; } + @Override public Bfloat16Indexer put(long i, float h) { + return putRaw(index(i), h); + } @Override public Bfloat16Indexer put(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, h[offset + n]); + putRaw(index(i) + n, h[offset + n]); } return this; } @Override public Bfloat16Indexer put(long i, long j, float h) { - put(i * strides[0] + j, h); + putRaw(index(i, j), h); return this; } @Override public Bfloat16Indexer put(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, h[offset + n]); + putRaw(index(i, j) + n, h[offset + n]); } return this; } @Override public Bfloat16Indexer put(long i, long j, long k, float h) { - put(i * strides[0] + j * strides[1] + k, h); + putRaw(index(i, j, k), h); return this; } @Override public Bfloat16Indexer put(long[] indices, float h) { - put(index(indices), h); + putRaw(index(indices), h); return this; } @Override public Bfloat16Indexer put(long[] indices, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, h[offset + n]); + putRaw(index(indices) + n, h[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/BooleanArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/BooleanArrayIndexer.java index 138edf5a2..696211ac8 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/BooleanArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/BooleanArrayIndexer.java @@ -52,25 +52,25 @@ public BooleanArrayIndexer(boolean[] array, long[] sizes, long[] strides) { } @Override public boolean get(long i) { - return array[(int)i]; + return array[(int)index(i)]; } @Override public BooleanIndexer get(long i, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = array[(int)i * (int)strides[0] + n]; + b[offset + n] = array[(int)index(i) + n]; } return this; } @Override public boolean get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j]; + return array[(int)index(i, j)]; } @Override public BooleanIndexer get(long i, long j, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]; + b[offset + n] = array[(int)index(i, j) + n]; } return this; } @Override public boolean get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]; + return array[(int)index(i, j, k)]; } @Override public boolean get(long... indices) { return array[(int)index(indices)]; @@ -83,27 +83,27 @@ public BooleanArrayIndexer(boolean[] array, long[] sizes, long[] strides) { } @Override public BooleanIndexer put(long i, boolean b) { - array[(int)i] = b; + array[(int)index(i)] = b; return this; } @Override public BooleanIndexer put(long i, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = b[offset + n]; + array[(int)index(i) + n] = b[offset + n]; } return this; } @Override public BooleanIndexer put(long i, long j, boolean b) { - array[(int)i * (int)strides[0] + (int)j] = b; + array[(int)index(i, j)] = b; return this; } @Override public BooleanIndexer put(long i, long j, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = b[offset + n]; + array[(int)index(i, j) + n] = b[offset + n]; } return this; } @Override public BooleanIndexer put(long i, long j, long k, boolean b) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = b; + array[(int)index(i, j, k)] = b; return this; } @Override public BooleanIndexer put(long[] indices, boolean b) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/BooleanBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/BooleanBufferIndexer.java index c4dd53531..603a73407 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/BooleanBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/BooleanBufferIndexer.java @@ -55,25 +55,25 @@ public BooleanBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { } @Override public boolean get(long i) { - return buffer.get((int)i) != 0; + return buffer.get((int)index(i)) != 0; } @Override public BooleanIndexer get(long i, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = buffer.get((int)i * (int)strides[0] + n) != 0; + b[offset + n] = buffer.get((int)index(i) + n) != 0; } return this; } @Override public boolean get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j) != 0; + return buffer.get((int)index(i, j)) != 0; } @Override public BooleanIndexer get(long i, long j, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n) != 0; + b[offset + n] = buffer.get((int)index(i, j) + n) != 0; } return this; } @Override public boolean get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k) != 0; + return buffer.get((int)index(i, j, k)) != 0; } @Override public boolean get(long... indices) { return buffer.get((int)index(indices)) != 0; @@ -86,27 +86,27 @@ public BooleanBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { } @Override public BooleanIndexer put(long i, boolean b) { - buffer.put((int)i, b ? (byte)1 : (byte)0); + buffer.put((int)index(i), b ? (byte)1 : (byte)0); return this; } @Override public BooleanIndexer put(long i, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, b[offset + n] ? (byte)1 : (byte)0); + buffer.put((int)index(i) + n, b[offset + n] ? (byte)1 : (byte)0); } return this; } @Override public BooleanIndexer put(long i, long j, boolean b) { - buffer.put((int)i * (int)strides[0] + (int)j, b ? (byte)1 : (byte)0); + buffer.put((int)index(i, j), b ? (byte)1 : (byte)0); return this; } @Override public BooleanIndexer put(long i, long j, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, b[offset + n] ? (byte)1 : (byte)0); + buffer.put((int)index(i, j) + n, b[offset + n] ? (byte)1 : (byte)0); } return this; } @Override public BooleanIndexer put(long i, long j, long k, boolean b) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, b ? (byte)1 : (byte)0); + buffer.put((int)index(i, j, k), b ? (byte)1 : (byte)0); return this; } @Override public BooleanIndexer put(long[] indices, boolean b) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/BooleanIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/BooleanIndexer.java index 2014cf75e..f6c60fafb 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/BooleanIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/BooleanIndexer.java @@ -100,19 +100,19 @@ public static BooleanIndexer create(final BooleanPointer pointer, long[] sizes, } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract boolean get(long i); - /** Returns {@code this} where {@code b = array/buffer[i]} */ + /** Returns {@code this} where {@code b = array/buffer[index(i)]} */ public BooleanIndexer get(long i, boolean[] b) { return get(i, b, 0, b.length); } - /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(i)]} */ public abstract BooleanIndexer get(long i, boolean[] b, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract boolean get(long i, long j); - /** Returns {@code this} where {@code b = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code b = array/buffer[index(i, j)]} */ public BooleanIndexer get(long i, long j, boolean[] b) { return get(i, j, b, 0, b.length); } - /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract BooleanIndexer get(long i, long j, boolean[] b, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract boolean get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract boolean get(long... indices); @@ -121,19 +121,19 @@ public static BooleanIndexer create(final BooleanPointer pointer, long[] sizes, /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(indices)]} */ public abstract BooleanIndexer get(long[] indices, boolean[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b} */ public abstract BooleanIndexer put(long i, boolean b); - /** Returns {@code this} where {@code array/buffer[i] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b} */ public BooleanIndexer put(long i, boolean... b) { return put(i, b, 0, b.length); } - /** Returns {@code this} where {@code array/buffer[i] = b[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b[offset:offset + length]} */ public abstract BooleanIndexer put(long i, boolean[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b} */ public abstract BooleanIndexer put(long i, long j, boolean b); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b} */ public BooleanIndexer put(long i, long j, boolean... b) { return put(i, j, b, 0, b.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b[offset:offset + length]} */ public abstract BooleanIndexer put(long i, long j, boolean[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = b} */ public abstract BooleanIndexer put(long i, long j, long k, boolean b); /** Returns {@code this} where {@code array/buffer[index(indices)] = b} */ public abstract BooleanIndexer put(long[] indices, boolean b); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/BooleanRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/BooleanRawIndexer.java index 54414dfc6..9df03702a 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/BooleanRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/BooleanRawIndexer.java @@ -60,68 +60,74 @@ public BooleanRawIndexer(BooleanPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public boolean get(long i) { + public boolean getRaw(long i) { return RAW.getBoolean(base + checkIndex(i, size) * VALUE_BYTES); } + @Override public boolean get(long i) { + return getRaw(index(i)); + } @Override public BooleanIndexer get(long i, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(i * strides[0] + n); + b[offset + n] = getRaw(index(i) + n); } return this; } @Override public boolean get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public BooleanIndexer get(long i, long j, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(i * strides[0] + j * strides[1] + n); + b[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public boolean get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public boolean get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public BooleanIndexer get(long[] indices, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(index(indices) + n); + b[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public BooleanIndexer put(long i, boolean b) { + public BooleanIndexer putRaw(long i, boolean b) { RAW.putBoolean(base + checkIndex(i, size) * VALUE_BYTES, b); return this; } + @Override public BooleanIndexer put(long i, boolean b) { + return putRaw(index(i), b); + } @Override public BooleanIndexer put(long i, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, b[offset + n]); + putRaw(index(i) + n, b[offset + n]); } return this; } @Override public BooleanIndexer put(long i, long j, boolean b) { - put(i * strides[0] + j, b); + putRaw(index(i, j), b); return this; } @Override public BooleanIndexer put(long i, long j, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, b[offset + n]); + putRaw(index(i, j) + n, b[offset + n]); } return this; } @Override public BooleanIndexer put(long i, long j, long k, boolean b) { - put(i * strides[0] + j * strides[1] + k, b); + putRaw(index(i, j, k), b); return this; } @Override public BooleanIndexer put(long[] indices, boolean b) { - put(index(indices), b); + putRaw(index(indices), b); return this; } @Override public BooleanIndexer put(long[] indices, boolean[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, b[offset + n]); + putRaw(index(indices) + n, b[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ByteArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ByteArrayIndexer.java index 988b01c1d..c190942ed 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ByteArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ByteArrayIndexer.java @@ -59,25 +59,25 @@ public ByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { } @Override public byte get(long i) { - return array[(int)i]; + return array[(int)index(i)]; } @Override public ByteIndexer get(long i, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = array[(int)i * (int)strides[0] + n]; + b[offset + n] = array[(int)index(i) + n]; } return this; } @Override public byte get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j]; + return array[(int)index(i, j)]; } @Override public ByteIndexer get(long i, long j, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]; + b[offset + n] = array[(int)index(i, j) + n]; } return this; } @Override public byte get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]; + return array[(int)index(i, j, k)]; } @Override public byte get(long... indices) { return array[(int)index(indices)]; @@ -90,27 +90,27 @@ public ByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { } @Override public ByteIndexer put(long i, byte b) { - array[(int)i] = b; + array[(int)index(i)] = b; return this; } @Override public ByteIndexer put(long i, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = b[offset + n]; + array[(int)index(i) + n] = b[offset + n]; } return this; } @Override public ByteIndexer put(long i, long j, byte b) { - array[(int)i * (int)strides[0] + (int)j] = b; + array[(int)index(i, j)] = b; return this; } @Override public ByteIndexer put(long i, long j, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = b[offset + n]; + array[(int)index(i, j) + n] = b[offset + n]; } return this; } @Override public ByteIndexer put(long i, long j, long k, byte b) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = b; + array[(int)index(i, j, k)] = b; return this; } @Override public ByteIndexer put(long[] indices, byte b) { @@ -131,6 +131,14 @@ ByteBuffer getBuffer() { return buffer; } + @Override public byte getByte(long i) { + return array[(int)i]; + } + @Override public ByteIndexer putByte(long i, byte b) { + array[(int)i] = b; + return this; + } + @Override public short getShort(long i) { if (RAW != null) { return RAW.getShort(array, checkIndex(i, array.length - 1)); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ByteBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ByteBufferIndexer.java index b86b1a7d9..2cd447895 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ByteBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ByteBufferIndexer.java @@ -55,25 +55,25 @@ public ByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { } @Override public byte get(long i) { - return buffer.get((int)i); + return buffer.get((int)index(i)); } @Override public ByteIndexer get(long i, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = buffer.get((int)i * (int)strides[0] + n); + b[offset + n] = buffer.get((int)index(i) + n); } return this; } @Override public byte get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j); + return buffer.get((int)index(i, j)); } @Override public ByteIndexer get(long i, long j, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n); + b[offset + n] = buffer.get((int)index(i, j) + n); } return this; } @Override public byte get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k); + return buffer.get((int)index(i, j, k)); } @Override public byte get(long... indices) { return buffer.get((int)index(indices)); @@ -86,27 +86,27 @@ public ByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { } @Override public ByteIndexer put(long i, byte b) { - buffer.put((int)i, b); + buffer.put((int)index(i), b); return this; } @Override public ByteIndexer put(long i, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, b[offset + n]); + buffer.put((int)index(i) + n, b[offset + n]); } return this; } @Override public ByteIndexer put(long i, long j, byte b) { - buffer.put((int)i * (int)strides[0] + (int)j, b); + buffer.put((int)index(i, j), b); return this; } @Override public ByteIndexer put(long i, long j, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, b[offset + n]); + buffer.put((int)index(i, j) + n, b[offset + n]); } return this; } @Override public ByteIndexer put(long i, long j, long k, byte b) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, b); + buffer.put((int)index(i, j, k), b); return this; } @Override public ByteIndexer put(long[] indices, byte b) { @@ -120,6 +120,14 @@ public ByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { return this; } + @Override public byte getByte(long i) { + return buffer.get((int)i); + } + @Override public ByteIndexer putByte(long i, byte b) { + buffer.put((int)i, b); + return this; + } + @Override public short getShort(long i) { return buffer.getShort((int)i); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java index 3e3cb5d12..b58995890 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java @@ -101,19 +101,19 @@ public static ByteIndexer create(final BytePointer pointer, long[] sizes, long[] } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract byte get(long i); - /** Returns {@code this} where {@code b = array/buffer[i]} */ + /** Returns {@code this} where {@code b = array/buffer[index(i)]} */ public ByteIndexer get(long i, byte[] b) { return get(i, b, 0, b.length); } - /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(i)]} */ public abstract ByteIndexer get(long i, byte[] b, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract byte get(long i, long j); - /** Returns {@code this} where {@code b = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code b = array/buffer[index(i, j)]} */ public ByteIndexer get(long i, long j, byte[] b) { return get(i, j, b, 0, b.length); } - /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract ByteIndexer get(long i, long j, byte[] b, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract byte get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract byte get(long... indices); @@ -122,19 +122,19 @@ public static ByteIndexer create(final BytePointer pointer, long[] sizes, long[] /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(indices)]} */ public abstract ByteIndexer get(long[] indices, byte[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b} */ public abstract ByteIndexer put(long i, byte b); - /** Returns {@code this} where {@code array/buffer[i] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b} */ public ByteIndexer put(long i, byte... b) { return put(i, b, 0, b.length); } - /** Returns {@code this} where {@code array/buffer[i] = b[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b[offset:offset + length]} */ public abstract ByteIndexer put(long i, byte[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b} */ public abstract ByteIndexer put(long i, long j, byte b); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b} */ public ByteIndexer put(long i, long j, byte... b) { return put(i, j, b, 0, b.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b[offset:offset + length]} */ public abstract ByteIndexer put(long i, long j, byte[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = b} */ public abstract ByteIndexer put(long i, long j, long k, byte b); /** Returns {@code this} where {@code array/buffer[index(indices)] = b} */ public abstract ByteIndexer put(long[] indices, byte b); @@ -143,6 +143,11 @@ public static ByteIndexer create(final BytePointer pointer, long[] sizes, long[] /** Returns {@code this} where {@code array/buffer[index(indices)] = b[offset:offset + length]} */ public abstract ByteIndexer put(long[] indices, byte[] b, int offset, int length); + /** Returns the {@code byte} value at {@code array/buffer[i]} */ + public abstract byte getByte(long i); + /** Sets the {@code byte} value at {@code array/buffer[i]} */ + public abstract ByteIndexer putByte(long i, byte b); + /** Returns the {@code short} value at {@code array/buffer[i]} */ public abstract short getShort(long i); /** Sets the {@code short} value at {@code array/buffer[i]} */ @@ -174,9 +179,9 @@ public static ByteIndexer create(final BytePointer pointer, long[] sizes, long[] public abstract ByteIndexer putChar(long i, char c); /** Returns the {@code byte} value at {@code array/buffer[i]}, treated as unsigned */ - public int getUByte(long i) { return get(i) & 0xFF; } + public int getUByte(long i) { return getByte(i) & 0xFF; } /** Sets the {@code byte} value at {@code array/buffer[i]}, treated as unsigned */ - public ByteIndexer putUByte(long i, int b) { return put(i, (byte)b); } + public ByteIndexer putUByte(long i, int b) { return putByte(i, (byte)b); } /** Returns the {@code short} value at {@code array/buffer[i]}, treated as unsigned */ public int getUShort(long i) { return getShort(i) & 0xFFFF; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ByteRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ByteRawIndexer.java index 56aef9dee..ff34ba449 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ByteRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ByteRawIndexer.java @@ -60,72 +60,86 @@ public ByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public byte get(long i) { + public byte getRaw(long i) { return RAW.getByte(base + checkIndex(i, size)); } + @Override public byte get(long i) { + return getRaw(index(i)); + } @Override public ByteIndexer get(long i, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(i * strides[0] + n); + b[offset + n] = getRaw(index(i) + n); } return this; } @Override public byte get(long i, long j) { - return get(i * strides[0] + (int)j); + return getRaw(index(i, j)); } @Override public ByteIndexer get(long i, long j, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(i * strides[0] + j * strides[1] + n); + b[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public byte get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public byte get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public ByteIndexer get(long[] indices, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(index(indices) + n); + b[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public ByteIndexer put(long i, byte b) { + public ByteIndexer putRaw(long i, byte b) { RAW.putByte(base + checkIndex(i, size), b); return this; } + @Override public ByteIndexer put(long i, byte b) { + return putRaw(index(i), b); + } @Override public ByteIndexer put(long i, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, b[offset + n]); + putRaw(index(i) + n, b[offset + n]); } return this; } @Override public ByteIndexer put(long i, long j, byte b) { - put(i * strides[0] + j, b); + putRaw(index(i, j), b); return this; } @Override public ByteIndexer put(long i, long j, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, b[offset + n]); + putRaw(index(i, j) + n, b[offset + n]); } return this; } @Override public ByteIndexer put(long i, long j, long k, byte b) { - put(i * strides[0] + j * strides[1] + k, b); + putRaw(index(i, j, k), b); return this; } @Override public ByteIndexer put(long[] indices, byte b) { - put(index(indices), b); + putRaw(index(indices), b); return this; } @Override public ByteIndexer put(long[] indices, byte[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, b[offset + n]); + putRaw(index(indices) + n, b[offset + n]); } return this; } + @Override public byte getByte(long i) { + return RAW.getByte(base + checkIndex(i, size - 1)); + } + @Override public ByteIndexer putByte(long i, byte b) { + RAW.putByte(base + checkIndex(i, size - 1), b); + return this; + } + @Override public short getShort(long i) { return RAW.getShort(base + checkIndex(i, size - 1)); } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/CharArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/CharArrayIndexer.java index 7e62bef3d..f8ab8cd8e 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/CharArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/CharArrayIndexer.java @@ -52,25 +52,25 @@ public CharArrayIndexer(char[] array, long[] sizes, long[] strides) { } @Override public char get(long i) { - return array[(int)i]; + return array[(int)index(i)]; } @Override public CharIndexer get(long i, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - c[offset + n] = array[(int)i * (int)strides[0] + n]; + c[offset + n] = array[(int)index(i) + n]; } return this; } @Override public char get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j]; + return array[(int)index(i, j)]; } @Override public CharIndexer get(long i, long j, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - c[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]; + c[offset + n] = array[(int)index(i, j) + n]; } return this; } @Override public char get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]; + return array[(int)index(i, j, k)]; } @Override public char get(long... indices) { return array[(int)index(indices)]; @@ -83,27 +83,27 @@ public CharArrayIndexer(char[] array, long[] sizes, long[] strides) { } @Override public CharIndexer put(long i, char c) { - array[(int)i] = c; + array[(int)index(i)] = c; return this; } @Override public CharIndexer put(long i, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = c[offset + n]; + array[(int)index(i) + n] = c[offset + n]; } return this; } @Override public CharIndexer put(long i, long j, char c) { - array[(int)i * (int)strides[0] + (int)j] = c; + array[(int)index(i, j)] = c; return this; } @Override public CharIndexer put(long i, long j, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = c[offset + n]; + array[(int)index(i, j) + n] = c[offset + n]; } return this; } @Override public CharIndexer put(long i, long j, long k, char c) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = c; + array[(int)index(i, j, k)] = c; return this; } @Override public CharIndexer put(long[] indices, char c) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/CharBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/CharBufferIndexer.java index 30188ef9d..ae449a90f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/CharBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/CharBufferIndexer.java @@ -55,25 +55,25 @@ public CharBufferIndexer(CharBuffer buffer, long[] sizes, long[] strides) { } @Override public char get(long i) { - return buffer.get((int)i); + return buffer.get((int)index(i)); } @Override public CharIndexer get(long i, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - c[offset + n] = buffer.get((int)i * (int)strides[0] + n); + c[offset + n] = buffer.get((int)index(i) + n); } return this; } @Override public char get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j); + return buffer.get((int)index(i, j)); } @Override public CharIndexer get(long i, long j, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - c[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n); + c[offset + n] = buffer.get((int)index(i, j) + n); } return this; } @Override public char get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k); + return buffer.get((int)index(i, j, k)); } @Override public char get(long... indices) { return buffer.get((int)index(indices)); @@ -86,27 +86,27 @@ public CharBufferIndexer(CharBuffer buffer, long[] sizes, long[] strides) { } @Override public CharIndexer put(long i, char c) { - buffer.put((int)i, c); + buffer.put((int)index(i), c); return this; } @Override public CharIndexer put(long i, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, c[offset + n]); + buffer.put((int)index(i) + n, c[offset + n]); } return this; } @Override public CharIndexer put(long i, long j, char c) { - buffer.put((int)i * (int)strides[0] + (int)j, c); + buffer.put((int)index(i, j), c); return this; } @Override public CharIndexer put(long i, long j, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, c[offset + n]); + buffer.put((int)index(i, j) + n, c[offset + n]); } return this; } @Override public CharIndexer put(long i, long j, long k, char c) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, c); + buffer.put((int)index(i, j, k), c); return this; } @Override public CharIndexer put(long[] indices, char c) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/CharIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/CharIndexer.java index 65bd6c1aa..4792fdffc 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/CharIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/CharIndexer.java @@ -100,19 +100,19 @@ public static CharIndexer create(final CharPointer pointer, long[] sizes, long[] } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract char get(long i); - /** Returns {@code this} where {@code c = array/buffer[i]} */ + /** Returns {@code this} where {@code c = array/buffer[index(i)]} */ public CharIndexer get(long i, char[] c) { return get(i, c, 0, c.length); } - /** Returns {@code this} where {@code c[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code c[offset:offset + length] = array/buffer[index(i)]} */ public abstract CharIndexer get(long i, char[] c, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract char get(long i, long j); - /** Returns {@code this} where {@code c = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code c = array/buffer[index(i, j)]} */ public CharIndexer get(long i, long j, char[] c) { return get(i, j, c, 0, c.length); } - /** Returns {@code this} where {@code c[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code c[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract CharIndexer get(long i, long j, char[] c, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract char get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract char get(long... indices); @@ -121,19 +121,19 @@ public static CharIndexer create(final CharPointer pointer, long[] sizes, long[] /** Returns {@code this} where {@code c[offset:offset + length] = array/buffer[index(indices)]} */ public abstract CharIndexer get(long[] indices, char[] c, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = c} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = c} */ public abstract CharIndexer put(long i, char c); - /** Returns {@code this} where {@code array/buffer[i] = c} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = c} */ public CharIndexer put(long i, char... c) { return put(i, c, 0, c.length); } - /** Returns {@code this} where {@code array/buffer[i] = c[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = c[offset:offset + length]} */ public abstract CharIndexer put(long i, char[] c, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = c} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = c} */ public abstract CharIndexer put(long i, long j, char c); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = c} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = c} */ public CharIndexer put(long i, long j, char... c) { return put(i, j, c, 0, c.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = c[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = c[offset:offset + length]} */ public abstract CharIndexer put(long i, long j, char[] c, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = c} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = c} */ public abstract CharIndexer put(long i, long j, long k, char c); /** Returns {@code this} where {@code array/buffer[index(indices)] = c} */ public abstract CharIndexer put(long[] indices, char c); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/CharRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/CharRawIndexer.java index 7efbdcbbe..b3885bab6 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/CharRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/CharRawIndexer.java @@ -60,68 +60,74 @@ public CharRawIndexer(CharPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public char get(long i) { + public char getRaw(long i) { return RAW.getChar(base + checkIndex(i, size) * VALUE_BYTES); } + @Override public char get(long i) { + return getRaw(index(i)); + } @Override public CharIndexer get(long i, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - c[offset + n] = get(i * strides[0] + n); + c[offset + n] = getRaw(index(i) + n); } return this; } @Override public char get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public CharIndexer get(long i, long j, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - c[offset + n] = get(i * strides[0] + j * strides[1] + n); + c[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public char get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public char get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public CharIndexer get(long[] indices, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - c[offset + n] = get(index(indices) + n); + c[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public CharIndexer put(long i, char c) { + public CharIndexer putRaw(long i, char c) { RAW.putChar(base + checkIndex(i, size) * VALUE_BYTES, c); return this; } + @Override public CharIndexer put(long i, char c) { + return putRaw(index(i), c); + } @Override public CharIndexer put(long i, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, c[offset + n]); + putRaw(index(i) + n, c[offset + n]); } return this; } @Override public CharIndexer put(long i, long j, char c) { - put(i * strides[0] + j, c); + putRaw(index(i, j), c); return this; } @Override public CharIndexer put(long i, long j, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, c[offset + n]); + putRaw(index(i, j) + n, c[offset + n]); } return this; } @Override public CharIndexer put(long i, long j, long k, char c) { - put(i * strides[0] + j * strides[1] + k, c); + putRaw(index(i, j, k), c); return this; } @Override public CharIndexer put(long[] indices, char c) { - put(index(indices), c); + putRaw(index(indices), c); return this; } @Override public CharIndexer put(long[] indices, char[] c, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, c[offset + n]); + putRaw(index(indices) + n, c[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/DoubleArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/DoubleArrayIndexer.java index 3c48a6ca1..d22e2bd95 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/DoubleArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/DoubleArrayIndexer.java @@ -52,25 +52,25 @@ public DoubleArrayIndexer(double[] array, long[] sizes, long[] strides) { } @Override public double get(long i) { - return array[(int)i]; + return array[(int)index(i)]; } @Override public DoubleIndexer get(long i, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - d[offset + n] = array[(int)i * (int)strides[0] + n]; + d[offset + n] = array[(int)index(i) + n]; } return this; } @Override public double get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j]; + return array[(int)index(i, j)]; } @Override public DoubleIndexer get(long i, long j, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - d[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]; + d[offset + n] = array[(int)index(i, j) + n]; } return this; } @Override public double get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]; + return array[(int)index(i, j, k)]; } @Override public double get(long... indices) { return array[(int)index(indices)]; @@ -83,27 +83,27 @@ public DoubleArrayIndexer(double[] array, long[] sizes, long[] strides) { } @Override public DoubleIndexer put(long i, double d) { - array[(int)i] = d; + array[(int)index(i)] = d; return this; } @Override public DoubleIndexer put(long i, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = d[offset + n]; + array[(int)index(i) + n] = d[offset + n]; } return this; } @Override public DoubleIndexer put(long i, long j, double d) { - array[(int)i * (int)strides[0] + (int)j] = d; + array[(int)index(i, j)] = d; return this; } @Override public DoubleIndexer put(long i, long j, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = d[offset + n]; + array[(int)index(i, j) + n] = d[offset + n]; } return this; } @Override public DoubleIndexer put(long i, long j, long k, double d) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = d; + array[(int)index(i, j, k)] = d; return this; } @Override public DoubleIndexer put(long[] indices, double d) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/DoubleBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/DoubleBufferIndexer.java index be28a718e..e0f17b0d5 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/DoubleBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/DoubleBufferIndexer.java @@ -55,25 +55,25 @@ public DoubleBufferIndexer(DoubleBuffer buffer, long[] sizes, long[] strides) { } @Override public double get(long i) { - return buffer.get((int)i); + return buffer.get((int)index(i)); } @Override public DoubleIndexer get(long i, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - d[offset + n] = buffer.get((int)i * (int)strides[0] + n); + d[offset + n] = buffer.get((int)index(i) + n); } return this; } @Override public double get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j); + return buffer.get((int)index(i, j)); } @Override public DoubleIndexer get(long i, long j, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - d[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n); + d[offset + n] = buffer.get((int)index(i, j) + n); } return this; } @Override public double get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k); + return buffer.get((int)index(i, j, k)); } @Override public double get(long... indices) { return buffer.get((int)index(indices)); @@ -86,27 +86,27 @@ public DoubleBufferIndexer(DoubleBuffer buffer, long[] sizes, long[] strides) { } @Override public DoubleIndexer put(long i, double d) { - buffer.put((int)i, d); + buffer.put((int)index(i), d); return this; } @Override public DoubleIndexer put(long i, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, d[offset + n]); + buffer.put((int)index(i) + n, d[offset + n]); } return this; } @Override public DoubleIndexer put(long i, long j, double d) { - buffer.put((int)i * (int)strides[0] + (int)j, d); + buffer.put((int)index(i, j), d); return this; } @Override public DoubleIndexer put(long i, long j, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, d[offset + n]); + buffer.put((int)index(i, j) + n, d[offset + n]); } return this; } @Override public DoubleIndexer put(long i, long j, long k, double d) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, d); + buffer.put((int)index(i, j, k), d); return this; } @Override public DoubleIndexer put(long[] indices, double d) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/DoubleIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/DoubleIndexer.java index 45e830999..808278c90 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/DoubleIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/DoubleIndexer.java @@ -100,19 +100,19 @@ public static DoubleIndexer create(final DoublePointer pointer, long[] sizes, lo } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract double get(long i); - /** Returns {@code this} where {@code d = array/buffer[i]} */ + /** Returns {@code this} where {@code d = array/buffer[index(i)]} */ public DoubleIndexer get(long i, double[] d) { return get(i, d, 0, d.length); } - /** Returns {@code this} where {@code d[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code d[offset:offset + length] = array/buffer[index(i)]} */ public abstract DoubleIndexer get(long i, double[] d, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract double get(long i, long j); - /** Returns {@code this} where {@code d = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code d = array/buffer[index(i, j)]} */ public DoubleIndexer get(long i, long j, double[] d) { return get(i, j, d, 0, d.length); } - /** Returns {@code this} where {@code d[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code d[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract DoubleIndexer get(long i, long j, double[] d, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract double get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract double get(long... indices); @@ -121,19 +121,19 @@ public static DoubleIndexer create(final DoublePointer pointer, long[] sizes, lo /** Returns {@code this} where {@code d[offset:offset + length] = array/buffer[index(indices)]} */ public abstract DoubleIndexer get(long[] indices, double[] d, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = d} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = d} */ public abstract DoubleIndexer put(long i, double d); - /** Returns {@code this} where {@code array/buffer[i] = d} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = d} */ public DoubleIndexer put(long i, double... d) { return put(i, d, 0, d.length); } - /** Returns {@code this} where {@code array/buffer[i] = d[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = d[offset:offset + length]} */ public abstract DoubleIndexer put(long i, double[] d, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = d} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = d} */ public abstract DoubleIndexer put(long i, long j, double d); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = d} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = d} */ public DoubleIndexer put(long i, long j, double... d) { return put(i, j, d, 0, d.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = d[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = d[offset:offset + length]} */ public abstract DoubleIndexer put(long i, long j, double[] d, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = d} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = d} */ public abstract DoubleIndexer put(long i, long j, long k, double d); /** Returns {@code this} where {@code array/buffer[index(indices)] = d} */ public abstract DoubleIndexer put(long[] indices, double d); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/DoubleRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/DoubleRawIndexer.java index 8e21a1e4c..2dd8ab45e 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/DoubleRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/DoubleRawIndexer.java @@ -60,68 +60,74 @@ public DoubleRawIndexer(DoublePointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public double get(long i) { + public double getRaw(long i) { return RAW.getDouble(base + checkIndex(i, size) * VALUE_BYTES); } + @Override public double get(long i) { + return getRaw(index(i)); + } @Override public DoubleIndexer get(long i, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - d[offset + n] = get(i * strides[0] + n); + d[offset + n] = getRaw(index(i) + n); } return this; } @Override public double get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public DoubleIndexer get(long i, long j, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - d[offset + n] = get(i * strides[0] + j * strides[1] + n); + d[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public double get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public double get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public DoubleIndexer get(long[] indices, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - d[offset + n] = get(index(indices) + n); + d[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public DoubleIndexer put(long i, double d) { + public DoubleIndexer putRaw(long i, double d) { RAW.putDouble(base + checkIndex(i, size) * VALUE_BYTES, d); return this; } + @Override public DoubleIndexer put(long i, double d) { + return put(index(i), d); + } @Override public DoubleIndexer put(long i, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, d[offset + n]); + putRaw(index(i) + n, d[offset + n]); } return this; } @Override public DoubleIndexer put(long i, long j, double d) { - put(i * strides[0] + j, d); + putRaw(index(i, j), d); return this; } @Override public DoubleIndexer put(long i, long j, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, d[offset + n]); + putRaw(index(i, j) + n, d[offset + n]); } return this; } @Override public DoubleIndexer put(long i, long j, long k, double d) { - put(i * strides[0] + j * strides[1] + k, d); + putRaw(index(i, j, k), d); return this; } @Override public DoubleIndexer put(long[] indices, double d) { - put(index(indices), d); + putRaw(index(indices), d); return this; } @Override public DoubleIndexer put(long[] indices, double[] d, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, d[offset + n]); + putRaw(index(indices) + n, d[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/FloatArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/FloatArrayIndexer.java index 07f7c83f0..9751fcc84 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/FloatArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/FloatArrayIndexer.java @@ -52,25 +52,25 @@ public FloatArrayIndexer(float[] array, long[] sizes, long[] strides) { } @Override public float get(long i) { - return array[(int)i]; + return array[(int)index(i)]; } @Override public FloatIndexer get(long i, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - f[offset + n] = array[(int)i * (int)strides[0] + n]; + f[offset + n] = array[(int)index(i) + n]; } return this; } @Override public float get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j]; + return array[(int)index(i, j)]; } @Override public FloatIndexer get(long i, long j, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - f[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]; + f[offset + n] = array[(int)index(i, j) + n]; } return this; } @Override public float get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]; + return array[(int)index(i, j, k)]; } @Override public float get(long... indices) { return array[(int)index(indices)]; @@ -83,27 +83,27 @@ public FloatArrayIndexer(float[] array, long[] sizes, long[] strides) { } @Override public FloatIndexer put(long i, float f) { - array[(int)i] = f; + array[(int)index(i)] = f; return this; } @Override public FloatIndexer put(long i, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = f[offset + n]; + array[(int)index(i) + n] = f[offset + n]; } return this; } @Override public FloatIndexer put(long i, long j, float f) { - array[(int)i * (int)strides[0] + (int)j] = f; + array[(int)index(i, j)] = f; return this; } @Override public FloatIndexer put(long i, long j, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = f[offset + n]; + array[(int)index(i, j) + n] = f[offset + n]; } return this; } @Override public FloatIndexer put(long i, long j, long k, float f) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = f; + array[(int)index(i, j, k)] = f; return this; } @Override public FloatIndexer put(long[] indices, float f) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/FloatBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/FloatBufferIndexer.java index ba4f4d081..50dcb5bc9 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/FloatBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/FloatBufferIndexer.java @@ -55,25 +55,25 @@ public FloatBufferIndexer(FloatBuffer buffer, long[] sizes, long[] strides) { } @Override public float get(long i) { - return buffer.get((int)i); + return buffer.get((int)index(i)); } @Override public FloatIndexer get(long i, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - f[offset + n] = buffer.get((int)i * (int)strides[0] + n); + f[offset + n] = buffer.get((int)index(i) + n); } return this; } @Override public float get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j); + return buffer.get((int)index(i, j)); } @Override public FloatIndexer get(long i, long j, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - f[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n); + f[offset + n] = buffer.get((int)index(i, j) + n); } return this; } @Override public float get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k); + return buffer.get((int)index(i, j, k)); } @Override public float get(long... indices) { return buffer.get((int)index(indices)); @@ -86,27 +86,27 @@ public FloatBufferIndexer(FloatBuffer buffer, long[] sizes, long[] strides) { } @Override public FloatIndexer put(long i, float f) { - buffer.put((int)i, f); + buffer.put((int)index(i), f); return this; } @Override public FloatIndexer put(long i, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, f[offset + n]); + buffer.put((int)index(i) + n, f[offset + n]); } return this; } @Override public FloatIndexer put(long i, long j, float f) { - buffer.put((int)i * (int)strides[0] + (int)j, f); + buffer.put((int)index(i, j), f); return this; } @Override public FloatIndexer put(long i, long j, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, f[offset + n]); + buffer.put((int)index(i, j) + n, f[offset + n]); } return this; } @Override public FloatIndexer put(long i, long j, long k, float f) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, f); + buffer.put((int)index(i, j, k), f); return this; } @Override public FloatIndexer put(long[] indices, float f) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/FloatIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/FloatIndexer.java index 9f32b803b..a367ca427 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/FloatIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/FloatIndexer.java @@ -100,19 +100,19 @@ public static FloatIndexer create(final FloatPointer pointer, long[] sizes, long } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract float get(long i); - /** Returns {@code this} where {@code f = array/buffer[i]} */ + /** Returns {@code this} where {@code f = array/buffer[index(i)]} */ public FloatIndexer get(long i, float[] f) { return get(i, f, 0, f.length); } - /** Returns {@code this} where {@code f[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code f[offset:offset + length] = array/buffer[index(i)]} */ public abstract FloatIndexer get(long i, float[] f, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract float get(long i, long j); - /** Returns {@code this} where {@code f = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code f = array/buffer[index(i, j)]} */ public FloatIndexer get(long i, long j, float[] f) { return get(i, j, f, 0, f.length); } - /** Returns {@code this} where {@code f[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code f[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract FloatIndexer get(long i, long j, float[] f, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract float get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract float get(long... indices); @@ -121,19 +121,19 @@ public static FloatIndexer create(final FloatPointer pointer, long[] sizes, long /** Returns {@code this} where {@code f[offset:offset + length] = array/buffer[index(indices)]} */ public abstract FloatIndexer get(long[] indices, float[] f, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = f} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = f} */ public abstract FloatIndexer put(long i, float f); - /** Returns {@code this} where {@code array/buffer[i] = f} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = f} */ public FloatIndexer put(long i, float... f) { return put(i, f, 0, f.length); } - /** Returns {@code this} where {@code array/buffer[i] = f[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = f[offset:offset + length]} */ public abstract FloatIndexer put(long i, float[] f, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = f} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = f} */ public abstract FloatIndexer put(long i, long j, float f); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = f} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = f} */ public FloatIndexer put(long i, long j, float... f) { return put(i, j, f, 0, f.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = f[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = f[offset:offset + length]} */ public abstract FloatIndexer put(long i, long j, float[] f, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = f} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = f} */ public abstract FloatIndexer put(long i, long j, long k, float f); /** Returns {@code this} where {@code array/buffer[index(indices)] = f} */ public abstract FloatIndexer put(long[] indices, float f); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/FloatRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/FloatRawIndexer.java index ee13f11a2..31ebbcba8 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/FloatRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/FloatRawIndexer.java @@ -60,68 +60,74 @@ public FloatRawIndexer(FloatPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public float get(long i) { + public float getRaw(long i) { return RAW.getFloat(base + checkIndex(i, size) * VALUE_BYTES); } + @Override public float get(long i) { + return getRaw(index(i)); + } @Override public FloatIndexer get(long i, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - f[offset + n] = get(i * strides[0] + n); + f[offset + n] = getRaw(index(i) + n); } return this; } @Override public float get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public FloatIndexer get(long i, long j, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - f[offset + n] = get(i * strides[0] + j * strides[1] + n); + f[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public float get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public float get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public FloatIndexer get(long[] indices, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - f[offset + n] = get(index(indices) + n); + f[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public FloatIndexer put(long i, float f) { + public FloatIndexer putRaw(long i, float f) { RAW.putFloat(base + checkIndex(i, size) * VALUE_BYTES, f); return this; } + @Override public FloatIndexer put(long i, float f) { + return putRaw(index(i), f); + } @Override public FloatIndexer put(long i, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, f[offset + n]); + putRaw(index(i) + n, f[offset + n]); } return this; } @Override public FloatIndexer put(long i, long j, float f) { - put(i * strides[0] + j, f); + putRaw(index(i, j), f); return this; } @Override public FloatIndexer put(long i, long j, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, f[offset + n]); + putRaw(index(i, j) + n, f[offset + n]); } return this; } @Override public FloatIndexer put(long i, long j, long k, float f) { - put(i * strides[0] + j * strides[1] + k, f); + putRaw(index(i, j, k), f); return this; } @Override public FloatIndexer put(long[] indices, float f) { - put(index(indices), f); + putRaw(index(indices), f); return this; } @Override public FloatIndexer put(long[] indices, float[] f, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, f[offset + n]); + putRaw(index(indices) + n, f[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/HalfArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/HalfArrayIndexer.java index b1773306c..a5204ad10 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/HalfArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/HalfArrayIndexer.java @@ -52,25 +52,25 @@ public HalfArrayIndexer(short[] array, long[] sizes, long[] strides) { } @Override public float get(long i) { - return toFloat(array[(int)i]); + return toFloat(array[(int)index(i)]); } @Override public HalfIndexer get(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = toFloat(array[(int)i * (int)strides[0] + n]); + h[offset + n] = toFloat(array[(int)index(i) + n]); } return this; } @Override public float get(long i, long j) { - return toFloat(array[(int)i * (int)strides[0] + (int)j]); + return toFloat(array[(int)index(i, j)]); } @Override public HalfIndexer get(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = toFloat(array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]); + h[offset + n] = toFloat(array[(int)index(i, j) + n]); } return this; } @Override public float get(long i, long j, long k) { - return toFloat(array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]); + return toFloat(array[(int)index(i, j, k)]); } @Override public float get(long... indices) { return toFloat(array[(int)index(indices)]); @@ -83,27 +83,27 @@ public HalfArrayIndexer(short[] array, long[] sizes, long[] strides) { } @Override public HalfIndexer put(long i, float h) { - array[(int)i] = (short)fromFloat(h); + array[(int)index(i)] = (short)fromFloat(h); return this; } @Override public HalfIndexer put(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = (short)fromFloat(h[offset + n]); + array[(int)index(i) + n] = (short)fromFloat(h[offset + n]); } return this; } @Override public HalfIndexer put(long i, long j, float h) { - array[(int)i * (int)strides[0] + (int)j] = (short)fromFloat(h); + array[(int)index(i, j)] = (short)fromFloat(h); return this; } @Override public HalfIndexer put(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = (short)fromFloat(h[offset + n]); + array[(int)index(i, j) + n] = (short)fromFloat(h[offset + n]); } return this; } @Override public HalfIndexer put(long i, long j, long k, float h) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = (short)fromFloat(h); + array[(int)index(i, j, k)] = (short)fromFloat(h); return this; } @Override public HalfIndexer put(long[] indices, float h) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/HalfBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/HalfBufferIndexer.java index 6911ff4ff..fb2e7bcf4 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/HalfBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/HalfBufferIndexer.java @@ -55,25 +55,25 @@ public HalfBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { } @Override public float get(long i) { - return toFloat(buffer.get((int)i)); + return toFloat(buffer.get((int)index(i))); } @Override public HalfIndexer get(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = toFloat(buffer.get((int)i * (int)strides[0] + n)); + h[offset + n] = toFloat(buffer.get((int)index(i) + n)); } return this; } @Override public float get(long i, long j) { - return toFloat(buffer.get((int)i * (int)strides[0] + (int)j)); + return toFloat(buffer.get((int)index(i, j))); } @Override public HalfIndexer get(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = toFloat(buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n)); + h[offset + n] = toFloat(buffer.get((int)index(i, j) + n)); } return this; } @Override public float get(long i, long j, long k) { - return toFloat(buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k)); + return toFloat(buffer.get((int)index(i, j, k))); } @Override public float get(long... indices) { return toFloat(buffer.get((int)index(indices))); @@ -86,27 +86,27 @@ public HalfBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { } @Override public HalfIndexer put(long i, float h) { - buffer.put((int)i, (short)fromFloat(h)); + buffer.put((int)index(i), (short)fromFloat(h)); return this; } @Override public HalfIndexer put(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, (short)fromFloat(h[offset + n])); + buffer.put((int)index(i) + n, (short)fromFloat(h[offset + n])); } return this; } @Override public HalfIndexer put(long i, long j, float h) { - buffer.put((int)i * (int)strides[0] + (int)j, (short)fromFloat(h)); + buffer.put((int)index(i, j), (short)fromFloat(h)); return this; } @Override public HalfIndexer put(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, (short)fromFloat(h[offset + n])); + buffer.put((int)index(i, j) + n, (short)fromFloat(h[offset + n])); } return this; } @Override public HalfIndexer put(long i, long j, long k, float h) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, (short)fromFloat(h)); + buffer.put((int)index(i, j, k), (short)fromFloat(h)); return this; } @Override public HalfIndexer put(long[] indices, float h) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/HalfIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/HalfIndexer.java index 875168b21..fbb6950e0 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/HalfIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/HalfIndexer.java @@ -160,48 +160,48 @@ public static int fromFloat( float fval ) >>> 126 - val ); // div by 2^(1-(exp-127+15)) and >> 13 | exp=0 } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract float get(long i); - /** Returns {@code this} where {@code s = array/buffer[i]} */ + /** Returns {@code this} where {@code h = array/buffer[index(i)]} */ public HalfIndexer get(long i, float[] h) { return get(i, h, 0, h.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code h[offset:offset + length] = array/buffer[index(i)]} */ public abstract HalfIndexer get(long i, float[] h, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract float get(long i, long j); - /** Returns {@code this} where {@code s = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code h = array/buffer[index(i, j)]} */ public HalfIndexer get(long i, long j, float[] h) { return get(i, j, h, 0, h.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code h[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract HalfIndexer get(long i, long j, float[] h, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract float get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract float get(long... indices); - /** Returns {@code this} where {@code s = array/buffer[index(indices)]} */ + /** Returns {@code this} where {@code h = array/buffer[index(indices)]} */ public HalfIndexer get(long[] indices, float[] h) { return get(indices, h, 0, h.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[index(indices)]} */ + /** Returns {@code this} where {@code h[offset:offset + length] = array/buffer[index(indices)]} */ public abstract HalfIndexer get(long[] indices, float[] h, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = h} */ public abstract HalfIndexer put(long i, float h); - /** Returns {@code this} where {@code array/buffer[i] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = h} */ public HalfIndexer put(long i, float... h) { return put(i, h, 0, h.length); } - /** Returns {@code this} where {@code array/buffer[i] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = h[offset:offset + length]} */ public abstract HalfIndexer put(long i, float[] h, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = h} */ public abstract HalfIndexer put(long i, long j, float h); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = h} */ public HalfIndexer put(long i, long j, float... h) { return put(i, j, h, 0, h.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = h[offset:offset + length]} */ public abstract HalfIndexer put(long i, long j, float[] h, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = h} */ public abstract HalfIndexer put(long i, long j, long k, float h); - /** Returns {@code this} where {@code array/buffer[index(indices)] = s} */ + /** Returns {@code this} where {@code array/buffer[index(indices)] = h} */ public abstract HalfIndexer put(long[] indices, float h); - /** Returns {@code this} where {@code array/buffer[index(indices)] = s} */ + /** Returns {@code this} where {@code array/buffer[index(indices)] = h} */ public HalfIndexer put(long[] indices, float... h) { return put(indices, h, 0, h.length); } - /** Returns {@code this} where {@code array/buffer[index(indices)] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(indices)] = h[offset:offset + length]} */ public abstract HalfIndexer put(long[] indices, float[] h, int offset, int length); @Override public double getDouble(long... indices) { return get(indices); } - @Override public HalfIndexer putDouble(long[] indices, double s) { return put(indices, (float)s); } + @Override public HalfIndexer putDouble(long[] indices, double h) { return put(indices, (float)h); } } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/HalfRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/HalfRawIndexer.java index 97c12baa0..5ba0e0dd7 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/HalfRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/HalfRawIndexer.java @@ -60,68 +60,74 @@ public HalfRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public float get(long i) { + public float getRaw(long i) { return toFloat(RAW.getShort(base + checkIndex(i, size) * VALUE_BYTES)); } + @Override public float get(long i) { + return getRaw(index(i)); + } @Override public HalfIndexer get(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = get(i * strides[0] + n); + h[offset + n] = getRaw(index(i) + n); } return this; } @Override public float get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public HalfIndexer get(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = get(i * strides[0] + j * strides[1] + n); + h[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public float get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public float get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public HalfIndexer get(long[] indices, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - h[offset + n] = get(index(indices) + n); + h[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public HalfIndexer put(long i, float h) { + public HalfIndexer putRaw(long i, float h) { RAW.putShort(base + checkIndex(i, size) * VALUE_BYTES, (short)fromFloat(h)); return this; } + @Override public HalfIndexer put(long i, float h) { + return putRaw(index(i), h); + } @Override public HalfIndexer put(long i, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, h[offset + n]); + putRaw(index(i) + n, h[offset + n]); } return this; } @Override public HalfIndexer put(long i, long j, float h) { - put(i * strides[0] + j, h); + putRaw(index(i, j), h); return this; } @Override public HalfIndexer put(long i, long j, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, h[offset + n]); + putRaw(index(i, j) + n, h[offset + n]); } return this; } @Override public HalfIndexer put(long i, long j, long k, float h) { - put(i * strides[0] + j * strides[1] + k, h); + putRaw(index(i, j, k), h); return this; } @Override public HalfIndexer put(long[] indices, float h) { - put(index(indices), h); + putRaw(index(indices), h); return this; } @Override public HalfIndexer put(long[] indices, float[] h, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, h[offset + n]); + putRaw(index(indices) + n, h[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/Indexer.java b/src/main/java/org/bytedeco/javacpp/indexer/Indexer.java index 3067bb335..c6a4bf3d3 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/Indexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/Indexer.java @@ -108,18 +108,54 @@ public static long[] strides(long... sizes) { return strides; } - /** - * Computes the linear index as the dot product of indices and strides. - * - * @param indices of each dimension - * @return index to access array or buffer - */ - public long index(long... indices) { - long index = 0; - for (int i = 0; i < indices.length && i < strides.length; i++) { - index += indices[i] * strides[i]; + protected class Index { + public long index(long i) { + return i * strides[0]; + } + + public long index(long i, long j) { + return i * strides[0] + j * strides[1]; + } + + public long index(long i, long j, long k) { + return i * strides[0] + j * strides[1] + k * strides[2]; + } + + /** + * Computes the linear index as the dot product of indices and strides. + * + * @param indices of each dimension + * @return index to access array or buffer + */ + public long index(long... indices) { + long index = 0; + for (int i = 0; i < indices.length && i < strides.length; i++) { + index += indices[i] * strides[i]; + } + return index; } - return index; + } + + protected Index index = new Index(); + + /** Returns {@code index.index(i)}. */ + public long index(long i) { + return index.index(i); + } + + /** Returns {@code index.index(i, j)}. */ + public long index(long i, long j) { + return index.index(i, j); + } + + /** Returns {@code index.index(i, j, k)}. */ + public long index(long i, long j, long k) { + return index.index(i, j, k); + } + + /** Returns {@code index.index(indices)}. */ + public long index(long... indices) { + return index.index(indices); } /** The associated (optional) {@link Indexable}. */ diff --git a/src/main/java/org/bytedeco/javacpp/indexer/IntArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/IntArrayIndexer.java index f465ae148..4b3e4c1d6 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/IntArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/IntArrayIndexer.java @@ -52,25 +52,25 @@ public IntArrayIndexer(int[] array, long[] sizes, long[] strides) { } @Override public int get(long i) { - return array[(int)i]; + return array[(int)index(i)]; } @Override public IntIndexer get(long i, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = array[(int)i * (int)strides[0] + n]; + m[offset + n] = array[(int)index(i) + n]; } return this; } @Override public int get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j]; + return array[(int)index(i, j)]; } @Override public IntIndexer get(long i, long j, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]; + m[offset + n] = array[(int)index(i, j) + n]; } return this; } @Override public int get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]; + return array[(int)index(i, j, k)]; } @Override public int get(long... indices) { return array[(int)index(indices)]; @@ -83,27 +83,27 @@ public IntArrayIndexer(int[] array, long[] sizes, long[] strides) { } @Override public IntIndexer put(long i, int n) { - array[(int)i] = n; + array[(int)index(i)] = n; return this; } @Override public IntIndexer put(long i, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = m[offset + n]; + array[(int)index(i) + n] = m[offset + n]; } return this; } @Override public IntIndexer put(long i, long j, int n) { - array[(int)i * (int)strides[0] + (int)j] = n; + array[(int)index(i, j)] = n; return this; } @Override public IntIndexer put(long i, long j, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = m[offset + n]; + array[(int)index(i, j) + n] = m[offset + n]; } return this; } @Override public IntIndexer put(long i, long j, long k, int n) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = n; + array[(int)index(i, j, k)] = n; return this; } @Override public IntIndexer put(long[] indices, int n) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/IntBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/IntBufferIndexer.java index 28ade931b..8328f5c49 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/IntBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/IntBufferIndexer.java @@ -55,25 +55,25 @@ public IntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { } @Override public int get(long i) { - return buffer.get((int)i); + return buffer.get((int)index(i)); } @Override public IntIndexer get(long i, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = buffer.get((int)i * (int)strides[0] + n); + m[offset + n] = buffer.get((int)index(i) + n); } return this; } @Override public int get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j); + return buffer.get((int)index(i, j)); } @Override public IntIndexer get(long i, long j, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n); + m[offset + n] = buffer.get((int)index(i, j) + n); } return this; } @Override public int get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k); + return buffer.get((int)index(i, j, k)); } @Override public int get(long... indices) { return buffer.get((int)index(indices)); @@ -86,27 +86,27 @@ public IntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { } @Override public IntIndexer put(long i, int n) { - buffer.put((int)i, n); + buffer.put((int)index(i), n); return this; } @Override public IntIndexer put(long i, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, m[offset + n]); + buffer.put((int)index(i) + n, m[offset + n]); } return this; } @Override public IntIndexer put(long i, long j, int n) { - buffer.put((int)i * (int)strides[0] + (int)j, n); + buffer.put((int)index(i, j), n); return this; } @Override public IntIndexer put(long i, long j, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, m[offset + n]); + buffer.put((int)index(i, j) + n, m[offset + n]); } return this; } @Override public IntIndexer put(long i, long j, long k, int n) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, n); + buffer.put((int)index(i, j, k), n); return this; } @Override public IntIndexer put(long[] indices, int n) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/IntIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/IntIndexer.java index 8647b0c80..b62b1c018 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/IntIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/IntIndexer.java @@ -100,19 +100,19 @@ public static IntIndexer create(final IntPointer pointer, long[] sizes, long[] s } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract int get(long i); - /** Returns {@code this} where {@code n = array/buffer[i]} */ + /** Returns {@code this} where {@code n = array/buffer[index(i)]} */ public IntIndexer get(long i, int[] n) { return get(i, n, 0, n.length); } - /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[index(i)]} */ public abstract IntIndexer get(long i, int[] n, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract int get(long i, long j); - /** Returns {@code this} where {@code n = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code n = array/buffer[index(i, j)]} */ public IntIndexer get(long i, long j, int[] n) { return get(i, j, n, 0, n.length); } - /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract IntIndexer get(long i, long j, int[] n, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract int get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract int get(long... indices); @@ -121,19 +121,19 @@ public static IntIndexer create(final IntPointer pointer, long[] sizes, long[] s /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[index(indices)]} */ public abstract IntIndexer get(long[] indices, int[] n, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = n} */ public abstract IntIndexer put(long i, int n); - /** Returns {@code this} where {@code array/buffer[i] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = n} */ public IntIndexer put(long i, int... n) { return put(i, n, 0, n.length); } - /** Returns {@code this} where {@code array/buffer[i] = n[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = n[offset:offset + length]} */ public abstract IntIndexer put(long i, int[] n, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = n} */ public abstract IntIndexer put(long i, long j, int n); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = n} */ public IntIndexer put(long i, long j, int... n) { return put(i, j, n, 0, n.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = n[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = n[offset:offset + length]} */ public abstract IntIndexer put(long i, long j, int[] n, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = n} */ public abstract IntIndexer put(long i, long j, long k, int n); /** Returns {@code this} where {@code array/buffer[index(indices)] = n} */ public abstract IntIndexer put(long[] indices, int n); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/IntRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/IntRawIndexer.java index d5cd88e4e..fe2d58e08 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/IntRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/IntRawIndexer.java @@ -60,68 +60,74 @@ public IntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public int get(long i) { + public int getRaw(long i) { return RAW.getInt(base + checkIndex(i, size) * VALUE_BYTES); } + @Override public int get(long i) { + return getRaw(index(i)); + } @Override public IntIndexer get(long i, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = get(i * strides[0] + n); + m[offset + n] = getRaw(index(i) + n); } return this; } @Override public int get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public IntIndexer get(long i, long j, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = get(i * strides[0] + j * strides[1] + n); + m[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public int get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public int get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public IntIndexer get(long[] indices, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = get(index(indices) + n); + m[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public IntIndexer put(long i, int n) { + public IntIndexer putRaw(long i, int n) { RAW.putInt(base + checkIndex(i, size) * VALUE_BYTES, n); return this; } + @Override public IntIndexer put(long i, int n) { + return putRaw(index(i), n); + } @Override public IntIndexer put(long i, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, m[offset + n]); + putRaw(index(i) + n, m[offset + n]); } return this; } @Override public IntIndexer put(long i, long j, int n) { - put(i * strides[0] + j, n); + putRaw(index(i, j), n); return this; } @Override public IntIndexer put(long i, long j, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, m[offset + n]); + putRaw(index(i, j) + n, m[offset + n]); } return this; } @Override public IntIndexer put(long i, long j, long k, int n) { - put(i * strides[0] + j * strides[1] + k, n); + putRaw(index(i, j, k), n); return this; } @Override public IntIndexer put(long[] indices, int n) { - put(index(indices), n); + putRaw(index(indices), n); return this; } @Override public IntIndexer put(long[] indices, int[] m, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, m[offset + n]); + putRaw(index(indices) + n, m[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/LongArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/LongArrayIndexer.java index 7541edbbf..899052cca 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/LongArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/LongArrayIndexer.java @@ -52,25 +52,25 @@ public LongArrayIndexer(long[] array, long[] sizes, long[] strides) { } @Override public long get(long i) { - return array[(int)i]; + return array[(int)index(i)]; } @Override public LongIndexer get(long i, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = array[(int)i * (int)strides[0] + n]; + l[offset + n] = array[(int)index(i) + n]; } return this; } @Override public long get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j]; + return array[(int)index(i, j)]; } @Override public LongIndexer get(long i, long j, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]; + l[offset + n] = array[(int)index(i, j) + n]; } return this; } @Override public long get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]; + return array[(int)index(i, j, k)]; } @Override public long get(long... indices) { return array[(int)index(indices)]; @@ -83,27 +83,27 @@ public LongArrayIndexer(long[] array, long[] sizes, long[] strides) { } @Override public LongIndexer put(long i, long l) { - array[(int)i] = l; + array[(int)index(i)] = l; return this; } @Override public LongIndexer put(long i, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = l[offset + n]; + array[(int)index(i) + n] = l[offset + n]; } return this; } @Override public LongIndexer put(long i, long j, long l) { - array[(int)i * (int)strides[0] + (int)j] = l; + array[(int)index(i, j)] = l; return this; } @Override public LongIndexer put(long i, long j, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = l[offset + n]; + array[(int)index(i, j) + n] = l[offset + n]; } return this; } @Override public LongIndexer put(long i, long j, long k, long l) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = l; + array[(int)index(i, j, k)] = l; return this; } @Override public LongIndexer put(long[] indices, long l) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/LongBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/LongBufferIndexer.java index 82923ec35..eeab25a2d 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/LongBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/LongBufferIndexer.java @@ -55,25 +55,25 @@ public LongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { } @Override public long get(long i) { - return buffer.get((int)i); + return buffer.get((int)index(i)); } @Override public LongIndexer get(long i, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = buffer.get((int)i * (int)strides[0] + n); + l[offset + n] = buffer.get((int)index(i) + n); } return this; } @Override public long get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j); + return buffer.get((int)index(i, j)); } @Override public LongIndexer get(long i, long j, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n); + l[offset + n] = buffer.get((int)index(i, j) + n); } return this; } @Override public long get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k); + return buffer.get((int)index(i, j, k)); } @Override public long get(long... indices) { return buffer.get((int)index(indices)); @@ -86,27 +86,27 @@ public LongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { } @Override public LongIndexer put(long i, long l) { - buffer.put((int)i, l); + buffer.put((int)index(i), l); return this; } @Override public LongIndexer put(long i, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, l[offset + n]); + buffer.put((int)index(i) + n, l[offset + n]); } return this; } @Override public LongIndexer put(long i, long j, long l) { - buffer.put((int)i * (int)strides[0] + (int)j, l); + buffer.put((int)index(i, j), l); return this; } @Override public LongIndexer put(long i, long j, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, l[offset + n]); + buffer.put((int)index(i, j) + n, l[offset + n]); } return this; } @Override public LongIndexer put(long i, long j, long k, long l) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, l); + buffer.put((int)index(i, j, k), l); return this; } @Override public LongIndexer put(long[] indices, long l) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/LongIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/LongIndexer.java index 30c5a3b12..8ac57e2ea 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/LongIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/LongIndexer.java @@ -100,19 +100,19 @@ public static LongIndexer create(final LongPointer pointer, long[] sizes, long[] } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract long get(long i); - /** Returns {@code this} where {@code l = array/buffer[i]} */ + /** Returns {@code this} where {@code l = array/buffer[index(i)]} */ public LongIndexer get(long i, long[] l) { return get(i, l, 0, l.length); } - /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[index(i)]} */ public abstract LongIndexer get(long i, long[] l, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract long get(long i, long j); - /** Returns {@code this} where {@code l = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code l = array/buffer[index(i, j)]} */ public LongIndexer get(long i, long j, long[] l) { return get(i, j, l, 0, l.length); } - /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract LongIndexer get(long i, long j, long[] l, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract long get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract long get(long... indices); @@ -121,19 +121,19 @@ public static LongIndexer create(final LongPointer pointer, long[] sizes, long[] /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[index(indices)]} */ public abstract LongIndexer get(long[] indices, long[] l, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = l} */ public abstract LongIndexer put(long i, long l); - /** Returns {@code this} where {@code array/buffer[i] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = l} */ public LongIndexer put(long i, long... l) { return put(i, l, 0, l.length); } - /** Returns {@code this} where {@code array/buffer[i] = l[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = l[offset:offset + length]} */ public abstract LongIndexer put(long i, long[] l, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = l} */ public abstract LongIndexer put(long i, long j, long l); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = l} */ public LongIndexer put(long i, long j, long... l) { return put(i, j, l, 0, l.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = l[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = l[offset:offset + length]} */ public abstract LongIndexer put(long i, long j, long[] l, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = l} */ public abstract LongIndexer put(long i, long j, long k, long l); /** Returns {@code this} where {@code array/buffer[index(indices)] = l} */ public abstract LongIndexer put(long[] indices, long l); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/LongRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/LongRawIndexer.java index f87dbac60..a53daecfa 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/LongRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/LongRawIndexer.java @@ -60,68 +60,74 @@ public LongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public long get(long i) { + public long getRaw(long i) { return RAW.getLong(base + checkIndex(i, size) * VALUE_BYTES); } + @Override public long get(long i) { + return getRaw(index(i)); + } @Override public LongIndexer get(long i, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = get(i * strides[0] + n); + l[offset + n] = getRaw(index(i) + n); } return this; } @Override public long get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public LongIndexer get(long i, long j, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = get(i * strides[0] + j * strides[1] + n); + l[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public long get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public long get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public LongIndexer get(long[] indices, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = get(index(indices) + n); + l[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public LongIndexer put(long i, long l) { + public LongIndexer putRaw(long i, long l) { RAW.putLong(base + checkIndex(i, size) * VALUE_BYTES, l); return this; } + @Override public LongIndexer put(long i, long l) { + return putRaw(index(i), l); + } @Override public LongIndexer put(long i, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, l[offset + n]); + putRaw(index(i) + n, l[offset + n]); } return this; } @Override public LongIndexer put(long i, long j, long l) { - put(i * strides[0] + j, l); + putRaw(index(i, j), l); return this; } @Override public LongIndexer put(long i, long j, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, l[offset + n]); + putRaw(index(i, j) + n, l[offset + n]); } return this; } @Override public LongIndexer put(long i, long j, long k, long l) { - put(i * strides[0] + j * strides[1] + k, l); + putRaw(index(i, j, k), l); return this; } @Override public LongIndexer put(long[] indices, long l) { - put(index(indices), l); + putRaw(index(indices), l); return this; } @Override public LongIndexer put(long[] indices, long[] l, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, l[offset + n]); + putRaw(index(indices) + n, l[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ShortArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ShortArrayIndexer.java index d239fd986..32e383a84 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ShortArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ShortArrayIndexer.java @@ -52,25 +52,25 @@ public ShortArrayIndexer(short[] array, long[] sizes, long[] strides) { } @Override public short get(long i) { - return array[(int)i]; + return array[(int)index(i)]; } @Override public ShortIndexer get(long i, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = array[(int)i * (int)strides[0] + n]; + s[offset + n] = array[(int)index(i) + n]; } return this; } @Override public short get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j]; + return array[(int)index(i, j)]; } @Override public ShortIndexer get(long i, long j, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]; + s[offset + n] = array[(int)index(i, j) + n]; } return this; } @Override public short get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]; + return array[(int)index(i, j, k)]; } @Override public short get(long... indices) { return array[(int)index(indices)]; @@ -83,27 +83,27 @@ public ShortArrayIndexer(short[] array, long[] sizes, long[] strides) { } @Override public ShortIndexer put(long i, short s) { - array[(int)i] = s; + array[(int)index(i)] = s; return this; } @Override public ShortIndexer put(long i, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = s[offset + n]; + array[(int)index(i) + n] = s[offset + n]; } return this; } @Override public ShortIndexer put(long i, long j, short s) { - array[(int)i * (int)strides[0] + (int)j] = s; + array[(int)index(i, j)] = s; return this; } @Override public ShortIndexer put(long i, long j, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = s[offset + n]; + array[(int)index(i, j) + n] = s[offset + n]; } return this; } @Override public ShortIndexer put(long i, long j, long k, short s) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = s; + array[(int)index(i, j, k)] = s; return this; } @Override public ShortIndexer put(long[] indices, short s) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ShortBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ShortBufferIndexer.java index 1a62200d1..739f4752f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ShortBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ShortBufferIndexer.java @@ -55,25 +55,25 @@ public ShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { } @Override public short get(long i) { - return buffer.get((int)i); + return buffer.get((int)index(i)); } @Override public ShortIndexer get(long i, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = buffer.get((int)i * (int)strides[0] + n); + s[offset + n] = buffer.get((int)index(i) + n); } return this; } @Override public short get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j); + return buffer.get((int)index(i, j)); } @Override public ShortIndexer get(long i, long j, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n); + s[offset + n] = buffer.get((int)index(i, j) + n); } return this; } @Override public short get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k); + return buffer.get((int)index(i, j, k)); } @Override public short get(long... indices) { return buffer.get((int)index(indices)); @@ -86,27 +86,27 @@ public ShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { } @Override public ShortIndexer put(long i, short s) { - buffer.put((int)i, s); + buffer.put((int)index(i), s); return this; } @Override public ShortIndexer put(long i, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, s[offset + n]); + buffer.put((int)index(i) + n, s[offset + n]); } return this; } @Override public ShortIndexer put(long i, long j, short s) { - buffer.put((int)i * (int)strides[0] + (int)j, s); + buffer.put((int)index(i, j), s); return this; } @Override public ShortIndexer put(long i, long j, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, s[offset + n]); + buffer.put((int)index(i, j) + n, s[offset + n]); } return this; } @Override public ShortIndexer put(long i, long j, long k, short s) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, s); + buffer.put((int)index(i, j, k), s); return this; } @Override public ShortIndexer put(long[] indices, short s) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ShortIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ShortIndexer.java index a672c5e2d..b93300c4f 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ShortIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ShortIndexer.java @@ -100,19 +100,19 @@ public static ShortIndexer create(final ShortPointer pointer, long[] sizes, long } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract short get(long i); - /** Returns {@code this} where {@code s = array/buffer[i]} */ + /** Returns {@code this} where {@code s = array/buffer[index(i)]} */ public ShortIndexer get(long i, short[] s) { return get(i, s, 0, s.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[index(i)]} */ public abstract ShortIndexer get(long i, short[] s, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract short get(long i, long j); - /** Returns {@code this} where {@code s = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code s = array/buffer[index(i, j)]} */ public ShortIndexer get(long i, long j, short[] s) { return get(i, j, s, 0, s.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract ShortIndexer get(long i, long j, short[] s, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract short get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract short get(long... indices); @@ -121,19 +121,19 @@ public static ShortIndexer create(final ShortPointer pointer, long[] sizes, long /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[index(indices)]} */ public abstract ShortIndexer get(long[] indices, short[] s, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = s} */ public abstract ShortIndexer put(long i, short s); - /** Returns {@code this} where {@code array/buffer[i] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = s} */ public ShortIndexer put(long i, short... s) { return put(i, s, 0, s.length); } - /** Returns {@code this} where {@code array/buffer[i] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = s[offset:offset + length]} */ public abstract ShortIndexer put(long i, short[] s, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = s} */ public abstract ShortIndexer put(long i, long j, short s); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = s} */ public ShortIndexer put(long i, long j, short... s) { return put(i, j, s, 0, s.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = s[offset:offset + length]} */ public abstract ShortIndexer put(long i, long j, short[] s, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = s} */ public abstract ShortIndexer put(long i, long j, long k, short s); /** Returns {@code this} where {@code array/buffer[index(indices)] = s} */ public abstract ShortIndexer put(long[] indices, short s); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ShortRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ShortRawIndexer.java index 1e6fbdaeb..4e8c683e3 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ShortRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ShortRawIndexer.java @@ -60,68 +60,74 @@ public ShortRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public short get(long i) { + public short getRaw(long i) { return RAW.getShort(base + checkIndex(i, size) * VALUE_BYTES); } + @Override public short get(long i) { + return getRaw(index(i)); + } @Override public ShortIndexer get(long i, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = get(i * strides[0] + n); + s[offset + n] = getRaw(index(i) + n); } return this; } @Override public short get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public ShortIndexer get(long i, long j, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = get(i * strides[0] + j * strides[1] + n); + s[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public short get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public short get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public ShortIndexer get(long[] indices, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = get(index(indices) + n); + s[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public ShortIndexer put(long i, short s) { + public ShortIndexer putRaw(long i, short s) { RAW.putShort(base + checkIndex(i, size) * VALUE_BYTES, s); return this; } + @Override public ShortIndexer put(long i, short s) { + return putRaw(index(i), s); + } @Override public ShortIndexer put(long i, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, s[offset + n]); + putRaw(index(i) + n, s[offset + n]); } return this; } @Override public ShortIndexer put(long i, long j, short s) { - put(i * strides[0] + j, s); + putRaw(index(i, j), s); return this; } @Override public ShortIndexer put(long i, long j, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, s[offset + n]); + putRaw(index(i, j) + n, s[offset + n]); } return this; } @Override public ShortIndexer put(long i, long j, long k, short s) { - put(i * strides[0] + j * strides[1] + k, s); + putRaw(index(i, j, k), s); return this; } @Override public ShortIndexer put(long[] indices, short s) { - put(index(indices), s); + putRaw(index(indices), s); return this; } @Override public ShortIndexer put(long[] indices, short[] s, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, s[offset + n]); + putRaw(index(indices) + n, s[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UByteArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UByteArrayIndexer.java index d75d50843..8613487b5 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UByteArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UByteArrayIndexer.java @@ -52,25 +52,25 @@ public UByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { } @Override public int get(long i) { - return array[(int)i] & 0xFF; + return array[(int)index(i)] & 0xFF; } @Override public UByteIndexer get(long i, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = array[(int)i * (int)strides[0] + n] & 0xFF; + b[offset + n] = array[(int)index(i) + n] & 0xFF; } return this; } @Override public int get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j] & 0xFF; + return array[(int)index(i, j)] & 0xFF; } @Override public UByteIndexer get(long i, long j, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] & 0xFF; + b[offset + n] = array[(int)index(i, j) + n] & 0xFF; } return this; } @Override public int get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] & 0xFF; + return array[(int)index(i, j, k)] & 0xFF; } @Override public int get(long... indices) { return array[(int)index(indices)] & 0xFF; @@ -83,27 +83,27 @@ public UByteArrayIndexer(byte[] array, long[] sizes, long[] strides) { } @Override public UByteIndexer put(long i, int b) { - array[(int)i] = (byte)b; + array[(int)index(i)] = (byte)b; return this; } @Override public UByteIndexer put(long i, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = (byte)b[offset + n]; + array[(int)index(i) + n] = (byte)b[offset + n]; } return this; } @Override public UByteIndexer put(long i, long j, int b) { - array[(int)i * (int)strides[0] + (int)j] = (byte)b; + array[(int)index(i, j)] = (byte)b; return this; } @Override public UByteIndexer put(long i, long j, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = (byte)b[offset + n]; + array[(int)index(i, j) + n] = (byte)b[offset + n]; } return this; } @Override public UByteIndexer put(long i, long j, long k, int b) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = (byte)b; + array[(int)index(i, j, k)] = (byte)b; return this; } @Override public UByteIndexer put(long[] indices, int b) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UByteBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UByteBufferIndexer.java index af5933bbb..4b6e857fa 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UByteBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UByteBufferIndexer.java @@ -55,25 +55,25 @@ public UByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { } @Override public int get(long i) { - return buffer.get((int)i) & 0xFF; + return buffer.get((int)index(i)) & 0xFF; } @Override public UByteIndexer get(long i, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = buffer.get((int)i * (int)strides[0] + n) & 0xFF; + b[offset + n] = buffer.get((int)index(i) + n) & 0xFF; } return this; } @Override public int get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j) & 0xFF; + return buffer.get((int)index(i, j)) & 0xFF; } @Override public UByteIndexer get(long i, long j, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n) & 0xFF; + b[offset + n] = buffer.get((int)index(i, j) + n) & 0xFF; } return this; } @Override public int get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k) & 0xFF; + return buffer.get((int)index(i, j, k)) & 0xFF; } @Override public int get(long... indices) { return buffer.get((int)index(indices)) & 0xFF; @@ -86,27 +86,27 @@ public UByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) { } @Override public UByteIndexer put(long i, int b) { - buffer.put((int)i, (byte)b); + buffer.put((int)index(i), (byte)b); return this; } @Override public UByteIndexer put(long i, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, (byte)b[offset + n]); + buffer.put((int)index(i) + n, (byte)b[offset + n]); } return this; } @Override public UByteIndexer put(long i, long j, int b) { - buffer.put((int)i * (int)strides[0] + (int)j, (byte)b); + buffer.put((int)index(i, j), (byte)b); return this; } @Override public UByteIndexer put(long i, long j, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, (byte)b[offset + n]); + buffer.put((int)index(i, j) + n, (byte)b[offset + n]); } return this; } @Override public UByteIndexer put(long i, long j, long k, int b) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, (byte)b); + buffer.put((int)index(i, j, k), (byte)b); return this; } @Override public UByteIndexer put(long[] indices, int b) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UByteIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UByteIndexer.java index e86e4c7fc..573e9b8d8 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UByteIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UByteIndexer.java @@ -100,19 +100,19 @@ public static UByteIndexer create(final BytePointer pointer, long[] sizes, long[ } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract int get(long i); - /** Returns {@code this} where {@code b = array/buffer[i]} */ + /** Returns {@code this} where {@code b = array/buffer[index(i)]} */ public UByteIndexer get(long i, int[] b) { return get(i, b, 0, b.length); } - /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(i)]} */ public abstract UByteIndexer get(long i, int[] b, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract int get(long i, long j); - /** Returns {@code this} where {@code b = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code b = array/buffer[index(i, j)]} */ public UByteIndexer get(long i, long j, int[] b) { return get(i, j, b, 0, b.length); } - /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract UByteIndexer get(long i, long j, int[] b, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract int get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract int get(long... indices); @@ -121,19 +121,19 @@ public static UByteIndexer create(final BytePointer pointer, long[] sizes, long[ /** Returns {@code this} where {@code b[offset:offset + length] = array/buffer[index(indices)]} */ public abstract UByteIndexer get(long[] indices, int[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b} */ public abstract UByteIndexer put(long i, int b); - /** Returns {@code this} where {@code array/buffer[i] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b} */ public UByteIndexer put(long i, int... b) { return put(i, b, 0, b.length); } - /** Returns {@code this} where {@code array/buffer[i] = b[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = b[offset:offset + length]} */ public abstract UByteIndexer put(long i, int[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b} */ public abstract UByteIndexer put(long i, long j, int b); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b} */ public UByteIndexer put(long i, long j, int... b) { return put(i, j, b, 0, b.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = b[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = b[offset:offset + length]} */ public abstract UByteIndexer put(long i, long j, int[] b, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = b} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = b} */ public abstract UByteIndexer put(long i, long j, long k, int b); /** Returns {@code this} where {@code array/buffer[index(indices)] = b} */ public abstract UByteIndexer put(long[] indices, int b); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UByteRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UByteRawIndexer.java index 15f54adf0..daadaf0d3 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UByteRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UByteRawIndexer.java @@ -60,68 +60,75 @@ public UByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public int get(long i) { + public int getRaw(long i) { return RAW.getByte(base + checkIndex(i, size)) & 0xFF; } + @Override public int get(long i) { + return getRaw(index(i)); + } @Override public UByteIndexer get(long i, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(i * strides[0] + n) & 0xFF; + b[offset + n] = getRaw(index(i) + n) & 0xFF; } return this; } @Override public int get(long i, long j) { - return get(i * strides[0] + j) & 0xFF; + return getRaw(index(i, j)) & 0xFF; } @Override public UByteIndexer get(long i, long j, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(i * strides[0] + j * strides[1] + n) & 0xFF; + b[offset + n] = getRaw(index(i, j) + n) & 0xFF; } return this; } @Override public int get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k) & 0xFF; + return getRaw(index(i, j, k)) & 0xFF; } @Override public int get(long... indices) { - return get(index(indices)) & 0xFF; + return getRaw(index(indices)) & 0xFF; } @Override public UByteIndexer get(long[] indices, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - b[offset + n] = get(index(indices) + n) & 0xFF; + b[offset + n] = getRaw(index(indices) + n) & 0xFF; } return this; } + public UByteIndexer putRaw(long i, int b) { + RAW.putByte(base + checkIndex(i, size), (byte)b); + return this; + } @Override public UByteIndexer put(long i, int b) { RAW.putByte(base + checkIndex(i, size), (byte)b); return this; } @Override public UByteIndexer put(long i, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, (byte)b[offset + n]); + putRaw(index(i) + n, (byte)b[offset + n]); } return this; } @Override public UByteIndexer put(long i, long j, int b) { - put(i * strides[0] + j, (byte)b); + putRaw(index(i, j), (byte)b); return this; } @Override public UByteIndexer put(long i, long j, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, (byte)b[offset + n]); + putRaw(index(i, j) + n, (byte)b[offset + n]); } return this; } @Override public UByteIndexer put(long i, long j, long k, int b) { - put(i * strides[0] + j * strides[1] + k, (byte)b); + putRaw(index(i, j, k), (byte)b); return this; } @Override public UByteIndexer put(long[] indices, int b) { - put(index(indices), (byte)b); + putRaw(index(indices), (byte)b); return this; } @Override public UByteIndexer put(long[] indices, int[] b, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, (byte)b[offset + n]); + putRaw(index(indices) + n, (byte)b[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UIntArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UIntArrayIndexer.java index 6f5721d4c..8e3a2c906 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UIntArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UIntArrayIndexer.java @@ -52,25 +52,25 @@ public UIntArrayIndexer(int[] array, long[] sizes, long[] strides) { } @Override public long get(long i) { - return array[(int)i] & 0xFFFFFFFFL; + return array[(int)index(i)] & 0xFFFFFFFFL; } @Override public UIntIndexer get(long i, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = array[(int)i * (int)strides[0] + n] & 0xFFFFFFFFL; + m[offset + n] = array[(int)index(i) + n] & 0xFFFFFFFFL; } return this; } @Override public long get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j] & 0xFFFFFFFFL; + return array[(int)index(i, j)] & 0xFFFFFFFFL; } @Override public UIntIndexer get(long i, long j, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] & 0xFFFFFFFFL; + m[offset + n] = array[(int)index(i, j) + n] & 0xFFFFFFFFL; } return this; } @Override public long get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] & 0xFFFFFFFFL; + return array[(int)index(i, j, k)] & 0xFFFFFFFFL; } @Override public long get(long... indices) { return array[(int)index(indices)] & 0xFFFFFFFFL; @@ -83,27 +83,27 @@ public UIntArrayIndexer(int[] array, long[] sizes, long[] strides) { } @Override public UIntIndexer put(long i, long n) { - array[(int)i] = (int)n; + array[(int)index(i)] = (int)n; return this; } @Override public UIntIndexer put(long i, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = (int)m[offset + n]; + array[(int)index(i) + n] = (int)m[offset + n]; } return this; } @Override public UIntIndexer put(long i, long j, long n) { - array[(int)i * (int)strides[0] + (int)j] = (int)n; + array[(int)index(i, j)] = (int)n; return this; } @Override public UIntIndexer put(long i, long j, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = (int)m[offset + n]; + array[(int)index(i, j) + n] = (int)m[offset + n]; } return this; } @Override public UIntIndexer put(long i, long j, long k, long n) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = (int)n; + array[(int)index(i, j, k)] = (int)n; return this; } @Override public UIntIndexer put(long[] indices, long n) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UIntBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UIntBufferIndexer.java index 134d34671..b6497a2df 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UIntBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UIntBufferIndexer.java @@ -55,25 +55,25 @@ public UIntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { } @Override public long get(long i) { - return buffer.get((int)i) & 0xFFFFFFFFL; + return buffer.get((int)index(i)) & 0xFFFFFFFFL; } @Override public UIntIndexer get(long i, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = buffer.get((int)i * (int)strides[0] + n) & 0xFFFFFFFFL; + m[offset + n] = buffer.get((int)index(i) + n) & 0xFFFFFFFFL; } return this; } @Override public long get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j) & 0xFFFFFFFFL; + return buffer.get((int)index(i, j)) & 0xFFFFFFFFL; } @Override public UIntIndexer get(long i, long j, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n) & 0xFFFFFFFFL; + m[offset + n] = buffer.get((int)index(i, j) + n) & 0xFFFFFFFFL; } return this; } @Override public long get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k) & 0xFFFFFFFFL; + return buffer.get((int)index(i, j, k)) & 0xFFFFFFFFL; } @Override public long get(long... indices) { return buffer.get((int)index(indices)) & 0xFFFFFFFFL; @@ -86,27 +86,27 @@ public UIntBufferIndexer(IntBuffer buffer, long[] sizes, long[] strides) { } @Override public UIntIndexer put(long i, long n) { - buffer.put((int)i, (int)n); + buffer.put((int)index(i), (int)n); return this; } @Override public UIntIndexer put(long i, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, (int)m[offset + n]); + buffer.put((int)index(i) + n, (int)m[offset + n]); } return this; } @Override public UIntIndexer put(long i, long j, long n) { - buffer.put((int)i * (int)strides[0] + (int)j, (int)n); + buffer.put((int)index(i, j), (int)n); return this; } @Override public UIntIndexer put(long i, long j, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, (int)m[offset + n]); + buffer.put((int)index(i, j) + n, (int)m[offset + n]); } return this; } @Override public UIntIndexer put(long i, long j, long k, long n) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, (int)n); + buffer.put((int)index(i, j, k), (int)n); return this; } @Override public UIntIndexer put(long[] indices, long n) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UIntIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UIntIndexer.java index 59001f25a..e93b610c7 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UIntIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UIntIndexer.java @@ -100,19 +100,19 @@ public static UIntIndexer create(final IntPointer pointer, long[] sizes, long[] } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract long get(long i); - /** Returns {@code this} where {@code n = array/buffer[i]} */ + /** Returns {@code this} where {@code n = array/buffer[index(i)]} */ public UIntIndexer get(long i, long[] n) { return get(i, n, 0, n.length); } - /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[index(i)]} */ public abstract UIntIndexer get(long i, long[] n, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract long get(long i, long j); - /** Returns {@code this} where {@code n = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code n = array/buffer[index(i, j)]} */ public UIntIndexer get(long i, long j, long[] n) { return get(i, j, n, 0, n.length); } - /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract UIntIndexer get(long i, long j, long[] n, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract long get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract long get(long... indices); @@ -121,19 +121,19 @@ public static UIntIndexer create(final IntPointer pointer, long[] sizes, long[] /** Returns {@code this} where {@code n[offset:offset + length] = array/buffer[index(indices)]} */ public abstract UIntIndexer get(long[] indices, long[] n, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = n} */ public abstract UIntIndexer put(long i, long n); - /** Returns {@code this} where {@code array/buffer[i] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = n} */ public UIntIndexer put(long i, long... n) { return put(i, n, 0, n.length); } - /** Returns {@code this} where {@code array/buffer[i] = n[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = n[offset:offset + length]} */ public abstract UIntIndexer put(long i, long[] n, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = n} */ public abstract UIntIndexer put(long i, long j, long n); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = n} */ public UIntIndexer put(long i, long j, long... n) { return put(i, j, n, 0, n.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = n[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = n[offset:offset + length]} */ public abstract UIntIndexer put(long i, long j, long[] n, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = n} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = n} */ public abstract UIntIndexer put(long i, long j, long k, long n); /** Returns {@code this} where {@code array/buffer[index(indices)] = n} */ public abstract UIntIndexer put(long[] indices, long n); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UIntRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UIntRawIndexer.java index d07e530cd..cff6325f0 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UIntRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UIntRawIndexer.java @@ -60,68 +60,74 @@ public UIntRawIndexer(IntPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public long get(long i) { + public long getRaw(long i) { return RAW.getInt(base + checkIndex(i, size) * VALUE_BYTES) & 0xFFFFFFFFL; } + @Override public long get(long i) { + return getRaw(index(i)); + } @Override public UIntIndexer get(long i, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = get(i * strides[0] + n) & 0xFFFFFFFFL; + m[offset + n] = getRaw(index(i) + n) & 0xFFFFFFFFL; } return this; } @Override public long get(long i, long j) { - return get(i * strides[0] + j) & 0xFFFFFFFFL; + return getRaw(index(i, j)) & 0xFFFFFFFFL; } @Override public UIntIndexer get(long i, long j, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = get(i * strides[0] + j * strides[1] + n) & 0xFFFFFFFFL; + m[offset + n] = getRaw(index(i, j) + n) & 0xFFFFFFFFL; } return this; } @Override public long get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k) & 0xFFFFFFFFL; + return getRaw(index(i, j, k)) & 0xFFFFFFFFL; } @Override public long get(long... indices) { - return get(index(indices)) & 0xFFFFFFFFL; + return getRaw(index(indices)) & 0xFFFFFFFFL; } @Override public UIntIndexer get(long[] indices, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - m[offset + n] = get(index(indices) + n) & 0xFFFFFFFFL; + m[offset + n] = getRaw(index(indices) + n) & 0xFFFFFFFFL; } return this; } - @Override public UIntIndexer put(long i, long n) { + public UIntIndexer putRaw(long i, long n) { RAW.putInt(base + checkIndex(i, size) * VALUE_BYTES, (int)n); return this; } + @Override public UIntIndexer put(long i, long n) { + return putRaw(index(i), n); + } @Override public UIntIndexer put(long i, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, (int)m[offset + n]); + putRaw(index(i) + n, (int)m[offset + n]); } return this; } @Override public UIntIndexer put(long i, long j, long n) { - put(i * strides[0] + j, (int)n); + putRaw(index(i, j), (int)n); return this; } @Override public UIntIndexer put(long i, long j, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, (int)m[offset + n]); + putRaw(index(i, j) + n, (int)m[offset + n]); } return this; } @Override public UIntIndexer put(long i, long j, long k, long n) { - put(i * strides[0] + j * strides[1] + k, (int)n); + putRaw(index(i, j, k), (int)n); return this; } @Override public UIntIndexer put(long[] indices, long n) { - put(index(indices), (int)n); + putRaw(index(indices), (int)n); return this; } @Override public UIntIndexer put(long[] indices, long[] m, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, (int)m[offset + n]); + putRaw(index(indices) + n, (int)m[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ULongArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ULongArrayIndexer.java index bd070cdf1..59e8cc45d 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ULongArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ULongArrayIndexer.java @@ -54,25 +54,25 @@ public ULongArrayIndexer(long[] array, long[] sizes, long[] strides) { } @Override public BigInteger get(long i) { - return toBigInteger(array[(int)i]); + return toBigInteger(array[(int)index(i)]); } @Override public ULongIndexer get(long i, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = toBigInteger(array[(int)i * (int)strides[0] + n]); + l[offset + n] = toBigInteger(array[(int)index(i) + n]); } return this; } @Override public BigInteger get(long i, long j) { - return toBigInteger(array[(int)i * (int)strides[0] + (int)j]); + return toBigInteger(array[(int)index(i, j)]); } @Override public ULongIndexer get(long i, long j, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = toBigInteger(array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n]); + l[offset + n] = toBigInteger(array[(int)index(i, j) + n]); } return this; } @Override public BigInteger get(long i, long j, long k) { - return toBigInteger(array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k]); + return toBigInteger(array[(int)index(i, j, k)]); } @Override public BigInteger get(long... indices) { return toBigInteger(array[(int)index(indices)]); @@ -85,27 +85,27 @@ public ULongArrayIndexer(long[] array, long[] sizes, long[] strides) { } @Override public ULongIndexer put(long i, BigInteger l) { - array[(int)i] = fromBigInteger(l); + array[(int)index(i)] = fromBigInteger(l); return this; } @Override public ULongIndexer put(long i, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = fromBigInteger(l[offset + n]); + array[(int)index(i) + n] = fromBigInteger(l[offset + n]); } return this; } @Override public ULongIndexer put(long i, long j, BigInteger l) { - array[(int)i * (int)strides[0] + (int)j] = fromBigInteger(l); + array[(int)index(i, j)] = fromBigInteger(l); return this; } @Override public ULongIndexer put(long i, long j, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = fromBigInteger(l[offset + n]); + array[(int)index(i, j) + n] = fromBigInteger(l[offset + n]); } return this; } @Override public ULongIndexer put(long i, long j, long k, BigInteger l) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = fromBigInteger(l); + array[(int)index(i, j, k)] = fromBigInteger(l); return this; } @Override public ULongIndexer put(long[] indices, BigInteger l) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ULongBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ULongBufferIndexer.java index 3e6fbd1b6..19dc0adb6 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ULongBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ULongBufferIndexer.java @@ -56,25 +56,25 @@ public ULongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { } @Override public BigInteger get(long i) { - return toBigInteger(buffer.get((int)i)); + return toBigInteger(buffer.get((int)index(i))); } @Override public ULongIndexer get(long i, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = toBigInteger(buffer.get((int)i * (int)strides[0] + n)); + l[offset + n] = toBigInteger(buffer.get((int)index(i) + n)); } return this; } @Override public BigInteger get(long i, long j) { - return toBigInteger(buffer.get((int)i * (int)strides[0] + (int)j)); + return toBigInteger(buffer.get((int)index(i, j))); } @Override public ULongIndexer get(long i, long j, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = toBigInteger(buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n)); + l[offset + n] = toBigInteger(buffer.get((int)index(i, j) + n)); } return this; } @Override public BigInteger get(long i, long j, long k) { - return toBigInteger(buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k)); + return toBigInteger(buffer.get((int)index(i, j, k))); } @Override public BigInteger get(long... indices) { return toBigInteger(buffer.get((int)index(indices))); @@ -87,27 +87,27 @@ public ULongBufferIndexer(LongBuffer buffer, long[] sizes, long[] strides) { } @Override public ULongIndexer put(long i, BigInteger l) { - buffer.put((int)i, fromBigInteger(l)); + buffer.put((int)index(i), fromBigInteger(l)); return this; } @Override public ULongIndexer put(long i, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, fromBigInteger(l[offset + n])); + buffer.put((int)index(i) + n, fromBigInteger(l[offset + n])); } return this; } @Override public ULongIndexer put(long i, long j, BigInteger l) { - buffer.put((int)i * (int)strides[0] + (int)j, fromBigInteger(l)); + buffer.put((int)index(i, j), fromBigInteger(l)); return this; } @Override public ULongIndexer put(long i, long j, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, fromBigInteger(l[offset + n])); + buffer.put((int)index(i, j) + n, fromBigInteger(l[offset + n])); } return this; } @Override public ULongIndexer put(long i, long j, long k, BigInteger l) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, fromBigInteger(l)); + buffer.put((int)index(i, j, k), fromBigInteger(l)); return this; } @Override public ULongIndexer put(long[] indices, BigInteger l) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ULongIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ULongIndexer.java index 7554c11aa..49faa49e3 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ULongIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ULongIndexer.java @@ -114,19 +114,19 @@ public static long fromBigInteger(BigInteger l) { return l.longValue(); } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract BigInteger get(long i); - /** Returns {@code this} where {@code l = array/buffer[i]} */ + /** Returns {@code this} where {@code l = array/buffer[index(i)]} */ public ULongIndexer get(long i, BigInteger[] l) { return get(i, l, 0, l.length); } - /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[index(i)]} */ public abstract ULongIndexer get(long i, BigInteger[] l, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract BigInteger get(long i, long j); - /** Returns {@code this} where {@code l = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code l = array/buffer[index(i, j)]} */ public ULongIndexer get(long i, long j, BigInteger[] l) { return get(i, j, l, 0, l.length); } - /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract ULongIndexer get(long i, long j, BigInteger[] l, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract BigInteger get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract BigInteger get(long... indices); @@ -135,19 +135,19 @@ public static long fromBigInteger(BigInteger l) { /** Returns {@code this} where {@code l[offset:offset + length] = array/buffer[index(indices)]} */ public abstract ULongIndexer get(long[] indices, BigInteger[] l, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = l} */ public abstract ULongIndexer put(long i, BigInteger l); - /** Returns {@code this} where {@code array/buffer[i] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = l} */ public ULongIndexer put(long i, BigInteger... l) { return put(i, l, 0, l.length); } - /** Returns {@code this} where {@code array/buffer[i] = l[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = l[offset:offset + length]} */ public abstract ULongIndexer put(long i, BigInteger[] l, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = l} */ public abstract ULongIndexer put(long i, long j, BigInteger l); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = l} */ public ULongIndexer put(long i, long j, BigInteger... l) { return put(i, j, l, 0, l.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = l[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = l[offset:offset + length]} */ public abstract ULongIndexer put(long i, long j, BigInteger[] l, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = l} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = l} */ public abstract ULongIndexer put(long i, long j, long k, BigInteger l); /** Returns {@code this} where {@code array/buffer[index(indices)] = l} */ public abstract ULongIndexer put(long[] indices, BigInteger l); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/ULongRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/ULongRawIndexer.java index 67872881b..22323c2da 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/ULongRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/ULongRawIndexer.java @@ -61,68 +61,74 @@ public ULongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public BigInteger get(long i) { + public BigInteger getRaw(long i) { return toBigInteger(RAW.getLong(base + checkIndex(i, size) * VALUE_BYTES)); } + @Override public BigInteger get(long i) { + return getRaw(index(i)); + } @Override public ULongIndexer get(long i, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = get(i * strides[0] + n); + l[offset + n] = getRaw(index(i) + n); } return this; } @Override public BigInteger get(long i, long j) { - return get(i * strides[0] + j); + return getRaw(index(i, j)); } @Override public ULongIndexer get(long i, long j, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = get(i * strides[0] + j * strides[1] + n); + l[offset + n] = getRaw(index(i, j) + n); } return this; } @Override public BigInteger get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k); + return getRaw(index(i, j, k)); } @Override public BigInteger get(long... indices) { - return get(index(indices)); + return getRaw(index(indices)); } @Override public ULongIndexer get(long[] indices, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - l[offset + n] = get(index(indices) + n); + l[offset + n] = getRaw(index(indices) + n); } return this; } - @Override public ULongIndexer put(long i, BigInteger l) { + public ULongIndexer putRaw(long i, BigInteger l) { RAW.putLong(base + checkIndex(i, size) * VALUE_BYTES, fromBigInteger(l)); return this; } + @Override public ULongIndexer put(long i, BigInteger l) { + return putRaw(index(i), l); + } @Override public ULongIndexer put(long i, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, l[offset + n]); + putRaw(index(i) + n, l[offset + n]); } return this; } @Override public ULongIndexer put(long i, long j, BigInteger l) { - put(i * strides[0] + j, l); + putRaw(index(i, j), l); return this; } @Override public ULongIndexer put(long i, long j, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, l[offset + n]); + putRaw(index(i, j) + n, l[offset + n]); } return this; } @Override public ULongIndexer put(long i, long j, long k, BigInteger l) { - put(i * strides[0] + j * strides[1] + k, l); + putRaw(index(i, j, k), l); return this; } @Override public ULongIndexer put(long[] indices, BigInteger l) { - put(index(indices), l); + putRaw(index(indices), l); return this; } @Override public ULongIndexer put(long[] indices, BigInteger[] l, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, l[offset + n]); + putRaw(index(indices) + n, l[offset + n]); } return this; } diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UShortArrayIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UShortArrayIndexer.java index 0b6080055..e6743c3e8 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UShortArrayIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UShortArrayIndexer.java @@ -52,25 +52,25 @@ public UShortArrayIndexer(short[] array, long[] sizes, long[] strides) { } @Override public int get(long i) { - return array[(int)i] & 0xFFFF; + return array[(int)index(i)] & 0xFFFF; } @Override public UShortIndexer get(long i, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = array[(int)i * (int)strides[0] + n] & 0xFFFF; + s[offset + n] = array[(int)index(i) + n] & 0xFFFF; } return this; } @Override public int get(long i, long j) { - return array[(int)i * (int)strides[0] + (int)j] & 0xFFFF; + return array[(int)index(i, j)] & 0xFFFF; } @Override public UShortIndexer get(long i, long j, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] & 0xFFFF; + s[offset + n] = array[(int)index(i, j) + n] & 0xFFFF; } return this; } @Override public int get(long i, long j, long k) { - return array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] & 0xFFFF; + return array[(int)index(i, j, k)] & 0xFFFF; } @Override public int get(long... indices) { return array[(int)index(indices)] & 0xFFFF; @@ -83,27 +83,27 @@ public UShortArrayIndexer(short[] array, long[] sizes, long[] strides) { } @Override public UShortIndexer put(long i, int s) { - array[(int)i] = (short)s; + array[(int)index(i)] = (short)s; return this; } @Override public UShortIndexer put(long i, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + n] = (short)s[offset + n]; + array[(int)index(i) + n] = (short)s[offset + n]; } return this; } @Override public UShortIndexer put(long i, long j, int s) { - array[(int)i * (int)strides[0] + (int)j] = (short)s; + array[(int)index(i, j)] = (short)s; return this; } @Override public UShortIndexer put(long i, long j, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + n] = (short)s[offset + n]; + array[(int)index(i, j) + n] = (short)s[offset + n]; } return this; } @Override public UShortIndexer put(long i, long j, long k, int s) { - array[(int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k] = (short)s; + array[(int)index(i, j, k)] = (short)s; return this; } @Override public UShortIndexer put(long[] indices, int s) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UShortBufferIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UShortBufferIndexer.java index fedd8cc02..100e6dabb 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UShortBufferIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UShortBufferIndexer.java @@ -55,25 +55,25 @@ public UShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { } @Override public int get(long i) { - return buffer.get((int)i) & 0xFFFF; + return buffer.get((int)index(i)) & 0xFFFF; } @Override public UShortIndexer get(long i, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = buffer.get((int)i * (int)strides[0] + n) & 0xFFFF; + s[offset + n] = buffer.get((int)index(i) + n) & 0xFFFF; } return this; } @Override public int get(long i, long j) { - return buffer.get((int)i * (int)strides[0] + (int)j) & 0xFFFF; + return buffer.get((int)index(i, j)) & 0xFFFF; } @Override public UShortIndexer get(long i, long j, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + n) & 0xFFFF; + s[offset + n] = buffer.get((int)index(i, j) + n) & 0xFFFF; } return this; } @Override public int get(long i, long j, long k) { - return buffer.get((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k) & 0xFFFF; + return buffer.get((int)index(i, j, k)) & 0xFFFF; } @Override public int get(long... indices) { return buffer.get((int)index(indices)) & 0xFFFF; @@ -86,27 +86,27 @@ public UShortBufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) { } @Override public UShortIndexer put(long i, int s) { - buffer.put((int)i, (short)s); + buffer.put((int)index(i), (short)s); return this; } @Override public UShortIndexer put(long i, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + n, (short)s[offset + n]); + buffer.put((int)index(i) + n, (short)s[offset + n]); } return this; } @Override public UShortIndexer put(long i, long j, int s) { - buffer.put((int)i * (int)strides[0] + (int)j, (short)s); + buffer.put((int)index(i, j), (short)s); return this; } @Override public UShortIndexer put(long i, long j, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + n, (short)s[offset + n]); + buffer.put((int)index(i, j) + n, (short)s[offset + n]); } return this; } @Override public UShortIndexer put(long i, long j, long k, int s) { - buffer.put((int)i * (int)strides[0] + (int)j * (int)strides[1] + (int)k, (short)s); + buffer.put((int)index(i, j, k), (short)s); return this; } @Override public UShortIndexer put(long[] indices, int s) { diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UShortIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UShortIndexer.java index 7edabe701..c7fcbee62 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UShortIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UShortIndexer.java @@ -100,19 +100,19 @@ public static UShortIndexer create(final ShortPointer pointer, long[] sizes, lon } } - /** Returns {@code array/buffer[i]} */ + /** Returns {@code array/buffer[index(i)]} */ public abstract int get(long i); - /** Returns {@code this} where {@code s = array/buffer[i]} */ + /** Returns {@code this} where {@code s = array/buffer[index(i)]} */ public UShortIndexer get(long i, int[] s) { return get(i, s, 0, s.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[i]} */ + /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[index(i)]} */ public abstract UShortIndexer get(long i, int[] s, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j]} */ + /** Returns {@code array/buffer[index(i, j)]} */ public abstract int get(long i, long j); - /** Returns {@code this} where {@code s = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code s = array/buffer[index(i, j)]} */ public UShortIndexer get(long i, long j, int[] s) { return get(i, j, s, 0, s.length); } - /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[i * strides[0] + j]} */ + /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[index(i, j)]} */ public abstract UShortIndexer get(long i, long j, int[] s, int offset, int length); - /** Returns {@code array/buffer[i * strides[0] + j * strides[1] + k]} */ + /** Returns {@code array/buffer[index(i, j, k)]} */ public abstract int get(long i, long j, long k); /** Returns {@code array/buffer[index(indices)]} */ public abstract int get(long... indices); @@ -121,19 +121,19 @@ public static UShortIndexer create(final ShortPointer pointer, long[] sizes, lon /** Returns {@code this} where {@code s[offset:offset + length] = array/buffer[index(indices)]} */ public abstract UShortIndexer get(long[] indices, int[] s, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = s} */ public abstract UShortIndexer put(long i, int s); - /** Returns {@code this} where {@code array/buffer[i] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = s} */ public UShortIndexer put(long i, int... s) { return put(i, s, 0, s.length); } - /** Returns {@code this} where {@code array/buffer[i] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i)] = s[offset:offset + length]} */ public abstract UShortIndexer put(long i, int[] s, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = s} */ public abstract UShortIndexer put(long i, long j, int s); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = s} */ public UShortIndexer put(long i, long j, int... s) { return put(i, j, s, 0, s.length); } - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j] = s[offset:offset + length]} */ + /** Returns {@code this} where {@code array/buffer[index(i, j)] = s[offset:offset + length]} */ public abstract UShortIndexer put(long i, long j, int[] s, int offset, int length); - /** Returns {@code this} where {@code array/buffer[i * strides[0] + j * strides[1] + k] = s} */ + /** Returns {@code this} where {@code array/buffer[index(i, j, k)] = s} */ public abstract UShortIndexer put(long i, long j, long k, int s); /** Returns {@code this} where {@code array/buffer[index(indices)] = s} */ public abstract UShortIndexer put(long[] indices, int s); diff --git a/src/main/java/org/bytedeco/javacpp/indexer/UShortRawIndexer.java b/src/main/java/org/bytedeco/javacpp/indexer/UShortRawIndexer.java index fe04ccef4..151353fdc 100644 --- a/src/main/java/org/bytedeco/javacpp/indexer/UShortRawIndexer.java +++ b/src/main/java/org/bytedeco/javacpp/indexer/UShortRawIndexer.java @@ -60,68 +60,74 @@ public UShortRawIndexer(ShortPointer pointer, long[] sizes, long[] strides) { return pointer; } - @Override public int get(long i) { + public int getRaw(long i) { return RAW.getShort(base + checkIndex(i, size) * VALUE_BYTES) & 0xFFFF; } + @Override public int get(long i) { + return getRaw(index(i)); + } @Override public UShortIndexer get(long i, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = get(i * strides[0] + n) & 0xFFFF; + s[offset + n] = getRaw(index(i) + n) & 0xFFFF; } return this; } @Override public int get(long i, long j) { - return get(i * strides[0] + j) & 0xFFFF; + return getRaw(index(i, j)) & 0xFFFF; } @Override public UShortIndexer get(long i, long j, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = get(i * strides[0] + j * strides[1] + n) & 0xFFFF; + s[offset + n] = getRaw(index(i, j) + n) & 0xFFFF; } return this; } @Override public int get(long i, long j, long k) { - return get(i * strides[0] + j * strides[1] + k) & 0xFFFF; + return getRaw(index(i, j, k)) & 0xFFFF; } @Override public int get(long... indices) { - return get(index(indices)) & 0xFFFF; + return getRaw(index(indices)) & 0xFFFF; } @Override public UShortIndexer get(long[] indices, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - s[offset + n] = get(index(indices) + n) & 0xFFFF; + s[offset + n] = getRaw(index(indices) + n) & 0xFFFF; } return this; } - @Override public UShortIndexer put(long i, int s) { + public UShortIndexer putRaw(long i, int s) { RAW.putShort(base + checkIndex(i, size) * VALUE_BYTES, (short)s); return this; } + @Override public UShortIndexer put(long i, int s) { + return putRaw(index(i), s); + } @Override public UShortIndexer put(long i, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + n, (short)s[offset + n]); + putRaw(index(i) + n, (short)s[offset + n]); } return this; } @Override public UShortIndexer put(long i, long j, int s) { - put(i * strides[0] + j, (short)s); + putRaw(index(i, j), (short)s); return this; } @Override public UShortIndexer put(long i, long j, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - put(i * strides[0] + j * strides[1] + n, (short)s[offset + n]); + putRaw(index(i, j) + n, (short)s[offset + n]); } return this; } @Override public UShortIndexer put(long i, long j, long k, int s) { - put(i * strides[0] + j * strides[1] + k, (short)s); + putRaw(index(i, j, k), (short)s); return this; } @Override public UShortIndexer put(long[] indices, int s) { - put(index(indices), (short)s); + putRaw(index(indices), (short)s); return this; } @Override public UShortIndexer put(long[] indices, int[] s, int offset, int length) { for (int n = 0; n < length; n++) { - put(index(indices) + n, (short)s[offset + n]); + putRaw(index(indices) + n, (short)s[offset + n]); } return this; } diff --git a/src/test/java/org/bytedeco/javacpp/IndexerTest.java b/src/test/java/org/bytedeco/javacpp/IndexerTest.java index 211ba21cf..038701d47 100644 --- a/src/test/java/org/bytedeco/javacpp/IndexerTest.java +++ b/src/test/java/org/bytedeco/javacpp/IndexerTest.java @@ -125,16 +125,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0]) & 0xFF); - assertEquals(n, directIndexer.get(i * strides[0]) & 0xFF); + assertEquals(n, arrayIndexer.get(i) & 0xFF); + assertEquals(n, directIndexer.get(i) & 0xFF); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1]) & 0xFF); - assertEquals(n, directIndexer.get(i, j * strides[1]) & 0xFF); + assertEquals(n, arrayIndexer.get(i, j) & 0xFF); + assertEquals(n, directIndexer.get(i, j) & 0xFF); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2]) & 0xFF); - assertEquals(n, directIndexer.get(i, j, k * strides[2]) & 0xFF); + assertEquals(n, arrayIndexer.get(i, j, k) & 0xFF); + assertEquals(n, directIndexer.get(i, j, k) & 0xFF); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index) & 0xFF); assertEquals(n, directIndexer.get(index) & 0xFF); arrayIndexer.put(index, (byte)(n + 1)); @@ -243,16 +243,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0])); - assertEquals(n, directIndexer.get(i * strides[0])); + assertEquals(n, arrayIndexer.get(i)); + assertEquals(n, directIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1])); - assertEquals(n, directIndexer.get(i, j * strides[1])); + assertEquals(n, arrayIndexer.get(i, j)); + assertEquals(n, directIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n, directIndexer.get(i, j, k * strides[2])); + assertEquals(n, arrayIndexer.get(i, j, k)); + assertEquals(n, directIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index)); assertEquals(n, directIndexer.get(index)); arrayIndexer.put(index, (short)(2 * n)); @@ -317,16 +317,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0])); - assertEquals(n, directIndexer.get(i * strides[0])); + assertEquals(n, arrayIndexer.get(i)); + assertEquals(n, directIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1])); - assertEquals(n, directIndexer.get(i, j * strides[1])); + assertEquals(n, arrayIndexer.get(i, j)); + assertEquals(n, directIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n, directIndexer.get(i, j, k * strides[2])); + assertEquals(n, arrayIndexer.get(i, j, k)); + assertEquals(n, directIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index)); assertEquals(n, directIndexer.get(index)); arrayIndexer.put(index, (int)(2 * n)); @@ -391,16 +391,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0])); - assertEquals(n, directIndexer.get(i * strides[0])); + assertEquals(n, arrayIndexer.get(i)); + assertEquals(n, directIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1])); - assertEquals(n, directIndexer.get(i, j * strides[1])); + assertEquals(n, arrayIndexer.get(i, j)); + assertEquals(n, directIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n, directIndexer.get(i, j, k * strides[2])); + assertEquals(n, arrayIndexer.get(i, j, k)); + assertEquals(n, directIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index)); assertEquals(n, directIndexer.get(index)); arrayIndexer.put(index, (long)(2 * n)); @@ -465,16 +465,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0]), 0); - assertEquals(n, directIndexer.get(i * strides[0]), 0); + assertEquals(n, arrayIndexer.get(i), 0); + assertEquals(n, directIndexer.get(i), 0); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1]), 0); - assertEquals(n, directIndexer.get(i, j * strides[1]), 0); + assertEquals(n, arrayIndexer.get(i, j), 0); + assertEquals(n, directIndexer.get(i, j), 0); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2]), 0); - assertEquals(n, directIndexer.get(i, j, k * strides[2]), 0); + assertEquals(n, arrayIndexer.get(i, j, k), 0); + assertEquals(n, directIndexer.get(i, j, k), 0); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index), 0); assertEquals(n, directIndexer.get(index), 0); arrayIndexer.put(index, (float)(2 * n)); @@ -539,16 +539,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0]), 0); - assertEquals(n, directIndexer.get(i * strides[0]), 0); + assertEquals(n, arrayIndexer.get(i), 0); + assertEquals(n, directIndexer.get(i), 0); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1]), 0); - assertEquals(n, directIndexer.get(i, j * strides[1]), 0); + assertEquals(n, arrayIndexer.get(i, j), 0); + assertEquals(n, directIndexer.get(i, j), 0); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2]), 0); - assertEquals(n, directIndexer.get(i, j, k * strides[2]), 0); + assertEquals(n, arrayIndexer.get(i, j, k), 0); + assertEquals(n, directIndexer.get(i, j, k), 0); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index), 0); assertEquals(n, directIndexer.get(index), 0); arrayIndexer.put(index, (double)(2 * n)); @@ -613,16 +613,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0])); - assertEquals(n, directIndexer.get(i * strides[0])); + assertEquals(n, arrayIndexer.get(i)); + assertEquals(n, directIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1])); - assertEquals(n, directIndexer.get(i, j * strides[1])); + assertEquals(n, arrayIndexer.get(i, j)); + assertEquals(n, directIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n, directIndexer.get(i, j, k * strides[2])); + assertEquals(n, arrayIndexer.get(i, j, k)); + assertEquals(n, directIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index)); assertEquals(n, directIndexer.get(index)); arrayIndexer.put(index, (char)(2 * n)); @@ -688,19 +688,19 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n % 2 != 0, arrayIndexer.get(i * strides[0])); - assertEquals(n % 2 != 0, directIndexer.get(i * strides[0])); - assertEquals(n % 2 != 0 ? 1 : 0, byteIndexer.get(i * strides[0])); + assertEquals(n % 2 != 0, arrayIndexer.get(i)); + assertEquals(n % 2 != 0, directIndexer.get(i)); + assertEquals(n % 2 != 0 ? 1 : 0, byteIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n % 2 != 0, arrayIndexer.get(i, j * strides[1])); - assertEquals(n % 2 != 0, directIndexer.get(i, j * strides[1])); - assertEquals(n % 2 != 0 ? 1 : 0, byteIndexer.get(i, j * strides[1])); + assertEquals(n % 2 != 0, arrayIndexer.get(i, j)); + assertEquals(n % 2 != 0, directIndexer.get(i, j)); + assertEquals(n % 2 != 0 ? 1 : 0, byteIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n % 2 != 0, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n % 2 != 0, directIndexer.get(i, j, k * strides[2])); - assertEquals(n % 2 != 0 ? 1 : 0, byteIndexer.get(i, j, k * strides[2])); + assertEquals(n % 2 != 0, arrayIndexer.get(i, j, k)); + assertEquals(n % 2 != 0, directIndexer.get(i, j, k)); + assertEquals(n % 2 != 0 ? 1 : 0, byteIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n % 2 != 0, arrayIndexer.get(index)); assertEquals(n % 2 != 0, directIndexer.get(index)); assertEquals(n % 2 != 0 ? 1 : 0, byteIndexer.get(index)); @@ -767,16 +767,16 @@ public void release() { } int n = start; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0])); - assertEquals(n, directIndexer.get(i * strides[0])); + assertEquals(n, arrayIndexer.get(i)); + assertEquals(n, directIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1])); - assertEquals(n, directIndexer.get(i, j * strides[1])); + assertEquals(n, arrayIndexer.get(i, j)); + assertEquals(n, directIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n, directIndexer.get(i, j, k * strides[2])); + assertEquals(n, arrayIndexer.get(i, j, k)); + assertEquals(n, directIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index)); assertEquals(n, directIndexer.get(index)); arrayIndexer.put(index, n + 1); @@ -842,16 +842,16 @@ public void release() { } int n = start; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0])); - assertEquals(n, directIndexer.get(i * strides[0])); + assertEquals(n, arrayIndexer.get(i)); + assertEquals(n, directIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1])); - assertEquals(n, directIndexer.get(i, j * strides[1])); + assertEquals(n, arrayIndexer.get(i, j)); + assertEquals(n, directIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n, directIndexer.get(i, j, k * strides[2])); + assertEquals(n, arrayIndexer.get(i, j, k)); + assertEquals(n, directIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index)); assertEquals(n, directIndexer.get(index)); arrayIndexer.put(index, 2 * n); @@ -917,16 +917,16 @@ public void release() { } long n = start; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0])); - assertEquals(n, directIndexer.get(i * strides[0])); + assertEquals(n, arrayIndexer.get(i)); + assertEquals(n, directIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1])); - assertEquals(n, directIndexer.get(i, j * strides[1])); + assertEquals(n, arrayIndexer.get(i, j)); + assertEquals(n, directIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n, directIndexer.get(i, j, k * strides[2])); + assertEquals(n, arrayIndexer.get(i, j, k)); + assertEquals(n, directIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index)); assertEquals(n, directIndexer.get(index)); arrayIndexer.put(index, 2 * n); @@ -992,16 +992,16 @@ public void release() { } BigInteger n = BigInteger.valueOf(start); for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0])); - assertEquals(n, directIndexer.get(i * strides[0])); + assertEquals(n, arrayIndexer.get(i)); + assertEquals(n, directIndexer.get(i)); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1])); - assertEquals(n, directIndexer.get(i, j * strides[1])); + assertEquals(n, arrayIndexer.get(i, j)); + assertEquals(n, directIndexer.get(i, j)); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2])); - assertEquals(n, directIndexer.get(i, j, k * strides[2])); + assertEquals(n, arrayIndexer.get(i, j, k)); + assertEquals(n, directIndexer.get(i, j, k)); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index)); assertEquals(n, directIndexer.get(index)); arrayIndexer.put(index, BigInteger.valueOf(2).multiply(n)); @@ -1080,16 +1080,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0]), 0); - assertEquals(n, directIndexer.get(i * strides[0]), 0); + assertEquals(n, arrayIndexer.get(i), 0); + assertEquals(n, directIndexer.get(i), 0); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1]), 0); - assertEquals(n, directIndexer.get(i, j * strides[1]), 0); + assertEquals(n, arrayIndexer.get(i, j), 0); + assertEquals(n, directIndexer.get(i, j), 0); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2]), 0); - assertEquals(n, directIndexer.get(i, j, k * strides[2]), 0); + assertEquals(n, arrayIndexer.get(i, j, k), 0); + assertEquals(n, directIndexer.get(i, j, k), 0); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index), 0); assertEquals(n, directIndexer.get(index), 0); arrayIndexer.put(index, 2 * n); @@ -1168,16 +1168,16 @@ public void release() { } int n = 0; for (int i = 0; i < sizes[0]; i++) { - assertEquals(n, arrayIndexer.get(i * strides[0]), 0); - assertEquals(n, directIndexer.get(i * strides[0]), 0); + assertEquals(n, arrayIndexer.get(i), 0); + assertEquals(n, directIndexer.get(i), 0); for (int j = 0; j < sizes[1]; j++) { - assertEquals(n, arrayIndexer.get(i, j * strides[1]), 0); - assertEquals(n, directIndexer.get(i, j * strides[1]), 0); + assertEquals(n, arrayIndexer.get(i, j), 0); + assertEquals(n, directIndexer.get(i, j), 0); for (int k = 0; k < sizes[2]; k++) { - assertEquals(n, arrayIndexer.get(i, j, k * strides[2]), 0); - assertEquals(n, directIndexer.get(i, j, k * strides[2]), 0); + assertEquals(n, arrayIndexer.get(i, j, k), 0); + assertEquals(n, directIndexer.get(i, j, k), 0); for (int m = 0; m < sizes[3]; m++) { - long[] index = { i, j, k, m * strides[3] }; + long[] index = { i, j, k, m }; assertEquals(n, arrayIndexer.get(index), 0); assertEquals(n, directIndexer.get(index), 0); arrayIndexer.put(index, 2 * n);