Package org.nd4j.linalg.indexing
Class Indices
- java.lang.Object
-
- org.nd4j.linalg.indexing.Indices
-
public class Indices extends Object
Indexing util.- Author:
- Adam Gibson
-
-
Constructor Summary
Constructors Constructor Description Indices()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static INDArrayIndex[]
adjustIndices(int[] originalShape, INDArrayIndex... indexes)
Prunes indices of greater length than the shape and fills in missing indices if there are anystatic INDArrayIndex[]
createFromStartAndEnd(INDArray start, INDArray end)
Create an n dimensional index based on the given interval indices.static INDArrayIndex[]
createFromStartAndEnd(INDArray start, INDArray end, boolean inclusive)
Create indices representing intervals along each dimensionstatic INDArrayIndex[]
fillIn(int[] shape, INDArrayIndex... indexes)
Fill in the missing indices to be the same length as the original shape.static boolean
isContiguous(int[] indices, int diff)
Returns whether indices are contiguous by a certain amount or notstatic boolean
isScalar(INDArray indexOver, INDArrayIndex... indexes)
Check if the given indexes over the specified array are searching for a scalarstatic long
linearOffset(int index, INDArray arr)
Compute the linear offset for an index in an ndarray.static long[]
offsets(long[] shape, INDArrayIndex... indices)
The offsets (begin index) for each indexstatic int
rowNumber(int index, INDArray arr)
Compute the linear offset for an index in an ndarray.static int[]
shape(int[] shape, INDArrayIndex... indices)
Calculate the shape for the given set of indices and offsets.static long[]
shape(long[] shape, INDArrayIndex... indices)
static int[]
shape(INDArrayIndex... indices)
Calculate the shape for the given set of indices.static int[]
stride(INDArray arr, INDArrayIndex[] indexes, int... shape)
Return the stride to be used for indexingstatic int[]
strides(char ordering, NDArrayIndex... indexes)
Calculate the strides based on the given indices
-
-
-
Method Detail
-
rowNumber
public static int rowNumber(int index, INDArray arr)
Compute the linear offset for an index in an ndarray. For c ordering this is just the index itself. For fortran ordering, the following algorithm is used. Assuming an ndarray is a list of vectors. The index of the vector relative to the given index is calculated. vectorAlongDimension is then used along the last dimension using the computed index. The offset + the computed column wrt the index: (index % the size of the last dimension) will render the given index in fortran ordering- Parameters:
index
- the indexarr
- the array- Returns:
- the linear offset
-
linearOffset
public static long linearOffset(int index, INDArray arr)
Compute the linear offset for an index in an ndarray. For c ordering this is just the index itself. For fortran ordering, the following algorithm is used. Assuming an ndarray is a list of vectors. The index of the vector relative to the given index is calculated. vectorAlongDimension is then used along the last dimension using the computed index. The offset + the computed column wrt the index: (index % the size of the last dimension) will render the given index in fortran ordering- Parameters:
index
- the indexarr
- the array- Returns:
- the linear offset
-
offsets
public static long[] offsets(long[] shape, INDArrayIndex... indices)
The offsets (begin index) for each index- Parameters:
indices
- the indices- Returns:
- the offsets for the given set of indices
-
fillIn
public static INDArrayIndex[] fillIn(int[] shape, INDArrayIndex... indexes)
Fill in the missing indices to be the same length as the original shape. Think of this as what fills in the indices for numpy or matlab: Given a which is (4,3,2) in numpy: a[1:3] is filled in by the rest to give back the full slice This algorithm fills in that delta- Parameters:
shape
- the original shapeindexes
- the indexes to start from- Returns:
- the filled in indices
-
adjustIndices
public static INDArrayIndex[] adjustIndices(int[] originalShape, INDArrayIndex... indexes)
Prunes indices of greater length than the shape and fills in missing indices if there are any- Parameters:
originalShape
- the original shape to adjust toindexes
- the indexes to adjust- Returns:
- the adjusted indices
-
strides
public static int[] strides(char ordering, NDArrayIndex... indexes)
Calculate the strides based on the given indices- Parameters:
ordering
- the ordering to calculate strides forindexes
- the indices to calculate stride for- Returns:
- the strides for the given indices
-
shape
public static int[] shape(INDArrayIndex... indices)
Calculate the shape for the given set of indices. The shape is defined as (for each dimension) the difference between the end index + 1 and the begin index- Parameters:
indices
- the indices to calculate the shape for- Returns:
- the shape for the given indices
-
isContiguous
public static boolean isContiguous(int[] indices, int diff)
Returns whether indices are contiguous by a certain amount or not- Parameters:
indices
- the indices to testdiff
- the difference considered to be contiguous- Returns:
- whether the given indices are contiguous or not
-
createFromStartAndEnd
public static INDArrayIndex[] createFromStartAndEnd(INDArray start, INDArray end)
Create an n dimensional index based on the given interval indices. Start and end represent the begin and end of each interval- Parameters:
start
- the start indexesend
- the end indexes- Returns:
- the interval index relative to the given start and end indices
-
createFromStartAndEnd
public static INDArrayIndex[] createFromStartAndEnd(INDArray start, INDArray end, boolean inclusive)
Create indices representing intervals along each dimension- Parameters:
start
- the start indexend
- the end indexinclusive
- whether the last index should be included- Returns:
- the ndarray indexes covering each dimension
-
shape
public static int[] shape(int[] shape, INDArrayIndex... indices)
Calculate the shape for the given set of indices and offsets. The shape is defined as (for each dimension) the difference between the end index + 1 and the begin index If specified, this will check for whether any of the indices are >= to end - 1 and if so, prune it down- Parameters:
shape
- the original shapeindices
- the indices to calculate the shape for- Returns:
- the shape for the given indices
-
shape
public static long[] shape(long[] shape, INDArrayIndex... indices)
-
stride
public static int[] stride(INDArray arr, INDArrayIndex[] indexes, int... shape)
Return the stride to be used for indexing- Parameters:
arr
- the array to get the strides forindexes
- the indexes to use for computing strideshape
- the shape of the output- Returns:
- the strides used for indexing
-
isScalar
public static boolean isScalar(INDArray indexOver, INDArrayIndex... indexes)
Check if the given indexes over the specified array are searching for a scalar- Parameters:
indexOver
- the array to index overindexes
- the index query- Returns:
- true if the given indexes are searching for a scalar false otherwise
-
-