Package ucar.ma2

Class Index

java.lang.Object
ucar.ma2.Index
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ChunkingIndex, FileWriter2.ChunkingIndex, Index0D, Index1D, Index2D, Index3D, Index4D, Index5D, Index6D, Index7D, IndexConstant

public class Index extends Object implements Cloneable
Indexes for Multidimensional arrays. An Index refers to a particular element of an array.

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.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Index0D
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Index(int[] _shape, int[] _stride)
    Constructor that lets you set the strides yourself.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    static long
    computeSize(int[] shape)
    Compute total number of elements in the array.
    int
    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[]
    Get the current counter.
    int
    Get the number of dimensions in the array.
    int[]
    Get the shape: length of array in each dimension.
    int
    getShape(int index)
    Get the length of the ith dimension.
    long
    Get the total number of elements in the array.
    int
    Increment the current element by 1.
    set(int v0)
    set current element at dimension 0 to v0
    set(int[] index)
    Set the current element's index.
    set(int v0, int v1)
    set current element at dimension 0,1 to v0,v1
    set(int v0, int v1, int v2)
    set current element at dimension 0,1,2 to v0,v1,v2
    set(int v0, int v1, int v2, int v3)
    set current element at dimension 0,1,2,3 to v0,v1,v2,v3
    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
    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
    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
    set0(int v)
    set current element at dimension 0 to v
    set1(int v)
    set current element at dimension 1 to v
    set2(int v)
    set current element at dimension 2 to v
    set3(int v)
    set current element at dimension 3 to v
    set4(int v)
    set current element at dimension 4 to v
    set5(int v)
    set current element at dimension 5 to v
    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 representation

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • scalarIndexImmutable

      public static final Index0D scalarIndexImmutable
  • Constructor Details

    • Index

      public Index(int[] _shape, int[] _stride)
      Constructor that lets you set the strides yourself. This is used as a counter, not a description of an index section.
      Parameters:
      _shape - Index shape
      _stride - Index stride
  • Method Details

    • factory

      public static Index factory(int[] shape)
      Generate a subclass of Index optimized for this array's rank
      Parameters:
      shape - use this shape
      Returns:
      a subclass of Index optimized for this array's rank
    • computeSize

      public static long computeSize(int[] shape)
      Compute total number of elements in the array. Stop at vlen
      Parameters:
      shape - length of array in each dimension.
      Returns:
      total number of elements in the array.
    • getRank

      public int getRank()
      Get the number of dimensions in the array.
      Returns:
      the number of dimensions in the array.
    • getShape

      public int[] getShape()
      Get the shape: length of array in each dimension.
      Returns:
      the shape
    • getShape

      public int getShape(int index)
      Get the length of the ith dimension.
      Parameters:
      index - which dimension. must be in [0, getRank())
      Returns:
      the ith dimension length
    • getSize

      public long getSize()
      Get the total number of elements in the array.
      Returns:
      the total number of elements in the array.
    • currentElement

      public int currentElement()
      Get the current element's index into the 1D backing array. VLEN stops processing.
      Returns:
      the current element's index into the 1D backing array.
    • getCurrentCounter

      public int[] getCurrentCounter()
      Get the current counter.
      Returns:
      copy of the current counter.
    • setCurrentCounter

      public void setCurrentCounter(int currElement)
      Set the current counter from the 1D "current element" currElement = offset + stride[0]*current[0] + ...
      Parameters:
      currElement - set to this value
    • incr

      public int incr()
      Increment the current element by 1. Used by IndexIterator. General rank, with subclass specialization. Vlen skipped.
      Returns:
      currentElement()
    • set

      public Index set(int[] index)
      Set the current element's index. General-rank case.
      Parameters:
      index - set current value to these values
      Returns:
      this, so you can use A.get(i.set(i))
      Throws:
      ArrayIndexOutOfBoundsException - if index.length != rank.
    • setDim

      public void setDim(int dim, int value)
      set current element at dimension dim to v
      Parameters:
      dim - set this dimension
      value - to this value
    • set0

      public Index set0(int v)
      set current element at dimension 0 to v
      Parameters:
      v - set 0th dimension index to this value
      Returns:
      this, so you can use A.get(i.set(i))
    • set1

      public Index set1(int v)
      set current element at dimension 1 to v
      Parameters:
      v - set dimension 1 index to this value
      Returns:
      this, so you can use A.get(i.set(i))
    • set2

      public Index set2(int v)
      set current element at dimension 2 to v
      Parameters:
      v - set dimension 2 index to this value
      Returns:
      this, so you can use A.get(i.set(i))
    • set3

      public Index set3(int v)
      set current element at dimension 3 to v
      Parameters:
      v - set dimension 3 index to this value
      Returns:
      this, so you can use A.get(i.set(i))
    • set4

      public Index set4(int v)
      set current element at dimension 4 to v
      Parameters:
      v - set dimension 4 index to this value
      Returns:
      this, so you can use A.get(i.set(i))
    • set5

      public Index set5(int v)
      set current element at dimension 5 to v
      Parameters:
      v - set dimension 5 index to this value
      Returns:
      this, so you can use A.get(i.set(i))
    • set6

      public Index set6(int v)
      set current element at dimension 6 to v
      Parameters:
      v - set dimension 6 index to this value
      Returns:
      this, so you can use A.get(i.set(i))
    • set

      public Index set(int v0)
      set current element at dimension 0 to v0
      Parameters:
      v0 - set dimension 0 index to this value
      Returns:
      this, so you can use A.get(i.set(i))
    • set

      public Index set(int v0, int v1)
      set current element at dimension 0,1 to v0,v1
      Parameters:
      v0 - set dimension 0 index to this value
      v1 - set dimension 1 index to this value
      Returns:
      this, so you can use A.get(i.set(i,j))
    • set

      public Index set(int v0, int v1, int v2)
      set current element at dimension 0,1,2 to v0,v1,v2
      Parameters:
      v0 - set dimension 0 index to this value
      v1 - set dimension 1 index to this value
      v2 - set dimension 2 index to this value
      Returns:
      this, so you can use A.get(i.set(i,j,k))
    • set

      public Index set(int v0, int v1, int v2, int v3)
      set current element at dimension 0,1,2,3 to v0,v1,v2,v3
      Parameters:
      v0 - set dimension 0 index to this value
      v1 - set dimension 1 index to this value
      v2 - set dimension 2 index to this value
      v3 - set dimension 3 index to this value
      Returns:
      this, so you can use A.get(i.set(i,j,k,l))
    • set

      public 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
      Parameters:
      v0 - set dimension 0 index to this value
      v1 - set dimension 1 index to this value
      v2 - set dimension 2 index to this value
      v3 - set dimension 3 index to this value
      v4 - set dimension 4 index to this value
      Returns:
      this, so you can use A.get(i.set(i,j,k,l,m))
    • set

      public 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
      Parameters:
      v0 - set dimension 0 index to this value
      v1 - set dimension 1 index to this value
      v2 - set dimension 2 index to this value
      v3 - set dimension 3 index to this value
      v4 - set dimension 4 index to this value
      v5 - set dimension 5 index to this value
      Returns:
      this, so you can use A.get(i.set(i,j,k,l,m,n))
    • set

      public 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
      Parameters:
      v0 - set dimension 0 index to this value
      v1 - set dimension 1 index to this value
      v2 - set dimension 2 index to this value
      v3 - set dimension 3 index to this value
      v4 - set dimension 4 index to this value
      v5 - set dimension 5 index to this value
      v6 - set dimension 6 index to this value
      Returns:
      this, so you can use A.get(i.set(i,j,k,l,m,n,p))
    • toStringDebug

      public String toStringDebug()
      String representation
      Returns:
      String representation
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clone

      public Object clone()