Package org.nd4j.linalg.indexing
Class NDArrayIndex
- java.lang.Object
-
- org.nd4j.linalg.indexing.NDArrayIndex
-
- All Implemented Interfaces:
INDArrayIndex
public abstract class NDArrayIndex extends Object implements INDArrayIndex
NDArray indexing- Author:
- Adam Gibson
-
-
Constructor Summary
Constructors Constructor Description NDArrayIndex(long... indices)NDArrayIndexing based on the given indexes
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static INDArrayIndexall()Represents collecting all elementsstatic INDArrayIndex[]allFor(INDArray arr)Generate an all index equal to the rank of the given arraystatic INDArrayIndex[]createCoveringShape(int[] shape)Creates an index covering the given shape (for each dimension 0,shape[i])static INDArrayIndex[]createCoveringShape(long[] shape)static INDArrayIndex[]deepCopy(INDArrayIndex[] indices)Deep copy all elements of this array ofINDArrayIndexinvokingINDArrayIndex.dup()on each entrylongend()The ending for this indexbooleanequals(Object o)inthashCode()static INDArrayIndex[]indexesFor(long... shape)Add indexes for the given shapestatic INDArrayIndexindices(long... indices)Returns an instance ofSpecifiedIndex.voidinit(long begin, long end)Initialize based on the specified begin and endvoidinit(long begin, long end, long max)voidinit(INDArray arr, int dimension)Init the index wrt the dimension and the given nd arrayvoidinit(INDArray arr, long begin, int dimension)Init the index wrt the dimension and the given nd arraystatic INDArrayIndexinterval(int begin, int end)Generates an interval from begin (inclusive) to end (exclusive)static INDArrayIndexinterval(int begin, int stride, int end, boolean inclusive)Generates an interval from begin (inclusive) to end (exclusive)static INDArrayIndexinterval(long begin, long end)static INDArrayIndexinterval(long begin, long end, boolean inclusive)Generates an interval from begin (inclusive) to end (exclusive)static INDArrayIndexinterval(long begin, long stride, long end)Generates an interval from begin (inclusive) to end (exclusive)static INDArrayIndexinterval(long begin, long stride, long end, boolean inclusive)static INDArrayIndexinterval(long begin, long stride, long end, long max)Generates an interval from begin (inclusive) to end (exclusive)static INDArrayIndexinterval(long begin, long stride, long end, long max, boolean inclusive)longlength()Returns the length of the indicesstatic INDArrayIndexnewAxis()Represents adding a new dimensionstatic INDArrayIndex[]nTimes(INDArrayIndex copy, int n)Repeat a copy of copy n timesstatic intnumNewAxis(INDArrayIndex... axes)Given an array of indexes return the number of new axis elements in teh arraystatic intnumPoints(INDArrayIndex... indexes)Number of point indexeslongoffset()The start of this indexstatic longoffset(int[] strides, long[] offsets)static longoffset(long[] strides, long[] offsets)Compute the offset given an array of offsets.static longoffset(INDArray arr, long... offsets)Compute the offset given an array of offsets.static longoffset(INDArray arr, INDArrayIndex... indices)Compute the offset given an array of offsets.static INDArrayIndexpoint(long point)Returns a point indexstatic INDArrayIndex[]rangeOfLength(INDArrayIndex[] indexes)Create a range based on the given indexes.static INDArrayIndex[]resolve(int[] shape, INDArrayIndex... intendedIndexes)Given an all index and the intended indexes, return an index array containing a combination of all elements for slicing and overriding particular indexes where necessarystatic INDArrayIndex[]resolve(long[] shape, INDArrayIndex... intendedIndexes)static INDArrayIndex[]resolve(INDArray arr, INDArrayIndex... intendedIndexes)Given an all index and the intended indexes, return an index array containing a combination of all elements for slicing and overriding particular indexes where necessarystatic INDArrayIndex[]resolve(INDArrayIndex[] allIndex, INDArrayIndex... intendedIndexes)Given an all index and the intended indexes, return an index array containing a combination of all elements for slicing and overriding particular indexes where necessarystatic INDArrayIndex[]resolveLong(long[] shapeInfo, INDArrayIndex... intendedIndexes)Given an all index and the intended indexes, return an index array containing a combination of all elements for slicing and overriding particular indexes where necessaryvoidreverse()Reverse the indexeslongstride()The stride for the index (most of the time will be 1)StringtoString()protected static INDArrayIndexvalidate(long size, INDArrayIndex index)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.nd4j.linalg.indexing.INDArrayIndex
dup, initialized, isInterval
-
-
-
-
Method Detail
-
deepCopy
public static INDArrayIndex[] deepCopy(INDArrayIndex[] indices)
Deep copy all elements of this array ofINDArrayIndexinvokingINDArrayIndex.dup()on each entry- Parameters:
indices- the indices to copy- Returns:
-
point
public static INDArrayIndex point(long point)
Returns a point index- Parameters:
point- the point index- Returns:
- the point index based on the specified point
-
indexesFor
public static INDArrayIndex[] indexesFor(long... shape)
Add indexes for the given shape- Parameters:
shape- the shape ot convert to indexes- Returns:
- the indexes for the given shape
-
offset
public static long offset(INDArray arr, long... offsets)
Compute the offset given an array of offsets. The offset is computed(for both fortran an d c ordering) as: sum from i to n - 1 o[i] * s[i] where i is the index o is the offset and s is the stride Notice the -1 at the end.- Parameters:
arr- the array to compute the offset foroffsets- the offsets for each dimension- Returns:
- the offset that should be used for indexing
-
offset
public static long offset(INDArray arr, INDArrayIndex... indices)
Compute the offset given an array of offsets. The offset is computed(for both fortran an d c ordering) as: sum from i to n - 1 o[i] * s[i] where i is the index o is the offset and s is the stride Notice the -1 at the end.- Parameters:
arr- the array to compute the offset forindices- the offsets for each dimension- Returns:
- the offset that should be used for indexing
-
offset
public static long offset(long[] strides, long[] offsets)Compute the offset given an array of offsets. The offset is computed(for both fortran an d c ordering) as: sum from i to n - 1 o[i] * s[i] where i is the index o is the offset and s is the stride Notice the -1 at the end.- Parameters:
strides- the strides to compute the offset foroffsets- the offsets for each dimension- Returns:
- the offset that should be used for indexing
-
offset
public static long offset(int[] strides, long[] offsets)
-
nTimes
public static INDArrayIndex[] nTimes(INDArrayIndex copy, int n)
Repeat a copy of copy n times- Parameters:
copy- the ndarray index to copyn- the number of times to copy- Returns:
- an array of length n containing copies of the given ndarray index
-
all
public static INDArrayIndex all()
Represents collecting all elements- Returns:
- an ndarray index meaning collect all elements
-
indices
public static INDArrayIndex indices(long... indices)
Returns an instance ofSpecifiedIndex. Note that SpecifiedIndex works differently than the other indexing options, in that it always returns a copy of the (subset of) the underlying array, for get operations. This means that INDArray.get(..., indices(x,y,z), ...) will be a copy of the relevant subset of the array.- Parameters:
indices- Indices to get
-
newAxis
public static INDArrayIndex newAxis()
Represents adding a new dimension- Returns:
- the indexing for adding a new dimension
-
resolve
public static INDArrayIndex[] resolve(INDArray arr, INDArrayIndex... intendedIndexes)
Given an all index and the intended indexes, return an index array containing a combination of all elements for slicing and overriding particular indexes where necessary- Parameters:
arr- the array to resolve indexes forintendedIndexes- the indexes specified by the user- Returns:
- the resolved indexes (containing all where nothing is specified, and the intended index for a particular dimension otherwise)
-
numPoints
public static int numPoints(INDArrayIndex... indexes)
Number of point indexes- Parameters:
indexes- the indexes to count for points- Returns:
- the number of point indexes in the array
-
resolveLong
public static INDArrayIndex[] resolveLong(long[] shapeInfo, INDArrayIndex... intendedIndexes)
Given an all index and the intended indexes, return an index array containing a combination of all elements for slicing and overriding particular indexes where necessary- Parameters:
shapeInfo- the index containing all elementsintendedIndexes- the indexes specified by the user- Returns:
- the resolved indexes (containing all where nothing is specified, and the intended index for a particular dimension otherwise)
-
resolve
public static INDArrayIndex[] resolve(int[] shape, INDArrayIndex... intendedIndexes)
Given an all index and the intended indexes, return an index array containing a combination of all elements for slicing and overriding particular indexes where necessary- Parameters:
shape- the index containing all elementsintendedIndexes- the indexes specified by the user- Returns:
- the resolved indexes (containing all where nothing is specified, and the intended index for a particular dimension otherwise)
-
resolve
public static INDArrayIndex[] resolve(long[] shape, INDArrayIndex... intendedIndexes)
-
validate
protected static INDArrayIndex validate(long size, INDArrayIndex index)
-
resolve
public static INDArrayIndex[] resolve(INDArrayIndex[] allIndex, INDArrayIndex... intendedIndexes)
Given an all index and the intended indexes, return an index array containing a combination of all elements for slicing and overriding particular indexes where necessary- Parameters:
allIndex- the index containing all elementsintendedIndexes- the indexes specified by the user- Returns:
- the resolved indexes (containing all where nothing is specified, and the intended index for a particular dimension otherwise)
-
numNewAxis
public static int numNewAxis(INDArrayIndex... axes)
Given an array of indexes return the number of new axis elements in teh array- Parameters:
axes- the indexes to get the number of new axes for- Returns:
- the number of new axis elements in the given array
-
allFor
public static INDArrayIndex[] allFor(INDArray arr)
Generate an all index equal to the rank of the given array- Parameters:
arr- the array to generate the all index for- Returns:
- an ndarray index array containing of length arr.rank() containing all elements
-
createCoveringShape
public static INDArrayIndex[] createCoveringShape(int[] shape)
Creates an index covering the given shape (for each dimension 0,shape[i])- Parameters:
shape- the shape to cover- Returns:
- the ndarray indexes to cover
-
createCoveringShape
public static INDArrayIndex[] createCoveringShape(long[] shape)
-
rangeOfLength
public static INDArrayIndex[] rangeOfLength(INDArrayIndex[] indexes)
Create a range based on the given indexes. This is similar to create covering shape in that it approximates the length of each dimension (ignoring elements) and reproduces an index of the same dimension and length.- Parameters:
indexes- the indexes to create the range for- Returns:
- the index ranges.
-
interval
public static INDArrayIndex interval(long begin, long stride, long end, long max)
Generates an interval from begin (inclusive) to end (exclusive)- Parameters:
begin- the beginstride- the stride at which to incrementend- the end indexmax- the max length for this domain- Returns:
- the interval
-
interval
public static INDArrayIndex interval(long begin, long stride, long end)
Generates an interval from begin (inclusive) to end (exclusive)- Parameters:
begin- the beginstride- the stride at which to incrementend- the end index- Returns:
- the interval
-
interval
public static INDArrayIndex interval(int begin, int stride, int end, boolean inclusive)
Generates an interval from begin (inclusive) to end (exclusive)- Parameters:
begin- the beginstride- the stride at which to incrementend- the end indexinclusive- whether the end should be inclusive or not- Returns:
- the interval
-
interval
public static INDArrayIndex interval(long begin, long stride, long end, long max, boolean inclusive)
-
interval
public static INDArrayIndex interval(long begin, long stride, long end, boolean inclusive)
-
interval
public static INDArrayIndex interval(int begin, int end)
Generates an interval from begin (inclusive) to end (exclusive)- Parameters:
begin- the beginend- the end index- Returns:
- the interval
-
interval
public static INDArrayIndex interval(long begin, long end)
-
interval
public static INDArrayIndex interval(long begin, long end, boolean inclusive)
Generates an interval from begin (inclusive) to end (exclusive)- Parameters:
begin- the beginend- the end indexinclusive- whether the end should be inclusive or not- Returns:
- the interval
-
end
public long end()
Description copied from interface:INDArrayIndexThe ending for this index- Specified by:
endin interfaceINDArrayIndex- Returns:
-
offset
public long offset()
Description copied from interface:INDArrayIndexThe start of this index- Specified by:
offsetin interfaceINDArrayIndex- Returns:
-
length
public long length()
Returns the length of the indices- Specified by:
lengthin interfaceINDArrayIndex- Returns:
- the length of the range
-
stride
public long stride()
Description copied from interface:INDArrayIndexThe stride for the index (most of the time will be 1)- Specified by:
stridein interfaceINDArrayIndex- Returns:
-
reverse
public void reverse()
Description copied from interface:INDArrayIndexReverse the indexes- Specified by:
reversein interfaceINDArrayIndex
-
init
public void init(INDArray arr, long begin, int dimension)
Description copied from interface:INDArrayIndexInit the index wrt the dimension and the given nd array- Specified by:
initin interfaceINDArrayIndex- Parameters:
arr- the array to initialize onbegin- the beginning indexdimension- the dimension to initialize on
-
init
public void init(INDArray arr, int dimension)
Description copied from interface:INDArrayIndexInit the index wrt the dimension and the given nd array- Specified by:
initin interfaceINDArrayIndex- Parameters:
arr- the array to initialize ondimension- the dimension to initialize on
-
init
public void init(long begin, long end, long max)- Specified by:
initin interfaceINDArrayIndex
-
init
public void init(long begin, long end)Description copied from interface:INDArrayIndexInitialize based on the specified begin and end- Specified by:
initin interfaceINDArrayIndex
-
-