protected Array(DataType dataType, int[] shape) { this.dataType = dataType; this.rank = shape.length; this.indexCalc = Index.factory(shape); }
protected Array(int[] shape) { rank = shape.length; indexCalc = Index.factory(shape); this.sort = computesort(); }
/** * Generate new Array with given type and shape and zeroed storage. * * @param classType element Class type, eg double.class. * @param shape shape of the array. * @return new Array<type> or Array<type>.D<rank> if 0 <= rank <= 7. */ static public Array factory(Class classType, int[] shape) { Index index = Index.factory(shape); return factory(classType, index); }
/** * Generate new Array with given dataType, shape, storage. * * @param dataType DataType, eg DataType.DOUBLE. * @param shape shape of the array. * @param storage primitive array of correct type * @return new Array<type> or Array<type>.D<rank> if 0 <= rank <= 7. * @throws ClassCastException wrong storage type */ static public Array factory(DataType dataType, int[] shape, Object storage) { return factory(dataType, Index.factory(shape), storage); }
/** * Generate new Array with given type and shape and zeroed storage. * * @param classType element Class type, eg double.class. * @param shape shape of the array. * @return new Array<type> or Array<type>.D<rank> if 0 <= rank <= 7. */ static public Array factory(Class classType, int[] shape) { Index index = Index.factory(shape); return factory(classType, index); }
protected Array(int[] shape) { rank = shape.length; indexCalc = Index.factory(shape); this.datatype = computesort(); }
/** * Generate new Array with given dataType and shape and zeroed storage. * * @param dataType instance of DataType. * @param shape shape of the array. * @return new Array<type> or Array<type>.D<rank> if 0 <= rank <= 7. */ static public Array factory(DataType dataType, int[] shape) { return factory(dataType, Index.factory(shape), null); }
/** * Generate new Array with given type, shape, storage. * This should be package private, but is exposed for efficiency. * Normally use factory( Class classType, int [] shape) instead. * storage must be 1D array of type classType. * storage.length must equal product of shapes * storage data needs to be in canonical order * * @param classType element class type, eg double.class. Corresponding Object types like Double.class are * mapped to double.class. Any reference types use ArrayObject. * @param shape array shape * @param storage 1D java array of type classType, except object types like Double.class are mapped to * their corresponding primitive type, eg double.class. * @return Array of given type, shape and storage * @throws IllegalArgumentException storage.length != product of shapes * @throws ClassCastException wrong storage type */ static public Array factory(Class classType, int[] shape, Object storage) { Index indexCalc = Index.factory(shape); return factory(classType, indexCalc, storage); }
/** * Make a vlen array * @param shape the outer shape, ie excluding the vlen dimension * @param storage must be an Array type. must not be null * @return ArrayObject */ static public Array makeVlenArray(int[] shape, @Nonnull Array[] storage) { Index index = Index.factory(shape); return ArrayObject.factory(storage[0].getDataType(), storage[0].getClass(), true, index, storage); }
/** * Generate new Array with given type, shape, storage. * This should be package private, but is exposed for efficiency. * Normally use factory( Class classType, int [] shape) instead. * storage must be 1D array of type classType. * storage.length must equal product of shapes * storage data needs to be in canonical order * * @param classType element class type, eg double.class. Corresponding Object types like Double.class are * mapped to double.class. Any reference types use ArrayObject. * @param shape array shape * @param storage 1D java array of type classType, except object types like Double.class are mapped to * their corresponding primitive type, eg double.class. * @return Array of given type, shape and storage * @throws IllegalArgumentException storage.length != product of shapes * @throws ClassCastException wrong storage type */ static public Array factory(Class classType, int[] shape, Object storage) { Index indexCalc = Index.factory(shape); return factory(classType, indexCalc, storage); }
/** * Generate new Array with given type, shape, storage. * This should be package private, but is exposed for efficiency. * Normally use factory( Class classType, int [] shape) instead. * storage must be 1D array of type classType. * storage.length must equal product of shapes * storage data needs to be in canonical order * * @param classType element class type, eg double.class. Corresponding Object types like Double.class are * mapped to double.class. Any reference types use ArrayObject. * @param shape array shape * @param storage 1D java array of type classType, except object types like Double.class are mapped to * their corresponding primitive type, eg double.class. * @return Array of given type, shape and storage * @throws IllegalArgumentException storage.length != product of shapes * @throws ClassCastException wrong storage type */ static public Array makeObjectArray(DataType dtype, Class classType, int[] shape, Object storage) { Index index = Index.factory(shape); return ArrayObject.factory(dtype, classType, false, index, (Object[]) storage); }
/** * Generate new Array with given type and shape and zeroed storage. * * @param dataType instance of DataType. * @param shape shape of the array. * @return new Array<type> or Array<type>.D<rank> if 0 <= rank <= 7. */ static public Array factory(DataType dataType, int[] shape) { Index index = Index.factory(shape); return factory(dataType.getPrimitiveClassType(), index); }
public int[] getCurrentCounter() { if (counter == null) // or counter == "" ? counter = Index.factory(maa.getShape()); counter.setCurrentCounter( currElement); return counter.current; }
/** * Generate new Array with given type and shape and zeroed storage. * * @param dataType instance of DataType. * @param shape shape of the array. * @return new Array<type> or Array<type>.D<rank> if 0 <= rank <= 7. */ static public Array factory(DataType dataType, int[] shape) { Index index = Index.factory(shape); return factory(dataType.getPrimitiveClassType(), index); }
public int[] getCurrentCounter() { if (counter == null) // or counter == "" ? counter = Index.factory(maa.getShape()); counter.setCurrentCounter( currElement); return counter.current; }
public String toString() { if (counter == null || counter.toString().equals("")) // not sure about the second condition counter = Index.factory(maa.getShape()); counter.setCurrentCounter( currElement); return counter.toString(); }
public String toString() { if (counter == null || counter.toString().equals("")) // not sure about the second condition counter = Index.factory(maa.getShape()); counter.setCurrentCounter( currElement); return counter.toString(); }
@Override public Array copy() { Array newA = factory(getDataType(), getElementType(), isVlen(), Index.factory(getShape())); MAMath.copy(newA, this); return newA; }
@Test public void testDataValues() throws IOException { Array valuesScan = varScan.read(); Array valuesExplicit = varExplicit.read(); List<int[]> idxs = new ArrayList<>(); idxs.add(new int[]{0, 0, 0, 0, 0}); idxs.add(new int[]{2, 20, 5, 38, 44}); idxs.add(new int[]{1, 10, 3, 19, 22}); Index idx = Index.factory(valuesScan.getShape()); for (int[] loc : idxs) { idx.set(loc); float a = valuesScan.getFloat(idx); float b = valuesExplicit.getFloat(idx); Assert.assertEquals(a, b, 0); } }
/** * Use this when this is a one dimensional array of Structures, or you are doing the index calculation yourself for * a multidimension array. This will read only the ith structure, and return the data as a StructureData object. * @param index index into 1D array * @return ith StructureData * @throws java.io.IOException on read error * @throws ucar.ma2.InvalidRangeException if index out of range */ public StructureData readStructure(int index) throws IOException, ucar.ma2.InvalidRangeException { Section section = null; // works for scalars i think if (getRank() == 1) { section = new Section().appendRange(index,index); } else if (getRank() > 1) { Index ii = Index.factory(shape); // convert to nD index ii.setCurrentCounter(index); int[] origin = ii.getCurrentCounter(); section = new Section(); for (int i=0;i<origin.length;i++) section.appendRange(origin[i], origin[i]); } Array dataArray = read(section); ArrayStructure data = (ArrayStructure) dataArray; return data.getStructureData(0); }