Class StrideIndex

  • Direct Known Subclasses:
    HyperslabIndex

    public class StrideIndex
    extends Index
    An Index that computes a linear index from given array sizes and strides.
    Author:
    Matteo Di Giovinazzo
    • Field Detail

      • strides

        protected final long[] strides
        The number of elements to skip to reach the next element in a given dimension. strides[i] > strides[i + 1] && strides[strides.length - 1] == 1 preferred.
    • Constructor Detail

      • StrideIndex

        public StrideIndex​(long... sizes)
        Calls StrideIndex(sizes, defaultStrides(sizes)).
      • StrideIndex

        public StrideIndex​(long[] sizes,
                           long[] strides)
        Constructor to set the Index.sizes and strides.
    • Method Detail

      • defaultStrides

        public static long[] defaultStrides​(long... sizes)
        Returns default (row-major contiguous) strides for the given sizes.
      • strides

        public long[] strides()
        Returns strides.
      • index

        public long index​(long i)
        Returns i * strides[0].
        Overrides:
        index in class Index
      • index

        public long index​(long i,
                          long j)
        Returns i * strides[0] + j * strides[1].
        Overrides:
        index in class Index
      • index

        public long index​(long i,
                          long j,
                          long k)
        Returns i * strides[0] + j * strides[1] + k * strides[2].
        Overrides:
        index in class Index
      • index

        public long index​(long... indices)
        Computes the linear index as the dot product of indices and strides.
        Specified by:
        index in class Index
        Parameters:
        indices - of each dimension
        Returns:
        index to access array or buffer