public class IndexChunker
extends java.lang.Object
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()); } }
Modifier and Type | Class and Description |
---|---|
static class |
IndexChunker.Chunk
A chunk of data that is contiguous in both the source and destination.
|
Constructor and Description |
---|
IndexChunker(int[] srcShape,
Section wantSection)
Constructor
|
Modifier and Type | Method and Description |
---|---|
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 java.lang.String |
printa(int[] a) |
protected static void |
printa(java.lang.String name,
int[] a) |
protected static void |
printl(java.lang.String name,
long[] a) |
java.lang.String |
toString() |
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 subset of srcShape.InvalidRangeException
- if wantSection is incorrectpublic long getTotalNelems()
public boolean hasNext()
public IndexChunker.Chunk next()
public java.lang.String toString()
toString
in class java.lang.Object
protected static java.lang.String printa(int[] a)
protected static void printa(java.lang.String name, int[] a)
protected static void printl(java.lang.String name, long[] a)