/** * Get the shape: length of array in each dimension. * * @return array whose length is the rank of this * Array and whose elements represent the length of each of its indices. */ public int[] getShape() { return indexCalc.getShape(); }
StringIterator() { if (rank == 0) strLen = 1; else strLen = indexCalc.getShape(rank - 1); carray = new char[strLen]; }
StringIterator() { if (rank == 0) strLen = 1; else strLen = indexCalc.getShape(rank - 1); carray = new char[strLen]; }
StringIterator() { if (rank == 0) strLen = 1; else strLen = indexCalc.getShape(rank - 1); carray = new char[strLen]; }
/** * Get the shape: length of array in each dimension. * * @return array whose length is the rank of this * Array and whose elements represent the length of each of its indices. */ public int[] getShape() { return indexCalc.getShape(); }
/** * Get the shape: length of array in each dimension. * * @return array whose length is the rank of this * Array and whose elements represent the length of each of its indices. */ public int[] getShape() { return indexCalc.getShape(); }
/** * Create a String out of this rank one ArrayChar object. * If there is a null (0) value in the ArrayChar array, the String will end there. * The null is not returned as part of the String. * * @return String value of CharArray * @throws IllegalArgumentException if rank != 1 */ public String getString() { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.getString rank must be 1"); int strLen = indexCalc.getShape(0); int count = 0; for (int k = 0; k < strLen; k++) { if (0 == storage[k]) break; count++; } return new String(storage, 0, count); }
/** * Set the ArrayChar values from the characters in the String. Rank must be 1. * If String longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * * @param val set characters from this String * @throws IllegalArgumentException if rank != 2 */ public void setString(String val) { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.setString rank must be 1"); int arrayLen = indexCalc.getShape(0); int strLen = Math.min(val.length(), arrayLen); for (int k = 0; k < strLen; k++) storage[k] = val.charAt(k); char c = 0; for (int k = strLen; k < arrayLen; k++) storage[k] = c; }
/** * Set the ArrayChar values from the characters in the String. Rank must be 1. * If String longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * * @param val set characters from this String * @throws IllegalArgumentException if rank != 2 */ public void setString(String val) { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.setString rank must be 1"); int arrayLen = indexCalc.getShape(0); int strLen = Math.min(val.length(), arrayLen); for (int k = 0; k < strLen; k++) storage[k] = val.charAt(k); char c = 0; for (int k = strLen; k < arrayLen; k++) storage[k] = c; }
/** * Set the ArrayChar values from the characters in the String. Rank must be 1. * If String longer than ArrayChar, ignore extra chars; if shorter, fill with 0. * * @param val set characters from this String * @throws IllegalArgumentException if rank != 2 */ public void setString(String val) { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.setString rank must be 1"); int arrayLen = indexCalc.getShape(0); int strLen = Math.min(val.length(), arrayLen); for (int k = 0; k < strLen; k++) storage[k] = val.charAt(k); char c = 0; for (int k = strLen; k < arrayLen; k++) storage[k] = c; }
/** * Create a String out of this rank one ArrayChar object. * If there is a null (0) value in the ArrayChar array, the String will end there. * The null is not returned as part of the String. * * @return String value of CharArray * @throws IllegalArgumentException if rank != 1 */ public String getString() { int rank = getRank(); if (rank != 1) throw new IllegalArgumentException("ArayChar.getString rank must be 1"); int strLen = indexCalc.getShape(0); int count = 0; for (int k = 0; k < strLen; k++) { if (0 == storage[k]) break; count++; } return new String(storage, 0, count); }
/** * Create a String out of this rank one ArrayChar object. * If there is a null (0) value in the ArrayChar array, the String will end there. * The null is not returned as part of the String. * * @return String value of CharArray * @throws IllegalArgumentException if rank != 1 */ public String getString() { int rank = getRank(); if (rank == 0) { return new String(storage); } if (rank != 1) throw new IllegalArgumentException("ArayChar.getString rank must be 1"); int strLen = indexCalc.getShape(0); int count = 0; for (int k = 0; k < strLen; k++) { if (0 == storage[k]) break; count++; } return new String(storage, 0, count); }
public void testSection() { Index ima = secA.getIndex(); int [] shape = ima.getShape(); //System.out.println(ima); assert( ima.getRank() == 3); assert( ima.getSize() == (mlen * n * p)); assert( shape[0] == mlen); assert( shape[1] == n); assert( shape[2] == p); }
/** * Make this into the equivilent 1D ArrayObject of Strings. * * @return 1D ArrayObject of Strings */ public ArrayObject make1DStringArray() { int nelems = (getRank() == 0) ? 1 : (int) getSize() / indexCalc.getShape(getRank()-1); Array sarr = Array.factory(DataType.STRING, new int[]{nelems}); IndexIterator newsiter = sarr.getIndexIterator(); ArrayChar.StringIterator siter = getStringIterator(); while (siter.hasNext()) { newsiter.setObjectNext(siter.next()); } return (ArrayObject) sarr; }
/** * Make this into the equivilent 1D ArrayObject of Strings. * * @return 1D ArrayObject of Strings */ public ArrayObject make1DStringArray() { int nelems = (getRank() == 0) ? 1 : (int) getSize() / indexCalc.getShape(getRank()-1); Array sarr = Array.factory(String.class, new int[]{nelems}); IndexIterator newsiter = sarr.getIndexIterator(); ArrayChar.StringIterator siter = getStringIterator(); while (siter.hasNext()) { newsiter.setObjectNext(siter.next()); } return (ArrayObject) sarr; }
/** * Make this into the equivilent 1D ArrayObject of Strings. * * @return 1D ArrayObject of Strings */ public ArrayObject make1DStringArray() { int nelems = (getRank() == 0) ? 1 : (int) getSize() / indexCalc.getShape(getRank()-1); Array sarr = Array.factory(String.class, new int[]{nelems}); IndexIterator newsiter = sarr.getIndexIterator(); ArrayChar.StringIterator siter = getStringIterator(); while (siter.hasNext()) { newsiter.setObjectNext(siter.next()); } return (ArrayObject) sarr; }
public void testRange3() throws InvalidRangeException { ArrayDouble secA2 = (ArrayDouble) A.section( new Section(1+":"+(m-2)+",0:"+(n-2)+",1:"+(p-1)).getRanges() ); Index imaOrg = A.getIndex(); Index ima = secA2.getIndex(); int [] shape = ima.getShape(); assert( ima.getRank() == 3); assert( ima.getSize() == (m-2)*(n-1)*(p-1)); assert( shape[0] == m-2); assert( shape[1] == n-1); assert( shape[2] == p-1); for (i=0; i<m-2; i++) { for (j=0; j<n-1; j++) { for (k=0; k<p-1; k++) { ima.set(i,j); double val = secA2.getDouble(ima.set(i,j,k)); double valOrg = A.getDouble(imaOrg.set(i+1,j,k+1)); //System.out.println("testSectionRange read1 = "+ val); assert (val == valOrg); } } } System.out.println("testRange 3"); }
public void testDoubleRange() throws InvalidRangeException { ArrayDouble secA2 = (ArrayDouble) A.section( new Section("2,:,:").getRanges() ); ArrayDouble secA1 = (ArrayDouble) secA2.section( new Section(":,1").getRanges() ); Index ima = secA1.getIndex(); int [] shape = ima.getShape(); assert( ima.getRank() == 1); assert( ima.getSize() == n); assert( shape[0] == n); for (j=0; j<n; j++) { ima.set(j); double val = secA1.getDouble(ima); //System.out.println("testDoubleRange read1 = "+ val); assert (val == 200+j*10+1); } IndexIterator iter = secA1.getIndexIterator(); for (i=0; i<n; i++) { double val = iter.getDoubleNext(); //double myVal = (double) (i+m1)*100+j*10+k; //System.out.println(val+ " "+myVal); //System.out.println("testDoubleRange read2 = "+ val); assert (val == 200+i*10+1); } System.out.println("testDoubleRange"); }
public void testDoubleRange2() throws InvalidRangeException { ArrayDouble secA2 = (ArrayDouble) A.section( new Section("2,:,:").getRanges() ); secA2 = (ArrayDouble) secA2.reduce(); ArrayDouble secA1 = (ArrayDouble) secA2.section( new Section(":,1").getRanges() ); Index ima = secA1.getIndex(); int [] shape = ima.getShape(); assert( ima.getRank() == 1); assert( ima.getSize() == n); assert( shape[0] == n); for (j=0; j<n; j++) { ima.set(j); double val = secA1.getDouble(ima); //System.out.println("testDoubleRange read1 = "+ val); assert (val == 200+j*10+1); } IndexIterator iter = secA1.getIndexIterator(); for (i=0; i<n; i++) { double val = iter.getDoubleNext(); //double myVal = (double) (i+m1)*100+j*10+k; //System.out.println(val+ " "+myVal); //System.out.println("testDoubleRange read2 = "+ val); assert (val == 200+i*10+1); } System.out.println("testDoubleRange 2"); }
public void testSectionCopy() throws InvalidRangeException { ArrayDouble secA2 = (ArrayDouble) A.section( new Section(1+":"+(m-2)+",0:"+(n-2)+",1:"+(p-1)).getRanges() ).copy(); Index imaOrg = A.getIndex(); Index ima = secA2.getIndex(); int [] shape = ima.getShape(); assert( ima.getRank() == 3); assert( ima.getSize() == (m-2)*(n-1)*(p-1)); assert( shape[0] == m-2); assert( shape[1] == n-1); assert( shape[2] == p-1); assert( secA2 instanceof ArrayDouble.D3); for (i=0; i<m-2; i++) { for (j=0; j<n-1; j++) { for (k=0; k<p-1; k++) { ima.set(i,j); double val = secA2.getDouble(ima.set(i,j,k)); secA2.setDouble(ima, 0.0); double valOrg = A.getDouble(imaOrg.set(i+1,j,k+1)); //System.out.println("testSectionRange read1 = "+ val); assert (val == valOrg); } } } System.out.println("test sectionCopy"); }