/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getDataType(), getShape()); MAMath.copy(newA, this); return newA; }
/** * Convert original array to desired type * * @param org original array * @param wantType desired type * @return converted data of desired type, or original array if it is already */ public static Array convert( Array org, DataType wantType) { if (org == null) return null; Class wantClass = wantType.getPrimitiveClassType(); if (org.getElementType().equals(wantClass)) return org; Array result = Array.factory(wantType, org.getShape()); copy(wantType, org.getIndexIterator(), result.getIndexIterator()); return result; }
/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getElementType(), getShape()); MAMath.copy(newA, this); newA.setUnsigned(isUnsigned()); return newA; }
/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getElementType(), getShape()); MAMath.copy(newA, this); newA.setUnsigned( isUnsigned()); return newA; }
/** * Convert original array to desired type * * @param org original array * @param wantType desired type * @return converted data of desired type, or original array if it is already */ public static Array convert( Array org, DataType wantType) { if (org == null) return null; Class wantClass = wantType.getPrimitiveClassType(); if (org.getElementType().equals(wantClass)) return org; Array result = Array.factory(wantType, org.getShape()); copy(wantType, org.getIndexIterator(), result.getIndexIterator()); return result; }
/** * Convert original array to desired type * * @param org original array * @param wantType desired type * @return converted data of desired type, or original array if it is already */ public static Array convert( Array org, DataType wantType) { if (org == null) return null; Class wantClass = wantType.getPrimitiveClassType(); if (org.getElementType().equals(wantClass)) return org; Array result = Array.factory(wantType, org.getShape()); copy(wantType, org.getIndexIterator(), result.getIndexIterator()); return result; }
@Override public Array copy() { Array newA = factory(getDataType(), getElementType(), isVlen(), Index.factory(getShape())); MAMath.copy(newA, this); return newA; }
/** * This gets the equivalent java array of the wanted type, in correct order. * It avoids copying if possible. * * @param wantType returned object will be an array of this type. This must be convertible to it. * @return java array of type want */ public Object get1DJavaArray(Class wantType) { if (wantType == getElementType()) { if (indexCalc.isFastIterator()) return getStorage(); // already in order else return copyTo1DJavaArray(); // gotta copy } // gotta convert to new type Array newA = factory(wantType, getShape()); MAMath.copy(newA, this); return newA.getStorage(); }
static private void extractSectionFromSequence(ParsedSectionSpec child, ArraySequence outerData, IndexIterator to) throws IOException, InvalidRangeException { try (StructureDataIterator sdataIter = outerData.getStructureDataIterator()) { while (sdataIter.hasNext()) { StructureData sdata = sdataIter.next(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); Array innerData = sdata.getArray(child.v.getShortName()); MAMath.copy(m.getDataType(), innerData.getIndexIterator(), to); } } }
/** * This gets the equivalent java array of the wanted type, in correct order. * It avoids copying if possible. * * @param wantType returned object will be an array of this type. This must be convertible to it. * @return java array of type want */ public Object get1DJavaArray(Class wantType) { if (wantType == getElementType()) { if (indexCalc.isFastIterator()) return getStorage(); // already in order else return copyTo1DJavaArray(); // gotta copy } // gotta convert to new type Array newA = factory(wantType, getShape()); MAMath.copy(newA, this); return newA.getStorage(); }
/** * This gets the equivalent java array of the wanted type, in correct order. * It avoids copying if possible. * * @param wantType returned object will be an array of this type. This must be convertible to it. * @return java array of type want */ public Object get1DJavaArray(DataType wantType) { if (wantType == getDataType()) { if (indexCalc.isFastIterator()) return getStorage(); // already in order else return copyTo1DJavaArray(); // gotta copy } // gotta convert to new type Array newA = factory(wantType, getShape()); MAMath.copy(newA, this); return newA.getStorage(); }
private ArrayDouble.D3 makeBoundsFromAux() { if (!computeIsInterval()) return null; Attribute boundsAtt = findAttributeIgnoreCase(CF.BOUNDS); if (boundsAtt == null) return null; String boundsVarName = boundsAtt.getStringValue(); VariableDS boundsVar = (VariableDS) ncd.findVariable(getParentGroup(), boundsVarName); Array data; try { //boundsVar.setUseNaNs(false); // missing values not allowed data = boundsVar.read(); } catch (IOException e) { log.warn("CoordinateAxis2D.makeBoundsFromAux read failed ", e); return null; } ArrayDouble.D3 bounds; assert (data.getRank() == 3) && (data.getShape()[2] == 2) : "incorrect shape data for variable " + boundsVar; if (data instanceof ArrayDouble.D3) { bounds = (ArrayDouble.D3) data; } else { bounds = (ArrayDouble.D3) Array.factory(DataType.DOUBLE, data.getShape()); MAMath.copy(data, bounds); } return bounds; }
private ArrayDouble.D3 makeBoundsFromAux() { if (!computeIsInterval()) return null; Attribute boundsAtt = findAttributeIgnoreCase(CF.BOUNDS); if (boundsAtt == null) return null; String boundsVarName = boundsAtt.getStringValue(); VariableDS boundsVar = (VariableDS) ncd.findVariable(getParentGroup(), boundsVarName); Array data; try { //boundsVar.setUseNaNs(false); // missing values not allowed data = boundsVar.read(); } catch (IOException e) { log.warn("CoordinateAxis2D.makeBoundsFromAux read failed ", e); return null; } ArrayDouble.D3 bounds; assert (data.getRank() == 3) && (data.getShape()[2] == 2) : "incorrect shape data for variable " + boundsVar; if (data instanceof ArrayDouble.D3) { bounds = (ArrayDouble.D3) data; } else { bounds = (ArrayDouble.D3) Array.factory(DataType.DOUBLE, data.getShape()); MAMath.copy(data, bounds); } return bounds; }
static private void extractSectionFromSequence(ParsedSectionSpec child, ArraySequence outerData, IndexIterator to) throws IOException, InvalidRangeException { StructureDataIterator sdataIter = outerData.getStructureDataIterator(); try { while (sdataIter.hasNext()) { StructureData sdata = sdataIter.next(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); Array innerData = sdata.getArray(child.v.getShortName()); MAMath.copy(m.getDataType(), innerData.getIndexIterator(), to); } } finally { sdataIter.finish(); } }
static private void extractSectionFromSequence(ParsedSectionSpec child, ArraySequence outerData, IndexIterator to) throws IOException, InvalidRangeException { StructureDataIterator sdataIter = outerData.getStructureDataIterator(); try { while (sdataIter.hasNext()) { StructureData sdata = sdataIter.next(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); Array innerData = sdata.getArray(child.v.getShortName()); MAMath.copy(m.getDataType(), innerData.getIndexIterator(), to); } } finally { sdataIter.finish(); } }
static private void extractSection(ParsedSectionSpec child, ArrayStructure outerData, IndexIterator to) throws IOException, InvalidRangeException { long wantNelems = child.section.computeSize(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); for (int recno = 0; recno < outerData.getSize(); recno++) { Array innerData = outerData.getArray(recno, m); if (child.child == null) { // inner variable if (wantNelems != innerData.getSize()) innerData = innerData.section(child.section.getRanges()); MAMath.copy(child.v.getDataType(), innerData.getIndexIterator(), to); } else { // not an inner variable - must be an ArrayStructure if (innerData instanceof ArraySequence) extractSectionFromSequence(child.child, (ArraySequence) innerData, to); else { if (wantNelems != innerData.getSize()) innerData = sectionArrayStructure(child, (ArrayStructure) innerData, m); extractSection(child.child, (ArrayStructure) innerData, to); } } } }
static private void extractSection(ParsedSectionSpec child, ArrayStructure outerData, IndexIterator to) throws IOException, InvalidRangeException { long wantNelems = child.section.computeSize(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); for (int recno = 0; recno < outerData.getSize(); recno++) { Array innerData = outerData.getArray(recno, m); if (child.child == null) { // inner variable if (wantNelems != innerData.getSize()) innerData = innerData.section(child.section.getRanges()); MAMath.copy(child.v.getDataType(), innerData.getIndexIterator(), to); } else { // not an inner variable - must be an ArrayStructure if (innerData instanceof ArraySequence) extractSectionFromSequence(child.child, (ArraySequence) innerData, to); else { if (wantNelems != innerData.getSize()) innerData = sectionArrayStructure(child, (ArrayStructure) innerData, m); extractSection(child.child, (ArrayStructure) innerData, to); } } } }
static private void extractSection(ParsedSectionSpec child, ArrayStructure outerData, IndexIterator to) throws IOException, InvalidRangeException { long wantNelems = child.section.computeSize(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); for (int recno = 0; recno < outerData.getSize(); recno++) { Array innerData = outerData.getArray(recno, m); if (child.child == null) { // inner variable if (wantNelems != innerData.getSize()) innerData = innerData.section(child.section.getRanges()); MAMath.copy(child.v.getDataType(), innerData.getIndexIterator(), to); } else { // not an inner variable - must be an ArrayStructure if (innerData instanceof ArraySequence) extractSectionFromSequence(child.child, (ArraySequence) innerData, to); else { if (wantNelems != innerData.getSize()) innerData = sectionArrayStructure(child, (ArrayStructure) innerData, m); extractSection(child.child, (ArrayStructure) innerData, to); } } } }
MAMath.copy(newData, data); v.setCachedData(newData, false);
MAMath.copy(newData, data); v.setCachedData(newData, false);