public class Index extends Object implements Cloneable
This is a generalization of index as int[]. Its main function is to do the index arithmetic to translate an n-dim index into a 1-dim index. The user obtains this by calling getIndex() on an Array. The set() and seti() routines are convenience routines for 1-7 dim arrays.
Array
Modifier and Type | Field and Description |
---|---|
static Index0D |
scalarIndexImmutable |
Constructor and Description |
---|
Index(int[] _shape,
int[] _stride)
Constructor that lets you set the strides yourself.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone() |
static long |
computeSize(int[] shape)
Compute total number of elements in the array.
|
int |
currentElement()
Get the current element's index into the 1D backing array.
|
static Index |
factory(int[] shape)
Generate a subclass of Index optimized for this array's rank
|
int[] |
getCurrentCounter()
Get the current counter.
|
int |
getRank()
Get the number of dimensions in the array.
|
int[] |
getShape()
Get the shape: length of array in each dimension.
|
int |
getShape(int index)
Get the length of the ith dimension.
|
long |
getSize()
Get the total number of elements in the array.
|
int |
incr()
Increment the current element by 1.
|
Index |
set(int v0)
set current element at dimension 0 to v0
|
Index |
set(int[] index)
Set the current element's index.
|
Index |
set(int v0,
int v1)
set current element at dimension 0,1 to v0,v1
|
Index |
set(int v0,
int v1,
int v2)
set current element at dimension 0,1,2 to v0,v1,v2
|
Index |
set(int v0,
int v1,
int v2,
int v3)
set current element at dimension 0,1,2,3 to v0,v1,v2,v3
|
Index |
set(int v0,
int v1,
int v2,
int v3,
int v4)
set current element at dimension 0,1,2,3,4 to v0,v1,v2,v3,v4
|
Index |
set(int v0,
int v1,
int v2,
int v3,
int v4,
int v5)
set current element at dimension 0,1,2,3,4,5 to v0,v1,v2,v3,v4,v5
|
Index |
set(int v0,
int v1,
int v2,
int v3,
int v4,
int v5,
int v6)
set current element at dimension 0,1,2,3,4,5,6 to v0,v1,v2,v3,v4,v5,v6
|
Index |
set0(int v)
set current element at dimension 0 to v
|
Index |
set1(int v)
set current element at dimension 1 to v
|
Index |
set2(int v)
set current element at dimension 2 to v
|
Index |
set3(int v)
set current element at dimension 3 to v
|
Index |
set4(int v)
set current element at dimension 4 to v
|
Index |
set5(int v)
set current element at dimension 5 to v
|
Index |
set6(int v)
set current element at dimension 6 to v
|
void |
setCurrentCounter(int currElement)
Set the current counter from the 1D "current element"
currElement = offset + stride[0]*current[0] + ...
|
void |
setDim(int dim,
int value)
set current element at dimension dim to v
|
String |
toString() |
String |
toStringDebug()
String representation
|
public static final Index0D scalarIndexImmutable
public Index(int[] _shape, int[] _stride)
_shape
- Index shape_stride
- Index stridepublic static long computeSize(int[] shape)
shape
- length of array in each dimension.public int currentElement()
public static Index factory(int[] shape)
shape
- use this shapepublic int[] getCurrentCounter()
public int getRank()
public int[] getShape()
public int getShape(int index)
index
- which dimension. must be in [0, getRank())public long getSize()
public int incr()
public Index set(int v0)
v0
- set dimension 0 index to this valuepublic Index set(int[] index)
index
- set current value to these valuesArrayIndexOutOfBoundsException
- if index.length != rank.public Index set(int v0, int v1)
v0
- set dimension 0 index to this valuev1
- set dimension 1 index to this valuepublic Index set(int v0, int v1, int v2)
v0
- set dimension 0 index to this valuev1
- set dimension 1 index to this valuev2
- set dimension 2 index to this valuepublic Index set(int v0, int v1, int v2, int v3)
v0
- set dimension 0 index to this valuev1
- set dimension 1 index to this valuev2
- set dimension 2 index to this valuev3
- set dimension 3 index to this valuepublic Index set(int v0, int v1, int v2, int v3, int v4)
v0
- set dimension 0 index to this valuev1
- set dimension 1 index to this valuev2
- set dimension 2 index to this valuev3
- set dimension 3 index to this valuev4
- set dimension 4 index to this valuepublic Index set(int v0, int v1, int v2, int v3, int v4, int v5)
v0
- set dimension 0 index to this valuev1
- set dimension 1 index to this valuev2
- set dimension 2 index to this valuev3
- set dimension 3 index to this valuev4
- set dimension 4 index to this valuev5
- set dimension 5 index to this valuepublic Index set(int v0, int v1, int v2, int v3, int v4, int v5, int v6)
v0
- set dimension 0 index to this valuev1
- set dimension 1 index to this valuev2
- set dimension 2 index to this valuev3
- set dimension 3 index to this valuev4
- set dimension 4 index to this valuev5
- set dimension 5 index to this valuev6
- set dimension 6 index to this valuepublic Index set0(int v)
v
- set 0th dimension index to this valuepublic Index set1(int v)
v
- set dimension 1 index to this valuepublic Index set2(int v)
v
- set dimension 2 index to this valuepublic Index set3(int v)
v
- set dimension 3 index to this valuepublic Index set4(int v)
v
- set dimension 4 index to this valuepublic Index set5(int v)
v
- set dimension 5 index to this valuepublic Index set6(int v)
v
- set dimension 6 index to this valuepublic void setCurrentCounter(int currElement)
currElement
- set to this valuepublic void setDim(int dim, int value)
dim
- set this dimensionvalue
- to this valuepublic String toStringDebug()