Asserts that the indices specified by this slice are within the valid size bounds for the provided underlying sequence length.
Asserts that the indices specified by this slice are within the valid size bounds for the provided underlying sequence length. Throws an IndexOutOfBoundsException exception if they are not.
Underlying sequence length.
IllegalArgumentException
If the underlying sequence length is not positive.
IndexOutOfBoundsException
If the indices specified by this slice are not within the valid size bounds for
the provided underlying sequence length.
End index for this slice.
Boolean value indicating whether this slice inclusive with respect to end
or not.
Length of this slice.
Length of this slice.
The length of a slice can only be computed if:
end - start
has the same sign as step
, orUnderlying sequence length.
IllegalArgumentException
If the underlying sequence length is not positive, or if the slice is invalid
for some reason.
IndexOutOfBoundsException
If the indices specified by this slice are not within the valid size bounds for
the provided underlying sequence length.
Length of this slice.
Length of this slice.
If end - start
has the opposite sign of step
, then the length of this slice is considered unknown and a value
of -1
is returned. This can be avoided by providing the underlying sequence length in the length method of
this class.
Start index for this slice.
Step for this slice.
Returns an array containing the indices represented by this slice, for the specified underlying sequence length.
Returns an array containing the indices represented by this slice, for the specified underlying sequence length.
This method takes case of negative indexing and the returned array is guaranteed to only have positive elements.
Underlying sequence length.
Array containing the indices represented by this slice, for the specified underlying sequence length.
IllegalArgumentException
If the underlying sequence length is not positive.
IndexOutOfBoundsException
If the indices specified by this slice are not within the valid size bounds for
the provided underlying sequence length.
Represents a slice object. A slice is a sequence of indices for some underlying sequence or tensor.
The companion object provides some helpful implicit conversion functions that allow for easy creation of slices.
For example:
Note how the end index is exclusive and the step size is optional.