/** * Copy Constructor. * Returned copy is mutable * * @param from the Section to copy */ public Section(Section from) { list = new ArrayList<Range>(from.getRanges()); }
/** * Copy Constructor. * Returned copy is mutable * * @param from the Section to copy */ public Section(Section from) { list = new ArrayList<>(from.getRanges()); }
public SectionIterable(Section section, int[] fullShape) { this.ranges = new ArrayList<>(); for (Range r : section.getRanges()) this.ranges.add(r); this.fullShape = fullShape; }
/** * Get shape as an List of Range objects. * The List is immutable. * * @return List of Ranges, one for each Dimension. */ public List<Range> getRanges() { return getShapeAsSection().getRanges(); }
/** * Get shape as an List of Range objects. * The List is immutable. * @return List of Ranges, one for each Dimension. */ public List<Range> getRanges() { return getShapeAsSection().getRanges(); }
private boolean isTiled(Variable v) { for (Dimension d : v.getDimensions()) { for (Range r : section.getRanges()) { if (d.getShortName().equals(r.getName())) return true; } } return false; }
private boolean isTiled(Variable v) { for (Dimension d : v.getDimensions()) { for (Range r : section.getRanges()) { if (d.getShortName().equals(r.getName())) return true; } } return false; }
public Section addRangeNames(List<String> rangeNames) throws InvalidRangeException { if (rangeNames.size() != getRank()) throw new InvalidRangeException("Invalid number of Range Names"); int count = 0; Section result = new Section(); for (Range r : getRanges()) { Range nr = new Range(rangeNames.get(count++), r); result.appendRange(nr); } return result; }
public Section addRangeNames(List<String> rangeNames) throws InvalidRangeException { if (rangeNames.size() != getRank()) throw new InvalidRangeException("Invalid number of Range Names"); int count = 0; Section result = new Section(); for (Range r : getRanges()) { Range nr = r.setName(rangeNames.get(count++)); result.appendRange(nr); } return result; }
@Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { Section orgSection = new Section(section.getRanges()); orgSection.insertRange(sliceDim, slice.getRange(sliceDim)); Array data = orgClient._read( orgSection); data = data.reduce( sliceDim); return data; }
Section makeVarSection(Variable mainv) { Section vSection = mainv.getShapeAsSection(); Section dataSection = new Section(); for (Range r : vSection.getRanges()) { Range rr = section.find(r.getName()); dataSection.appendRange(rr != null ? rr : r); } return dataSection; } }
@Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { Section orgSection = new Section(section.getRanges()); orgSection.insertRange(sliceDim, slice.getRange(sliceDim)); Array data = orgClient._read( orgSection); data = data.reduce( sliceDim); return data; }
Section makeVarSection(Variable mainv) { Section vSection = mainv.getShapeAsSection(); Section dataSection = new Section(); for (Range r : vSection.getRanges()) { Range rr = section.find(r.getName()); dataSection.appendRange(rr != null ? rr : r); } return dataSection; } }
@Test public void testSectionIterator() throws InvalidRangeException, IOException { Array data = A; Section section = new Section("1,:,:"); Array datasection = data.sectionNoReduce(section.getRanges()); double sum = MAMath.sumDouble(datasection); assert sum == 663.0; }
static public NcStreamProto.Section encodeSection(Section section) { NcStreamProto.Section.Builder sbuilder = NcStreamProto.Section.newBuilder(); for (Range r : section.getRanges()) { NcStreamProto.Range.Builder rbuilder = NcStreamProto.Range.newBuilder(); if (r.first() != 0) rbuilder.setStart(r.first()); rbuilder.setSize(r.length()); if (r.stride() != 1) rbuilder.setStride(r.stride()); sbuilder.addRange(rbuilder); } return sbuilder.build(); }
static public NcStreamProto.Section encodeSection(Section section) { NcStreamProto.Section.Builder sbuilder = NcStreamProto.Section.newBuilder(); for (Range r : section.getRanges()) { NcStreamProto.Range.Builder rbuilder = NcStreamProto.Range.newBuilder(); if (r.first() != 0) rbuilder.setStart(r.first()); rbuilder.setSize(r.length()); if (r.stride() != 1) rbuilder.setStride(r.stride()); sbuilder.addRange(rbuilder); } return sbuilder.build(); }
private static Section randomSubset(Section all, int stride) throws InvalidRangeException { Section s = new Section(); for (Range r : all.getRanges()) { int first = random(r.first(), r.last() / 2); int last = random(r.last() / 2, r.last()); s.appendRange(first, last, stride); } return s; }
@Test public void testArrayObjectIter() throws InvalidRangeException { Array arrayObject = Array.factory(DataType.OPAQUE, new int[] {30}); testArrayObjectIter(arrayObject, 30); Array arrayObjectSubset = arrayObject.sectionNoReduce(new Section("1:20").getRanges()); // subset it testArrayObjectIter(arrayObjectSubset, 20); Array arrayObjectSubsetCopy = arrayObjectSubset.copy(); testArrayObjectIter(arrayObjectSubsetCopy, 20); }
public void testStride(String stride) throws IOException, InvalidRangeException { Variable time = ncfile.findVariable("time"); ArrayInt all = (ArrayInt) time.read(); ArrayInt correct = (ArrayInt) all.section(new Section(stride).getRanges()); logger.debug("correct({}) {}", stride, NCdumpW.toString(correct)); ArrayInt data = (ArrayInt) time.read(stride); logger.debug("data({}) {}", stride, NCdumpW.toString(data)); Index ci = correct.getIndex(); Index di = data.getIndex(); for (int i=0; i<data.getSize(); i++) assert (data.getInt(di.set(i)) == correct.getInt(ci.set(i))) : stride +" index " + i + " = " + data.getInt(di.set(i)) +" != "+ correct.getInt(ci.set(i)); }