类 Section


  • public class Section
    extends Object
    A section of multidimensional array indices. Represented as List. Immutable if makeImmutable() was called.
    作者:
    caron
    • 嵌套类概要

      嵌套类 
      修饰符和类型 说明
      class  Section.Iterator  
    • 构造器概要

      构造器 
      构造器 说明
      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​(String sectionSpec)
      Parse an index section String specification, return equivilent Section.
      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

        public Section​(int[] shape)
        Create Section from a shape array, assumes 0 origin.
        参数:
        shape - array of lengths for each Range. 0 = EMPTY, < 0 = VLEN
      • Section

        public Section​(int[] origin,
                       int[] shape)
                throws InvalidRangeException
        Create Section from a shape and origin arrays.
        参数:
        origin - array of start for each Range
        shape - array of lengths for each Range
        抛出:
        InvalidRangeException - if origin < 0, or shape < 1.
      • Section

        public Section​(int[] origin,
                       int[] size,
                       int[] stride)
                throws InvalidRangeException
        Create Section from a shape, origin, and stride arrays.
        参数:
        origin - array of start for each Range
        size - array of lengths for each Range (last = origin + size -1)
        stride - stride between consecutive elements, must be > 0
        抛出:
        InvalidRangeException - if origin < 0, or shape < 1.
      • Section

        public Section​(List<Range> from)
        Create Section from a List.
        参数:
        from - the list of Range
      • Section

        public Section​(Range... ranges)
        Create Section from a variable length list of Ranges
        参数:
        ranges - the list
      • Section

        public Section​(Section from)
        Copy Constructor. Returned copy is mutable
        参数:
        from - the Section to copy
      • Section

        public Section​(List<Range> from,
                       int[] shape)
                throws InvalidRangeException
        Create Section from a List.
        参数:
        from - the list of Range
        shape - use this as default shape if any of the ranges are null.
        抛出:
        InvalidRangeException - if shape and range list done match
      • Section

        public Section​(String sectionSpec)
                throws InvalidRangeException
        Parse an index section String specification, return equivilent Section. A null Range means "all" (i.e.":") indices in that dimension.

        The sectionSpec string uses fortran90 array section syntax, namely:

           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 optional
        抛出:
        InvalidRangeException - when the Range is illegal
        IllegalArgumentException - when sectionSpec is misformed
      • Section

        public Section()
        No-arg Constructor
    • 方法详细资料

      • fill

        public static Section fill​(Section s,
                                   int[] shape)
                            throws InvalidRangeException
        Return a Section guaranteed to be non null, with no null Ranges, and within the bounds set by shape. A section with no nulls is called "filled". If s is already filled, return it, otherwise return a new Section, filled from the shape.
        参数:
        s - the original Section, may be null or not filled
        shape - use this as default shape if any of the ranges are null.
        返回:
        a filled Section
        抛出:
        InvalidRangeException - if shape and s and shape rank dont match, or if s has invalid range compared to shape
      • compact

        public Section compact()
                        throws InvalidRangeException
        Create a new Section by compacting each Range. first = first/stride, last=last/stride, stride=1.
        返回:
        compacted Section
        抛出:
        InvalidRangeException - elements must be nonnegative, 0 <= first <= last
      • removeVlen

        public Section removeVlen()
                           throws InvalidRangeException
        Create a new Section by compacting each Range. first = first/stride, last=last/stride, stride=1.
        返回:
        compacted Section
        抛出:
        InvalidRangeException - elements must be nonnegative, 0 <= first <= last
      • compose

        public Section compose​(Section want)
                        throws InvalidRangeException
        Create a new Section by composing with a Section that is reletive to this Section.
        参数:
        want - Section reletive to this one. If null, return this. If individual ranges are null, use corresponding Range in this.
        返回:
        new Section, composed
        抛出:
        InvalidRangeException - if want.getRank() not equal to this.getRank(), or invalid component Range
      • intersect

        public Section intersect​(Section other)
                          throws InvalidRangeException
        Create a new Section by intersection with another Section
        参数:
        other - Section other section
        返回:
        new Section, composed
        抛出:
        InvalidRangeException - if want.getRank() not equal to this.getRank(), or invalid component Range
      • union

        public Section union​(Section other)
                      throws InvalidRangeException
        Create a new Section by union with another Section
        参数:
        other - Section other section
        返回:
        new Section, union of the two
        抛出:
        InvalidRangeException - if want.getRank() not equal to this.getRank(), or invalid component Range
      • shiftOrigin

        public Section shiftOrigin​(Section newOrigin)
                            throws InvalidRangeException
        Create a new Section by shifting each range by newOrigin.first() The result is then a reletive offset from the newOrigin.
        参数:
        newOrigin - this becomes the origin of the result
        返回:
        new Section, shifted
        抛出:
        InvalidRangeException - if want.getRank() not equal to this.getRank()
      • intersects

        public boolean intersects​(Section other)
                           throws InvalidRangeException
        See if this Section intersects with another Section. ignores strides
        参数:
        other - another section
        返回:
        true if intersection is non-empty
        抛出:
        InvalidRangeException - if want.getRank() not equal to this.getRank(), ignoring vlen
      • contains

        public boolean contains​(Section other)
        See if this Section contains another Section. ignores strides Must have same rank and last >= other.last.
        参数:
        other - another section
        返回:
        true if its a subset
      • toString

        public String toString()
        Convert List of Ranges to String Spec. Inverse of new Section(String sectionSpec)
        覆盖:
        toString 在类中 Object
        返回:
        index section String specification
      • appendRange

        public Section appendRange()
        Append a null Range to the Section - meaning "all"
        返回:
        this
      • appendRange

        public Section appendRange​(Range r)
        Append a Range to the Section
        返回:
        this
      • appendRange

        public Section appendRange​(int first,
                                   int last)
                            throws InvalidRangeException
        Append a new Range(first, last) to the Section
        参数:
        first - starting index
        last - last index, inclusive
        返回:
        this
        抛出:
        InvalidRangeException - if last < first
      • appendRange

        public Section appendRange​(int first,
                                   int last,
                                   int stride)
                            throws InvalidRangeException
        Append a new Range(first,last,stride) to the Section
        参数:
        first - starting index
        last - last index, inclusive
        stride - stride
        返回:
        this
        抛出:
        InvalidRangeException - if last < first
      • appendRange

        public Section appendRange​(String name,
                                   int first,
                                   int last,
                                   int stride)
                            throws InvalidRangeException
        Append a new Range(name,first,last,stride) to the Section
        参数:
        name - name of Range
        first - starting index
        last - last index, inclusive
        stride - stride
        返回:
        this
        抛出:
        InvalidRangeException - if last < first
      • insertRange

        public Section insertRange​(int index,
                                   Range r)
        Insert a range at the specified index in the list.
        参数:
        index - insert here in the list, existing ranges at or after this index get shifted by one
        r - insert this Range
        返回:
        this
        抛出:
        IndexOutOfBoundsException - if bad index
      • removeRange

        public Section removeRange​(int index)
        Remove a range at the specified index in the list.
        参数:
        index - remove here in the list, existing ranges after this index get shifted by one
        返回:
        this
        抛出:
        IndexOutOfBoundsException - if bad index
      • setRange

        public Section setRange​(int index,
                                Range r)
        Set the range at the specified index in the list, previous Range is discarded
        参数:
        index - list index, must be in interval [0,size).
        r - insert this Range
        返回:
        this
        抛出:
        IndexOutOfBoundsException - if bad index
      • replaceRange

        public Section replaceRange​(int index,
                                    Range r)
        Replace a range at the specified index in the list.
        参数:
        index - replace here in the list.
        r - use this Range
        返回:
        this
        抛出:
        IndexOutOfBoundsException - if bad index
      • reduce

        public Section reduce()
        Remove any ranges of length 1
        返回:
        new Section if any Range had length 1, else this
      • subSection

        public Section subSection​(int from,
                                  int endExclusive)
      • setDefaults

        public void setDefaults​(int[] shape)
                         throws InvalidRangeException
        If any of the ranges are null, which means "all", set the Range from the corresponding length in shape[].
        参数:
        shape - default length for each Range; must have matching rank.
        抛出:
        InvalidRangeException - if rank is wrong
      • makeImmutable

        public Section makeImmutable()
        Makes the object immutable, so can be safely shared
        返回:
        this Section
      • isImmutable

        public boolean isImmutable()
      • isVariableLength

        public boolean isVariableLength()
      • isStrided

        public boolean isStrided()
      • getShape

        public int[] getShape()
        Get shape array using the Range.length() values.
        返回:
        int[] shape
      • getOrigin

        public int[] getOrigin()
        Get origin array using the Range.first() values.
        返回:
        int[] origin
      • getStride

        public int[] getStride()
        Get stride array using the Range.stride() values.
        返回:
        int[] origin
      • getOrigin

        public int getOrigin​(int i)
        Get origin of the ith Range
        参数:
        i - index of Range
        返回:
        origin of ith Range
      • getShape

        public int getShape​(int i)
        Get length of the ith Range
        参数:
        i - index of Range
        返回:
        length of ith Range
      • getStride

        public int getStride​(int i)
        Get stride of the ith Range
        参数:
        i - index of Range
        返回:
        stride of ith Range
      • getRank

        public int getRank()
        Get rank - number of Ranges.
        返回:
        rank
      • getVlenRank

        public int getVlenRank()
        Get rank excluding vlens.
        返回:
        rank
      • compatibleRank

        public boolean compatibleRank​(Section other)
        Compare this section with another upto the vlen in either
      • computeSize

        public long computeSize()
        Compute total number of elements represented by the section. Any VLEN Ranges are effectively skipped.
        返回:
        total number of elements
      • getRanges

        public List<Range> getRanges()
        Get the list of Ranges.
        返回:
        the List
      • getRange

        public Range getRange​(int i)
        Get the ith Range
        参数:
        i - index into the list of Ranges
        返回:
        ith Range
      • find

        public Range find​(String rangeName)
        Find a Range by its name.
        参数:
        rangeName - find this Range
        返回:
        named Range or null
      • checkInRange

        public String checkInRange​(int[] shape)
        Check if this Section is legal for the given shape. [Note: modified by dmh to address the case of unlimited where the size is zero]
        参数:
        shape - range must fit within this shape, rank must match.
        返回:
        error message if illegal, null if all ok
      • equivalent

        public boolean equivalent​(int[] shape)
                           throws InvalidRangeException
        Is this section equivilent to the given shape. All non-null ranges must have origin 0 and length = shape[i]
        参数:
        shape - the given shape.
        返回:
        true if equivilent
        抛出:
        InvalidRangeException - if setion rank doesnt match shape length
      • equals

        public boolean equals​(Object o)
        Sections with equals Ranges are equal.
        覆盖:
        equals 在类中 Object
      • hashCode

        public int hashCode()
        Override Object.hashCode() to agree with equals.
        覆盖:
        hashCode 在类中 Object
      • getIterator

        public 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[]. The index is in the "source" array.
        参数:
        shape - total array shape
        返回:
        iterator over this section