|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectucar.nc2.iosp.IndexChunker
public class IndexChunker
Iterator to read/write subsets of a multidimensional array, finding the contiguous chunks. The iteration is monotonic in both src and dest positions.
Example for Integers:int[] read( IndexChunker index, int[] src) { int[] dest = new int[index.getTotalNelems()]; while (index.hasNext()) { Indexer2.Chunk chunk = index.next(); System.arraycopy(src, chunk.getSrcElem(), dest, chunk.getDestElem(), chunk.getNelems()); } return dest; } int[] read( IndexChunker index, RandomAccessFile raf, long start_pos) { int[] dest = new int[index.getTotalNelems()]; while (index.hasNext()) { Indexer2.Chunk chunk = index.next(); raf.seek( start_pos + chunk.getSrcElem() * 4); raf.readInt(dest, chunk.getDestElem(), chunk.getNelems()); } return dest; } // note src and dest misnamed void write( IndexChunker index, int[] src, RandomAccessFile raf, long start_pos) { while (index.hasNext()) { Indexer2.Chunk chunk = index.next(); raf.seek( start_pos + chunk.getSrcElem() * 4); raf.writeInt(src, chunk.getDestElem(), chunk.getNelems()); } }
Nested Class Summary | |
---|---|
static class |
IndexChunker.Chunk
A chunk of data that is contiguous in both the source and destination. |
Constructor Summary | |
---|---|
IndexChunker(int[] srcShape,
Section wantSection)
Constructor |
Method Summary | |
---|---|
long |
getTotalNelems()
Get total number of elements in wantSection |
boolean |
hasNext()
If there are more chunks to process |
IndexChunker.Chunk |
next()
Get the next chunk |
protected static String |
printa(int[] a)
|
protected static void |
printa(String name,
int[] a)
|
protected static void |
printl(String name,
long[] a)
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public IndexChunker(int[] srcShape, Section wantSection) throws InvalidRangeException
srcShape
- the shape of the source, eg Variable.getShape()wantSection
- the wanted section in srcShape, ie must be sibset of srcShape.
InvalidRangeException
- if wantSection is incorrectMethod Detail |
---|
public long getTotalNelems()
public boolean hasNext()
public IndexChunker.Chunk next()
public String toString()
toString
in class Object
protected static String printa(int[] a)
protected static void printa(String name, int[] a)
protected static void printl(String name, long[] a)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |