Class NDArrayIndex

    • Constructor Detail

      • NDArrayIndex

        public NDArrayIndex​(long... indices)
        NDArrayIndexing based on the given indexes
        Parameters:
        indices -
    • Method Detail

      • 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 for
        offsets - 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 for
        indices - 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 for
        offsets - 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 copy
        n - 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 of SpecifiedIndex. 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 for
        intendedIndexes - 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 elements
        intendedIndexes - 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 elements
        intendedIndexes - 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​(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 elements
        intendedIndexes - 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 begin
        stride - the stride at which to increment
        end - the end index
        max - 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 begin
        stride - the stride at which to increment
        end - 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 begin
        stride - the stride at which to increment
        end - the end index
        inclusive - 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 begin
        end - 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 begin
        end - the end index
        inclusive - whether the end should be inclusive or not
        Returns:
        the interval
      • end

        public long end()
        Description copied from interface: INDArrayIndex
        The ending for this index
        Specified by:
        end in interface INDArrayIndex
        Returns:
      • offset

        public long offset()
        Description copied from interface: INDArrayIndex
        The start of this index
        Specified by:
        offset in interface INDArrayIndex
        Returns:
      • length

        public long length()
        Returns the length of the indices
        Specified by:
        length in interface INDArrayIndex
        Returns:
        the length of the range
      • stride

        public long stride()
        Description copied from interface: INDArrayIndex
        The stride for the index (most of the time will be 1)
        Specified by:
        stride in interface INDArrayIndex
        Returns:
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • init

        public void init​(INDArray arr,
                         long begin,
                         int dimension)
        Description copied from interface: INDArrayIndex
        Init the index wrt the dimension and the given nd array
        Specified by:
        init in interface INDArrayIndex
        Parameters:
        arr - the array to initialize on
        begin - the beginning index
        dimension - the dimension to initialize on
      • init

        public void init​(INDArray arr,
                         int dimension)
        Description copied from interface: INDArrayIndex
        Init the index wrt the dimension and the given nd array
        Specified by:
        init in interface INDArrayIndex
        Parameters:
        arr - the array to initialize on
        dimension - the dimension to initialize on
      • init

        public void init​(long begin,
                         long end,
                         long max)
        Specified by:
        init in interface INDArrayIndex
      • init

        public void init​(long begin,
                         long end)
        Description copied from interface: INDArrayIndex
        Initialize based on the specified begin and end
        Specified by:
        init in interface INDArrayIndex