Skip to content

Commit

Permalink
bytedeco#391 Moved Index creation methods inside Index. Keeping Index…
Browse files Browse the repository at this point in the history
….strides() (package private) only for backward compatibility, because we need to return strides() in Indexer.
  • Loading branch information
matteodg committed May 3, 2020
1 parent 93db7b9 commit bad45f3
Show file tree
Hide file tree
Showing 63 changed files with 237 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

package org.bytedeco.javacpp.indexer;

import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@code short[]} array, treated as bfloat16.
*
Expand All @@ -36,17 +33,17 @@ public class Bfloat16ArrayIndexer extends Bfloat16Indexer {

/** Calls {@code Bfloat16ArrayIndexer(array, defaultIndex({ array.length }))}. */
public Bfloat16ArrayIndexer(short[] array) {
this(array, defaultIndex(array.length));
this(array, Index.create(array.length));
}

/** Calls {@code Bfloat16ArrayIndexer(array, sizes)}. */
@Deprecated public Bfloat16ArrayIndexer(short[] array, long... sizes) {
this(array, defaultIndex(sizes));
this(array, Index.create(sizes));
}

/** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */
@Deprecated public Bfloat16ArrayIndexer(short[] array, long[] sizes, long[] strides) {
this(array, customStrides(sizes, strides));
this(array, Index.create(sizes, strides));
}

/** Constructor to set the {@link #array} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.nio.Buffer;
import java.nio.ShortBuffer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@link ShortBuffer}, treated as bfloat16.
Expand All @@ -38,17 +36,17 @@ public class Bfloat16BufferIndexer extends Bfloat16Indexer {

/** Calls {@code Bfloat16BufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */
public Bfloat16BufferIndexer(ShortBuffer buffer) {
this(buffer, defaultIndex(buffer.limit()));
this(buffer, Index.create(buffer.limit()));
}

/** Calls {@code Bfloat16BufferIndexer(buffer, defaultIndex(sizes))}. */
@Deprecated public Bfloat16BufferIndexer(ShortBuffer buffer, long... sizes) {
this(buffer, defaultIndex(sizes));
this(buffer, Index.create(sizes));
}

/** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */
@Deprecated public Bfloat16BufferIndexer(ShortBuffer buffer, long[] sizes, long[] strides) {
this(buffer, customStrides(sizes, strides));
this(buffer, Index.create(sizes, strides));
}

/** Constructor to set the {@link #buffer} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

package org.bytedeco.javacpp.indexer;

import java.nio.ShortBuffer;
import org.bytedeco.javacpp.ShortPointer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;

import java.nio.ShortBuffer;

/**
* Abstract indexer for the {@code short} primitive type, treated as bfloat16.
Expand Down Expand Up @@ -105,7 +105,7 @@ public static Bfloat16Indexer create(ShortPointer pointer, Index index) {
* @return the new bfloat16 indexer backed by the raw memory interface, a buffer, or an array
*/
@Deprecated public static Bfloat16Indexer create(final ShortPointer pointer, long[] sizes, long[] strides, boolean direct) {
return create(pointer, customStrides(sizes, strides), direct);
return create(pointer, Index.create(sizes, strides), direct);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.ShortPointer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@link ShortPointer} using the {@link Raw} instance, treated as bfloat16.
Expand All @@ -42,17 +40,17 @@ public class Bfloat16RawIndexer extends Bfloat16Indexer {

/** Calls {@code Bfloat16RawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */
public Bfloat16RawIndexer(ShortPointer pointer) {
this(pointer, defaultIndex( pointer.limit() - pointer.position() ));
this(pointer, Index.create( pointer.limit() - pointer.position() ));
}

/** Calls {@code Bfloat16RawIndexer(pointer, defaultIndex(sizes))}. */
@Deprecated public Bfloat16RawIndexer(ShortPointer pointer, long... sizes) {
this(pointer, defaultIndex(sizes));
this(pointer, Index.create(sizes));
}

/** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */
@Deprecated public Bfloat16RawIndexer(ShortPointer pointer, long[] sizes, long[] strides) {
this(pointer, customStrides(sizes, strides));
this(pointer, Index.create(sizes, strides));
}

/** Constructor to set the {@link #pointer} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

package org.bytedeco.javacpp.indexer;

import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@code boolean[]} array.
*
Expand All @@ -36,17 +33,17 @@ public class BooleanArrayIndexer extends BooleanIndexer {

/** Calls {@code BooleanArrayIndexer(array, defaultIndex({ array.length }))}. */
public BooleanArrayIndexer(boolean[] array) {
this(array, defaultIndex(array.length));
this(array, Index.create(array.length));
}

/** Calls {@code BooleanArrayIndexer(array, sizes)}. */
@Deprecated public BooleanArrayIndexer(boolean[] array, long... sizes) {
this(array, defaultIndex(sizes));
this(array, Index.create(sizes));
}

/** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */
@Deprecated public BooleanArrayIndexer(boolean[] array, long[] sizes, long[] strides) {
this(array, customStrides(sizes, strides));
this(array, Index.create(sizes, strides));
}

/** Constructor to set the {@link #array} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.nio.Buffer;
import java.nio.ByteBuffer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@link ByteBuffer} as {@code boolean} values.
Expand All @@ -38,17 +36,17 @@ public class BooleanBufferIndexer extends BooleanIndexer {

/** Calls {@code BooleanBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */
public BooleanBufferIndexer(ByteBuffer buffer) {
this(buffer, defaultIndex(buffer.limit()));
this(buffer, Index.create(buffer.limit()));
}

/** Calls {@code BooleanBufferIndexer(buffer, defaultIndex(sizes))}. */
@Deprecated public BooleanBufferIndexer(ByteBuffer buffer, long... sizes) {
this(buffer, defaultIndex(sizes));
this(buffer, Index.create(sizes));
}

/** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */
@Deprecated public BooleanBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) {
this(buffer, customStrides(sizes, strides));
this(buffer, Index.create(sizes, strides));
}

/** Constructor to set the {@link #buffer} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

package org.bytedeco.javacpp.indexer;

import java.nio.ByteBuffer;
import org.bytedeco.javacpp.BooleanPointer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;

import java.nio.ByteBuffer;

/**
* Abstract indexer for the {@code boolean} primitive type.
Expand Down Expand Up @@ -103,7 +103,7 @@ public static BooleanIndexer create(BooleanPointer pointer, Index index) {
* @return the new boolean indexer backed by the raw memory interface, a buffer, or an array
*/
@Deprecated public static BooleanIndexer create(final BooleanPointer pointer, long[] sizes, long[] strides, boolean direct) {
return create(pointer, customStrides(sizes, strides), direct);
return create(pointer, Index.create(sizes, strides), direct);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import org.bytedeco.javacpp.BooleanPointer;
import org.bytedeco.javacpp.Pointer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@link BooleanPointer} using the {@link Raw} instance.
Expand All @@ -42,7 +40,7 @@ public class BooleanRawIndexer extends BooleanIndexer {

/** Calls {@code BooleanRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */
public BooleanRawIndexer(BooleanPointer pointer) {
this(pointer, defaultIndex( pointer.limit() - pointer.position() ));
this(pointer, Index.create( pointer.limit() - pointer.position() ));
}

/** Calls {@code BooleanRawIndexer(pointer, defaultIndex(sizes))}. */
Expand All @@ -52,7 +50,7 @@ public BooleanRawIndexer(BooleanPointer pointer) {

/** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */
@Deprecated public BooleanRawIndexer(BooleanPointer pointer, long[] sizes, long[] strides) {
this(pointer, customStrides(sizes, strides));
this(pointer, Index.create(sizes, strides));
}

/** Constructor to set the {@link #pointer} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@code byte[]} array.
Expand All @@ -42,17 +40,17 @@ public class ByteArrayIndexer extends ByteIndexer {

/** Calls {@code ByteArrayIndexer(array, defaultIndex({ array.length }))}. */
public ByteArrayIndexer(byte[] array) {
this(array, defaultIndex(array.length));
this(array, Index.create(array.length));
}

/** Calls {@code ByteArrayIndexer(array, sizes)}. */
@Deprecated public ByteArrayIndexer(byte[] array, long... sizes) {
this(array, defaultIndex(sizes));
this(array, Index.create(sizes));
}

/** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */
@Deprecated public ByteArrayIndexer(byte[] array, long[] sizes, long[] strides) {
this(array, customStrides(sizes, strides));
this(array, Index.create(sizes, strides));
}

/** Constructor to set the {@link #array} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.nio.Buffer;
import java.nio.ByteBuffer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@link ByteBuffer}.
Expand All @@ -38,17 +36,17 @@ public class ByteBufferIndexer extends ByteIndexer {

/** Calls {@code ByteBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */
public ByteBufferIndexer(ByteBuffer buffer) {
this(buffer, defaultIndex(buffer.limit()));
this(buffer, Index.create(buffer.limit()));
}

/** Calls {@code ByteBufferIndexer(buffer, defaultIndex(sizes))}. */
@Deprecated public ByteBufferIndexer(ByteBuffer buffer, long... sizes) {
this(buffer, defaultIndex(sizes));
this(buffer, Index.create(sizes));
}

/** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */
@Deprecated public ByteBufferIndexer(ByteBuffer buffer, long[] sizes, long[] strides) {
this(buffer, customStrides(sizes, strides));
this(buffer, Index.create(sizes, strides));
}

/** Constructor to set the {@link #buffer} and {@link #index}. */
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/bytedeco/javacpp/indexer/ByteIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

package org.bytedeco.javacpp.indexer;

import org.bytedeco.javacpp.BytePointer;

import java.math.BigInteger;
import java.nio.ByteBuffer;
import org.bytedeco.javacpp.BytePointer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;

/**
* Abstract indexer for the {@code byte} primitive type.
Expand Down Expand Up @@ -104,7 +104,7 @@ public static ByteIndexer create(BytePointer pointer, Index index) {
* @return the new byte indexer backed by the raw memory interface, a buffer, or an array
*/
@Deprecated public static ByteIndexer create(final BytePointer pointer, long[] sizes, long[] strides, boolean direct) {
return create(pointer, customStrides(sizes, strides), direct);
return create(pointer, Index.create(sizes, strides), direct);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.Pointer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@link BytePointer} using the {@link Raw} instance.
Expand All @@ -42,7 +40,7 @@ public class ByteRawIndexer extends ByteIndexer {

/** Calls {@code ByteRawIndexer(pointer, defaultIndex({ pointer.limit() - pointer.position() }))}. */
public ByteRawIndexer(BytePointer pointer) {
this(pointer, defaultIndex( pointer.limit() - pointer.position() ));
this(pointer, Index.create( pointer.limit() - pointer.position() ));
}

/** Calls {@code ByteRawIndexer(pointer, defaultIndex(sizes))}. */
Expand All @@ -52,7 +50,7 @@ public ByteRawIndexer(BytePointer pointer) {

/** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */
@Deprecated public ByteRawIndexer(BytePointer pointer, long[] sizes, long[] strides) {
this(pointer, customStrides(sizes, strides));
this(pointer, Index.create(sizes, strides));
}

/** Constructor to set the {@link #pointer} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

package org.bytedeco.javacpp.indexer;

import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@code char[]} array.
*
Expand All @@ -36,17 +33,17 @@ public class CharArrayIndexer extends CharIndexer {

/** Calls {@code CharArrayIndexer(array, defaultIndex({ array.length }))}. */
public CharArrayIndexer(char[] array) {
this(array, defaultIndex(array.length));
this(array, Index.create(array.length));
}

/** Calls {@code CharArrayIndexer(array, sizes)}. */
@Deprecated public CharArrayIndexer(char[] array, long... sizes) {
this(array, defaultIndex(sizes));
this(array, Index.create(sizes));
}

/** Constructor to set the {@link #array}, {@link #sizes} and {@link #strides}. */
@Deprecated public CharArrayIndexer(char[] array, long[] sizes, long[] strides) {
this(array, customStrides(sizes, strides));
this(array, Index.create(sizes, strides));
}

/** Constructor to set the {@link #array} and {@link #index}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.nio.Buffer;
import java.nio.CharBuffer;
import static org.bytedeco.javacpp.indexer.StrideIndex.customStrides;
import static org.bytedeco.javacpp.indexer.StrideIndex.defaultIndex;

/**
* An indexer for a {@link CharBuffer}.
Expand All @@ -38,17 +36,17 @@ public class CharBufferIndexer extends CharIndexer {

/** Calls {@code CharBufferIndexer(buffer, defaultIndex({ buffer.limit() }))}. */
public CharBufferIndexer(CharBuffer buffer) {
this(buffer, defaultIndex(buffer.limit()));
this(buffer, Index.create(buffer.limit()));
}

/** Calls {@code CharBufferIndexer(buffer, defaultIndex(sizes))}. */
public CharBufferIndexer(CharBuffer buffer, long... sizes) {
this(buffer, defaultIndex(sizes));
this(buffer, Index.create(sizes));
}

/** Constructor to set the {@link #buffer}, {@link #sizes} and {@link #strides}. */
public CharBufferIndexer(CharBuffer buffer, long[] sizes, long[] strides) {
this(buffer, customStrides(sizes, strides));
this(buffer, Index.create(sizes, strides));
}

/** Constructor to set the {@link #buffer} and {@link #index}. */
Expand Down
Loading

0 comments on commit bad45f3

Please sign in to comment.