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 |
---|---|
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 |
hashCode()
Override Object.hashCode() to agree with equals.
|
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 |
isVariableLength() |
static Section |
make(java.util.List<RangeIterator> rangeIter) |
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) |
void |
setDefaults(int[] shape)
If any of the ranges are null, which means "all", set the Range from the
corresponding length in shape[].
|
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()
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(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(Range... ranges)
ranges
- the listpublic Section(Section from)
from
- the Section to copypublic 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 static Section.Builder builder()
public java.lang.String checkInRange(int[] shape)
shape
- range must fit within this shape, rank must match.public Section compact() throws InvalidRangeException
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic boolean compatibleRank(Section other)
public 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 long computeSize()
public static long computeSize(int[] shape)
public boolean conformal(Section other)
public boolean contains(Section other)
other
- another sectionpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public boolean equalShape(Section other)
public boolean equivalent(int[] shape) throws InvalidRangeException
shape
- the given shape.InvalidRangeException
- if section rank doesnt match shape lengthpublic 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 shape@Nullable public Range find(java.lang.String rangeName)
rangeName
- find this Rangepublic Section.Iterator getIterator(int[] shape)
shape
- total array shapepublic int[] getOrigin()
public int getOrigin(int i)
i
- index of Rangepublic Range getRange(int i)
i
- index into the list of Rangespublic java.util.List<Range> getRanges()
public int getRank()
public int[] getShape()
public int getShape(int i)
i
- index of Rangepublic long getSize()
public int hashCode()
hashCode
in class java.lang.Object
public Section intersect(Section other) throws InvalidRangeException
other
- Section other sectionInvalidRangeException
- if want.getRank() not equal to this.getRank(), or invalid component Rangepublic boolean intersects(Section other) throws InvalidRangeException
other
- another sectionInvalidRangeException
- if want.getRank() not equal to this.getRank(),public boolean isImmutable()
public boolean isVariableLength()
public static Section make(java.util.List<RangeIterator> rangeIter)
public int offset(Section intersect) throws InvalidRangeException
intersect
- the subrangeInvalidRangeException
public Section reduce()
public void setDefaults(int[] shape) throws InvalidRangeException
shape
- default length for each Range; must have matching rank.InvalidRangeException
- if rank is wrongpublic Section shiftOrigin(int[] newOrigin) throws InvalidRangeException
InvalidRangeException
public Section shiftOrigin(Section newOrigin) throws InvalidRangeException
newOrigin
- this becomes the origin of the resultInvalidRangeException
- if want.getRank() not equal to this.getRank()public java.lang.String show()
public Section subSection(int fromIndex, int endExclusive)
public Section.Builder toBuilder()
public java.lang.String toString()
toString
in class java.lang.Object
public Section union(Section other) throws InvalidRangeException
other
- Section other sectionInvalidRangeException
- if want.getRank() not equal to this.getRank(), or invalid component Range