Skip to content

Commit

Permalink
bytedeco#391 Rename Indexer.slice() to Indexer.reindex(), remove Inde…
Browse files Browse the repository at this point in the history
…x.strides(), add Index.ONE as single dimension index of size one, remove Indexer.ONE_STRIDE
  • Loading branch information
matteodg committed May 3, 2020
1 parent bad45f3 commit 8f436ab
Show file tree
Hide file tree
Showing 47 changed files with 55 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Bfloat16ArrayIndexer(short[] array, Index index) {
}

@Override
public Bfloat16Indexer slice(Index index) {
public Bfloat16Indexer reindex(Index index) {
return new Bfloat16ArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Bfloat16BufferIndexer(ShortBuffer buffer, Index index) {
}

@Override
public Bfloat16Indexer slice(Index index) {
public Bfloat16Indexer reindex(Index index) {
return new Bfloat16BufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Bfloat16RawIndexer(ShortPointer pointer, Index index) {
}

@Override
public Bfloat16Indexer slice(Index index) {
public Bfloat16Indexer reindex(Index index) {
return new Bfloat16RawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public BooleanArrayIndexer(boolean[] array, Index index) {
}

@Override
public BooleanIndexer slice(Index index) {
public BooleanIndexer reindex(Index index) {
return new BooleanArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public BooleanBufferIndexer(ByteBuffer buffer, Index index) {
}

@Override
public BooleanIndexer slice(Index index) {
public BooleanIndexer reindex(Index index) {
return new BooleanBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public BooleanRawIndexer(BooleanPointer pointer, Index index) {
}

@Override
public BooleanIndexer slice(Index index) {
public BooleanIndexer reindex(Index index) {
return new BooleanRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ByteArrayIndexer(byte[] array, Index index) {
}

@Override
public ByteIndexer slice(Index index) {
public ByteIndexer reindex(Index index) {
return new ByteArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ByteBufferIndexer(ByteBuffer buffer, Index index) {
}

@Override
public ByteIndexer slice(Index index) {
public ByteIndexer reindex(Index index) {
return new ByteBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ByteRawIndexer(BytePointer pointer, Index index) {
}

@Override
public ByteIndexer slice(Index index) {
public ByteIndexer reindex(Index index) {
return new ByteRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CharArrayIndexer(char[] array, Index index) {
}

@Override
public CharIndexer slice(Index index) {
public CharIndexer reindex(Index index) {
return new CharArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public CharBufferIndexer(CharBuffer buffer, Index index) {
}

@Override
public CharIndexer slice(Index index) {
public CharIndexer reindex(Index index) {
return new CharBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public CharRawIndexer(CharPointer pointer, Index index) {
}

@Override
public CharIndexer slice(Index index) {
public CharIndexer reindex(Index index) {
return new CharRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public DoubleArrayIndexer(double[] array, Index index) {
}

@Override
public DoubleIndexer slice(Index index) {
public DoubleIndexer reindex(Index index) {
return new DoubleArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DoubleBufferIndexer(DoubleBuffer buffer, Index index) {
}

@Override
public DoubleIndexer slice(Index index) {
public DoubleIndexer reindex(Index index) {
return new DoubleBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public DoubleRawIndexer(DoublePointer pointer, Index index) {
}

@Override
public DoubleIndexer slice(Index index) {
public DoubleIndexer reindex(Index index) {
return new DoubleRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public FloatArrayIndexer(float[] array, Index index) {
}

@Override
public FloatIndexer slice(Index index) {
public FloatIndexer reindex(Index index) {
return new FloatArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public FloatBufferIndexer(FloatBuffer buffer, Index index) {
}

@Override
public FloatIndexer slice(Index index) {
public FloatIndexer reindex(Index index) {
return new FloatBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public FloatRawIndexer(FloatPointer pointer, Index index) {
}

@Override
public FloatIndexer slice(Index index) {
public FloatIndexer reindex(Index index) {
return new FloatRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public HalfArrayIndexer(short[] array, Index index) {
}

@Override
public HalfIndexer slice(Index index) {
public HalfIndexer reindex(Index index) {
return new HalfArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public HalfBufferIndexer(ShortBuffer buffer, Index index) {
}

@Override
public HalfIndexer slice(Index index) {
public HalfIndexer reindex(Index index) {
return new HalfBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public HalfRawIndexer(ShortPointer pointer, Index index) {
}

@Override
public HalfIndexer slice(Index index) {
public HalfIndexer reindex(Index index) {
return new HalfRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,4 @@ public long index(long... indices) {
public long[] sizes() {
return sizes;
}

@Override
long[] strides() {
return strides;
}
}
9 changes: 2 additions & 7 deletions src/main/java/org/bytedeco/javacpp/indexer/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
public abstract class Index {

public static Index ONE = create(1);

public static Index create(long... sizes) {
return new StrideIndex(sizes, defaultStrides(sizes));
}
Expand Down Expand Up @@ -89,11 +91,4 @@ public static long[] defaultStrides(long... sizes) {

/** Returns {@link #sizes} */
public abstract long[] sizes();

/**
* Needed for backward compatibility with {@link Indexer#strides()}
* @return
*/
@Deprecated
abstract long[] strides();
}
14 changes: 7 additions & 7 deletions src/main/java/org/bytedeco/javacpp/indexer/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public abstract class Indexer implements AutoCloseable {
release();
}

@Deprecated protected static final long[] ONE_STRIDE = { 1 };

/**
* The number of elements in each dimension.
* These values are not typically used by the indexer.
Expand All @@ -72,7 +70,9 @@ public abstract class Indexer implements AutoCloseable {
protected Indexer(Index index) {
this.index = index;
this.sizes = index.sizes();
this.strides = index.strides();
if (index instanceof StrideIndex) {
this.strides = ((StrideIndex) index).strides();
}
}

/** Constructor to set the {@link #sizes} and {@link #strides}. */
Expand All @@ -84,13 +84,13 @@ protected Indexer(Index index) {

/** Returns {@link #sizes} */
@Deprecated public long[] sizes() { return sizes; }
/** Returns {@link #strides} */
/** Returns {@link #strides} or {@code null} if there are no strides. */
@Deprecated public long[] strides() { return strides; }

/** Returns {@code sizes[i]} */
@Deprecated public long size(int i) { return sizes[i]; }
/** Returns {@code strides[i]} */
@Deprecated public long stride(int i) { return strides[i]; }
/** Returns {@code strides[i]} or {@code -1} if there are no strides */
@Deprecated public long stride(int i) { return strides != null ? strides[i] : -1; }

/** Returns {@code sizes.length > 0 && sizes.length < 4 ? sizes[0] : -1} */
@Deprecated public long rows() { return sizes.length > 0 && sizes.length < 4 ? sizes[0] : -1; }
Expand Down Expand Up @@ -165,7 +165,7 @@ public long index(long... indices) {
* @param index
* @return
*/
public abstract Indexer slice(Index index);
public abstract Indexer reindex(Index index);

@Override public String toString() {
long rows = sizes.length > 0 ? sizes[0] : 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IntArrayIndexer(int[] array, Index index) {
}

@Override
public IntIndexer slice(Index index) {
public IntIndexer reindex(Index index) {
return new IntArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public IntBufferIndexer(IntBuffer buffer, Index index) {
}

@Override
public IntIndexer slice(Index index) {
public IntIndexer reindex(Index index) {
return new IntBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public IntRawIndexer(IntPointer pointer, Index index) {
}

@Override
public IntIndexer slice(Index index) {
public IntIndexer reindex(Index index) {
return new IntRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public LongArrayIndexer(long[] array, Index index) {
}

@Override
public LongIndexer slice(Index index) {
public LongIndexer reindex(Index index) {
return new LongArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LongBufferIndexer(LongBuffer buffer, Index index) {
}

@Override
public LongIndexer slice(Index index) {
public LongIndexer reindex(Index index) {
return new LongBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public LongRawIndexer(LongPointer pointer, Index index) {
}

@Override
public LongIndexer slice(Index index) {
public LongIndexer reindex(Index index) {
return new LongRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ShortArrayIndexer(short[] array, Index index) {
}

@Override
public ShortIndexer slice(Index index) {
public ShortIndexer reindex(Index index) {
return new ShortArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ShortBufferIndexer(ShortBuffer buffer, Index index) {
}

@Override
public ShortIndexer slice(Index index) {
public ShortIndexer reindex(Index index) {
return new ShortBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ShortRawIndexer(ShortPointer pointer, Index index) {
}

@Override
public ShortIndexer slice(Index index) {
public ShortIndexer reindex(Index index) {
return new ShortRawIndexer(pointer, index);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/bytedeco/javacpp/indexer/StrideIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ protected StrideIndex(long[] sizes, long[] strides) {
@Override
public long[] sizes() { return sizes; }

@Deprecated
@Override
long[] strides() { return strides; }
public long[] strides() {
return strides;
}

@Override
public long index(long i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public UByteArrayIndexer(byte[] array, Index index) {
}

@Override
public UByteIndexer slice(Index index) {
public UByteIndexer reindex(Index index) {
return new UByteArrayIndexer(array, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public UByteBufferIndexer(ByteBuffer buffer, Index index) {
}

@Override
public UByteIndexer slice(Index index) {
public UByteIndexer reindex(Index index) {
return new UByteBufferIndexer(buffer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public UByteRawIndexer(BytePointer pointer, Index index) {
}

@Override
public UByteIndexer slice(Index index) {
public UByteIndexer reindex(Index index) {
return new UByteRawIndexer(pointer, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public UIntArrayIndexer(int[] array, Index index) {
}

@Override
public UIntIndexer slice(Index index) {
public UIntIndexer reindex(Index index) {
return new UIntArrayIndexer(array, index);
}

Expand Down
Loading

0 comments on commit 8f436ab

Please sign in to comment.