public class Section extends Object
| Modifier and Type | Class and Description |
|---|---|
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(List<Range> from)
Create Section from a List
|
Section(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(String sectionSpec)
Parse an index section String specification, return equivilent Section.
|
| Modifier and Type | Method and Description |
|---|---|
Section |
addRangeNames(List<String> rangeNames) |
Section |
appendRange()
Append a null Range to the Section - meaning "all"
|
Section |
appendRange(int size)
Append a new Range(0,size-1) to the Section
|
Section |
appendRange(int first,
int last)
Append a new Range(first, last) to the Section
|
Section |
appendRange(int first,
int last,
int stride)
Append a new Range(first,last,stride) to the Section
|
Section |
appendRange(Range r)
Append a Range to the Section
|
Section |
appendRange(String name,
int first,
int last,
int stride)
Append a new Range(name,first,last,stride) to the Section
|
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 reletive 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(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(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
|
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)
Insert a range at the specified index in the list.
|
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(List<RangeIterator> rangeIter) |
Section |
makeImmutable()
Makes the object immutable, so can be safely shared
|
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() |
Section |
removeRange(int index)
Remove a range at the specified index in the list.
|
Section |
removeVlen() |
Section |
replaceRange(int index,
Range r)
Replace a range at the specified index in the list.
|
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)
Set the range at the specified index in the list, previous Range is discarded
|
Section |
shiftOrigin(int[] newOrigin) |
Section |
shiftOrigin(Section newOrigin)
Create a new Section by shifting each range by newOrigin.first()
The result is then a reletive offset from the newOrigin.
|
String |
show() |
Section |
subSection(int fromIndex,
int endExclusive) |
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(List<Range> from)
from - the list of Rangepublic Section(Range... ranges)
ranges - the listpublic Section(Section from)
from - the Section to copypublic Section(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(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 illegalIllegalArgumentException - 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(List<RangeIterator> rangeIter)
public Section compact() throws InvalidRangeException
InvalidRangeException - elements must be nonnegative, 0 <= first <= lastpublic Section compose(Section want) throws InvalidRangeException
want - Section reletive 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 subrangeInvalidRangeExceptionpublic 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
InvalidRangeExceptionpublic 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 String toString()
public String show()
public Section appendRange()
public Section appendRange(int size)
size - add this Rangepublic Section appendRange(int first, int last) throws InvalidRangeException
first - starting indexlast - last index, inclusiveInvalidRangeException - if last < firstpublic Section appendRange(int first, int last, int stride) throws InvalidRangeException
first - starting indexlast - last index, inclusivestride - strideInvalidRangeException - if last < firstpublic Section appendRange(String name, int first, int last, int stride) throws InvalidRangeException
name - name of Rangefirst - starting indexlast - last index, inclusivestride - strideInvalidRangeException - if last < firstpublic 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 RangeIndexOutOfBoundsException - if bad indexpublic Section removeRange(int index)
index - remove here in the list, existing ranges after this index get shifted by oneIndexOutOfBoundsException - if bad indexpublic Section setRange(int index, Range r)
index - list index, must be in interval [0,size).r - insert this RangeIndexOutOfBoundsException - if bad indexpublic Section replaceRange(int index, Range r)
index - replace here in the list.r - use this RangeIndexOutOfBoundsException - 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 wrongpublic Section makeImmutable()
public Section subSection(int fromIndex, int endExclusive)
public Section removeLast()
public Section removeVlen()
public boolean isImmutable()
public boolean isVariableLength()
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 Range getRange(int i)
i - index into the list of Rangespublic Range find(String rangeName)
rangeName - find this Rangepublic Section addRangeNames(List<String> rangeNames) throws InvalidRangeException
InvalidRangeExceptionpublic 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(Object o)
public int hashCode()
public Section.Iterator getIterator(int[] shape)
shape - total array shape