public class Section
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Section.Builder |
class |
Section.Iterator |
Constructor and Description |
---|
Section()
No-arg Constructor
|
Section(int[] shape)
Create Section from a shape array, assumes 0 origin.
|
Section(int[] origin,
int[] shape)
Create Section from a shape and origin arrays.
|
Section(int[] origin,
int[] size,
int[] stride)
Create Section from a shape, origin, and stride arrays.
|
Section(java.util.List<Range> from)
Create Section from a List
|
Section(java.util.List<Range> from,
int[] shape)
Create Section from a List
|
Section(Range... ranges)
Create Section from a variable length list of Ranges
|
Section(Section from)
Copy Constructor.
|
Section(java.lang.String sectionSpec)
Parse an index section String specification, return equivilent Section.
|
Modifier and Type | Method and Description |
---|---|
Section |
addRangeNames(java.util.List<java.lang.String> rangeNames)
Deprecated.
do not use
|
Section |
appendRange()
Deprecated.
use builder().appendNullRange()
|
Section |
appendRange(int size)
Deprecated.
use builder().appendRange(size)
|
Section |
appendRange(int first,
int last)
Deprecated.
use builder().appendRange
|
Section |
appendRange(int first,
int last,
int stride)
Deprecated.
use builder().appendRange
|
Section |
appendRange(Range r)
Deprecated.
use builder().appendRange(r)
|
Section |
appendRange(java.lang.String name,
int first,
int last,
int stride)
Deprecated.
use builder().appendRange
|
static Section.Builder |
builder() |
java.lang.String |
checkInRange(int[] shape)
Check if this Section is legal for the given shape.
|
Section |
compact()
Create a new Section by compacting each Range.
|
boolean |
compatibleRank(Section other)
Compare this section with another upto the vlen in either
|
Section |
compose(Section want)
Create a new Section by composing with a Section that is relative to this Section.
|
long |
computeSize()
Compute total number of elements represented by the section.
|
static long |
computeSize(int[] shape) |
boolean |
conformal(Section other) |
boolean |
contains(Section other)
See if this Section contains another Section.
|
boolean |
equals(java.lang.Object o)
Sections with equals Ranges are equal.
|
boolean |
equalShape(Section other) |
boolean |
equivalent(int[] shape)
Is this section equivilent to the given shape.
|
static Section |
fill(Section s,
int[] shape)
Return a Section guaranteed to be non null, with no null Ranges, and within the bounds set by shape.
|
Range |
find(java.lang.String rangeName)
Find a Range by its name.
|
Section.Iterator |
getIterator(int[] shape)
Iterate over a section, returning the index in an equivalent 1D array of shape[], and optionally the corresponding
index[n]
So this is a section in a (possibly) larger array described by shape[].
|
int[] |
getOrigin()
Get origin array using the Range.first() values.
|
int |
getOrigin(int i)
Get origin of the ith Range
|
Range |
getRange(int i)
Get the ith Range
|
java.util.List<Range> |
getRanges()
Get the list of Ranges.
|
int |
getRank()
Get rank - number of Ranges.
|
int[] |
getShape()
Get shape array using the Range.length() values.
|
int |
getShape(int i)
Get length of the ith Range
|
long |
getSize() |
int[] |
getStride()
Deprecated.
dont assume evenly strided
|
int |
getStride(int i)
Deprecated.
dont assume evenly strided
|
int |
hashCode()
Override Object.hashCode() to agree with equals.
|
Section |
insertRange(int index,
Range r)
Deprecated.
use builder().insertRange
|
Section |
intersect(Section other)
Create a new Section by intersection with another Section
|
boolean |
intersects(Section other)
See if this Section intersects with another Section.
|
boolean |
isImmutable() |
boolean |
isStrided()
Deprecated.
dont assume evenly strided
|
boolean |
isVariableLength() |
static Section |
make(java.util.List<RangeIterator> rangeIter) |
Section |
makeImmutable()
Deprecated.
use builder()
|
int |
offset(Section intersect)
Compute the element offset of an intersecting subrange of this.
|
Section |
prepend(Section parentSection) |
Section |
reduce()
Remove any ranges of length 1
|
Section |
removeFirst(Section parentSection) |
Section |
removeLast()
Deprecated.
use builder().removeLast()
|
Section |
removeRange(int index)
Deprecated.
use builder().removeRange
|
Section |
removeVlen()
Deprecated.
use builder().removeVlen()
|
Section |
replaceRange(int index,
Range r)
Deprecated.
use builder().replaceRange
|
void |
setDefaults(int[] shape)
If any of the ranges are null, which means "all", set the Range from the
corresponding length in shape[].
|
Section |
setRange(int index,
Range r)
Deprecated.
use builder().setRange
|
Section |
shiftOrigin(int[] newOrigin) |
Section |
shiftOrigin(Section newOrigin)
Create a new Section by shifting each range by newOrigin.first()
The result is then a relative offset from the newOrigin.
|
java.lang.String |
show() |
Section |
subSection(int fromIndex,
int endExclusive) |
Section.Builder |
toBuilder() |
java.lang.String |
toString()
Convert List of Ranges to String Spec.
|
Section |
union(Section other)
Create a new Section by union with another Section
|
public Section(int[] shape)
shape
- array of lengths for each Range. 0 = EMPTY, < 0 = VLENpublic Section(int[] origin, int[] shape) throws InvalidRangeException
origin
- array of start for each Rangeshape
- array of lengths for each RangeInvalidRangeException
- if origin < 0, or shape < 1.public Section(int[] origin, int[] size, int[] stride) throws InvalidRangeException
origin
- array of start for each Rangesize
- array of lengths for each Range (last = origin + size -1)stride
- stride between consecutive elements, must be > 0InvalidRangeException
- if origin < 0, or shape < 1.public Section(java.util.List<Range> from)
from
- the list of Rangepublic Section(Range... ranges)
ranges
- the listpublic Section(Section from)
from
- the Section to copypublic Section(java.util.List<Range> from, int[] shape) throws InvalidRangeException
from
- the list of Rangeshape
- use this as default shape if any of the ranges are null.InvalidRangeException
- if shape and range list dont matchpublic Section(java.lang.String sectionSpec) throws InvalidRangeException
sectionSpec := dims dims := dim | dim, dims dim := ':' | slice | start ':' end | start ':' end ':' stride slice := INTEGER start := INTEGER stride := INTEGER end := INTEGER where nonterminals are in lower case, terminals are in upper case, literals are in single quotes. Meaning of index selector : ':' = all slice = hold index to that value start:end = all indices from start to end inclusive start:end:stride = all indices from start to end inclusive with given stride
sectionSpec
- the token to parse, eg "(1:20,:,3,10:20:2)", parenthesis optionalInvalidRangeException
- when the Range is illegaljava.lang.IllegalArgumentException
- when sectionSpec is misformedpublic Section()
public static Section fill(Section s, int[] shape) throws InvalidRangeException
s
- the original Section, may be null or not filledshape
- use this as default shape if any of the ranges are null.InvalidRangeException
- if shape and s and shape rank dont match, or if s has invalid range compared to shapepublic static Section make(java.util.List<RangeIterator> rangeIter)
public Section compact() throws InvalidRangeException
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic Section compose(Section want) throws InvalidRangeException
want
- Section relative to this one. If null, return this. If individual ranges are null, use corresponding
Range in this.InvalidRangeException
- if want.getRank() not equal to this.getRank(), or invalid component Rangepublic Section intersect(Section other) throws InvalidRangeException
other
- Section other sectionInvalidRangeException
- if want.getRank() not equal to this.getRank(), or invalid component Rangepublic int offset(Section intersect) throws InvalidRangeException
intersect
- the subrangeInvalidRangeException
public Section union(Section other) throws InvalidRangeException
other
- Section other sectionInvalidRangeException
- if want.getRank() not equal to this.getRank(), or invalid component Rangepublic Section shiftOrigin(Section newOrigin) throws InvalidRangeException
newOrigin
- this becomes the origin of the resultInvalidRangeException
- if want.getRank() not equal to this.getRank()public Section shiftOrigin(int[] newOrigin) throws InvalidRangeException
InvalidRangeException
public boolean intersects(Section other) throws InvalidRangeException
other
- another sectionInvalidRangeException
- if want.getRank() not equal to this.getRank(),public boolean contains(Section other)
other
- another sectionpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String show()
@Deprecated public Section appendRange()
@Deprecated public Section appendRange(Range r)
@Deprecated public Section appendRange(int size)
size
- add this Range@Deprecated public Section appendRange(int first, int last) throws InvalidRangeException
first
- starting indexlast
- last index, inclusiveInvalidRangeException
- if last < first@Deprecated public Section appendRange(int first, int last, int stride) throws InvalidRangeException
first
- starting indexlast
- last index, inclusivestride
- strideInvalidRangeException
- if last < first@Deprecated public Section appendRange(java.lang.String name, int first, int last, int stride) throws InvalidRangeException
name
- name of Rangefirst
- starting indexlast
- last index, inclusivestride
- strideInvalidRangeException
- if last < first@Deprecated public Section insertRange(int index, Range r)
index
- insert here in the list, existing ranges at or after this index get shifted by oner
- insert this Rangejava.lang.IndexOutOfBoundsException
- if bad index@Deprecated public Section removeRange(int index)
index
- remove here in the list, existing ranges after this index get shifted by onejava.lang.IndexOutOfBoundsException
- if bad index@Deprecated public Section setRange(int index, Range r)
index
- list index, must be in interval [0,size).r
- insert this Rangejava.lang.IndexOutOfBoundsException
- if bad index@Deprecated public Section replaceRange(int index, Range r)
index
- replace here in the list.r
- use this Rangejava.lang.IndexOutOfBoundsException
- if bad indexpublic Section reduce()
public void setDefaults(int[] shape) throws InvalidRangeException
shape
- default length for each Range; must have matching rank.InvalidRangeException
- if rank is wrong@Deprecated public Section makeImmutable()
public Section subSection(int fromIndex, int endExclusive)
@Deprecated public Section removeLast()
@Deprecated public Section removeVlen()
public boolean isImmutable()
public boolean isVariableLength()
@Deprecated public boolean isStrided()
public int[] getShape()
public int[] getOrigin()
public int[] getStride()
public int getOrigin(int i)
i
- index of Rangepublic int getShape(int i)
i
- index of Rangepublic int getStride(int i)
i
- index of Rangepublic long getSize()
public int getRank()
public boolean compatibleRank(Section other)
public long computeSize()
public static long computeSize(int[] shape)
public java.util.List<Range> getRanges()
public Range getRange(int i)
i
- index into the list of Ranges@Nullable public Range find(java.lang.String rangeName)
rangeName
- find this Range@Deprecated public Section addRangeNames(java.util.List<java.lang.String> rangeNames) throws InvalidRangeException
InvalidRangeException
public java.lang.String checkInRange(int[] shape)
shape
- range must fit within this shape, rank must match.public boolean equivalent(int[] shape) throws InvalidRangeException
shape
- the given shape.InvalidRangeException
- if section rank doesnt match shape lengthpublic boolean conformal(Section other)
public boolean equalShape(Section other)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public Section.Iterator getIterator(int[] shape)
shape
- total array shapepublic Section.Builder toBuilder()
public static Section.Builder builder()