|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.knowceans.util.ArrayIo
public class ArrayIo
MatrixIo provides methods to load and save matrices and vectors to file, which automatic compression if the file extension given is ".zip". The standard methods are load/saveBinaryMatrix that load/save a double[][] with the protocol rows,cols,foreach(row): foreach(col): double[row][col] :end :end.
Custom protocols for more complex data can be easily constructed by opening a stream using one of the open*Stream() methods, using the methods of the Data*Stream classes and read/write* methods of this class for matrices and vectors and then closing the stream using the close*Stream methods in this class (provided for symmetry) or the close() methods in the Data*Stream classes.
TODO: The binary methods could be considered for change to a subclass of DataInputStream and DataOutputStream.
Constructor Summary | |
---|---|
ArrayIo()
|
Method Summary | |
---|---|
static void |
closeInputStream(java.io.DataInputStream dis)
Close the input stream |
static void |
closeOutputStream(java.io.DataOutputStream dos)
Close the data output, which results in flushing the write buffer and closing the file. |
static java.lang.String |
formatDouble(double d)
|
static double[][] |
loadAscii(java.lang.String filename)
|
static int[][] |
loadBinaryIntMatrix(java.lang.String filename)
Loads an integer matrix from a binary file, optionally a zip file. |
static double[][] |
loadBinaryMatrix(java.lang.String filename)
Loads a matrix from a binary file, optionally a zip file. |
static java.io.DataInputStream |
openInputStream(java.lang.String filename)
Opens a data input stream with optional zip compression. |
static java.io.DataOutputStream |
openOutputStream(java.lang.String filename)
Opens a data output stream with optional zip compression. |
static java.lang.String |
padSpace(java.lang.String s,
int length)
|
static java.lang.Object |
read(java.io.DataInputStream is,
java.lang.Object type)
generic method that calls the methods according to the type of the argument Object |
static double[][] |
readDoubleMatrix(java.io.DataInputStream bw)
Read matrix from file. |
static double[][][] |
readDoubleTensor(java.io.DataInputStream bw)
|
static double[] |
readDoubleVector(java.io.DataInputStream bw)
Read vector from file. |
static float[][] |
readFloatMatrix(java.io.DataInputStream bw)
Read matrix from file. |
static float[] |
readFloatVector(java.io.DataInputStream bw)
Read vector from file. |
static int[][] |
readIntMatrix(java.io.DataInputStream bw)
Read matrix from file. |
static int[] |
readIntVector(java.io.DataInputStream bw)
Read vector from file. |
static void |
saveAscii(java.lang.String filename,
double[][] a)
|
static void |
saveBinaryIntMatrix(java.lang.String filename,
int[][] a)
Writes integer matrix to binary file. |
static void |
saveBinaryMatrix(java.lang.String filename,
double[][] a)
Writes matrix to binary file. |
static void |
saveShades(java.lang.String filename,
double[][] a)
Save a matrix as shaded values using MayaShades. |
static void |
saveTransposedAscii(java.lang.String filename,
double[][] a)
|
static void |
saveTransposedShades(java.lang.String filename,
double[][] a)
Save a transposed matrix as shaded values using MayaShades. |
static void |
write(java.io.DataOutputStream os,
java.lang.Object data)
generic write method that calls the respective method of the type of data |
static void |
writeDoubleMatrix(java.io.DataOutputStream bw,
double[][] matrix)
Writes a double matrix in the format rows,cols1,a11,a12,a1...,cols2,a21,... |
static void |
writeDoubleTensor(java.io.DataOutputStream bw,
double[][][] tensor)
Writes a double tensor (here = 3d matrix). |
static void |
writeDoubleVector(java.io.DataOutputStream bw,
double[] vector)
Writes a double vector in the format size,v1,v2,... |
static void |
writeFloatMatrix(java.io.DataOutputStream bw,
float[][] matrix)
Writes a float matrix in the format rows,cols,a11,a12,a1...,a21,... |
static void |
writeFloatVector(java.io.DataOutputStream bw,
float[] vector)
Writes a float vector in the format size,v1,v2,... |
static void |
writeIntMatrix(java.io.DataOutputStream bw,
int[][] matrix)
Writes an integer matrix in the format rows,cols1,a11,a12,a1...,cols2,a21,... |
static void |
writeIntVector(java.io.DataOutputStream bw,
int[] vector)
Writes an integer vector in the format size,v1,v2,... |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ArrayIo()
Method Detail |
---|
public static int[][] loadBinaryIntMatrix(java.lang.String filename)
filename
-
public static double[][] loadBinaryMatrix(java.lang.String filename)
filename
-
public static void saveBinaryIntMatrix(java.lang.String filename, int[][] a)
filename
- a
- public static void saveBinaryMatrix(java.lang.String filename, double[][] a)
filename
- a
- public static java.lang.Object read(java.io.DataInputStream is, java.lang.Object type) throws java.io.IOException
is
- type
-
java.io.IOException
public static int[][] readIntMatrix(java.io.DataInputStream bw) throws java.io.IOException
bw
-
java.io.IOException
public static int[] readIntVector(java.io.DataInputStream bw) throws java.io.IOException
bw
-
java.io.IOException
public static double[][][] readDoubleTensor(java.io.DataInputStream bw) throws java.io.IOException
java.io.IOException
public static double[][] readDoubleMatrix(java.io.DataInputStream bw) throws java.io.IOException
bw
-
java.io.IOException
public static double[] readDoubleVector(java.io.DataInputStream bw) throws java.io.IOException
bw
-
java.io.IOException
public static float[][] readFloatMatrix(java.io.DataInputStream bw) throws java.io.IOException
bw
-
java.io.IOException
public static float[] readFloatVector(java.io.DataInputStream bw) throws java.io.IOException
bw
-
java.io.IOException
public static void write(java.io.DataOutputStream os, java.lang.Object data) throws java.io.IOException
writer
- data
- object
java.io.IOException
public static void writeIntMatrix(java.io.DataOutputStream bw, int[][] matrix) throws java.io.IOException
bw
- matrix
-
java.io.IOException
public static void writeIntVector(java.io.DataOutputStream bw, int[] vector) throws java.io.IOException
bw
- vector
-
java.io.IOException
public static void writeDoubleTensor(java.io.DataOutputStream bw, double[][][] tensor) throws java.io.IOException
bw
- tensor
-
java.io.IOException
public static void writeDoubleMatrix(java.io.DataOutputStream bw, double[][] matrix) throws java.io.IOException
bw
- matrix
-
java.io.IOException
public static void writeDoubleVector(java.io.DataOutputStream bw, double[] vector) throws java.io.IOException
bw
- vector
-
java.io.IOException
public static void writeFloatMatrix(java.io.DataOutputStream bw, float[][] matrix) throws java.io.IOException
bw
- matrix
-
java.io.IOException
public static void writeFloatVector(java.io.DataOutputStream bw, float[] vector) throws java.io.IOException
bw
- vector
-
java.io.IOException
public static java.lang.String padSpace(java.lang.String s, int length)
public static java.lang.String formatDouble(double d)
d
-
public static double[][] loadAscii(java.lang.String filename)
public static void saveAscii(java.lang.String filename, double[][] a)
filename
- a
- public static void saveTransposedAscii(java.lang.String filename, double[][] a)
filename
- a
- matrix (with equal columns for each row)public static java.io.DataOutputStream openOutputStream(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
filename
-
java.io.FileNotFoundException
java.io.IOException
public static void closeOutputStream(java.io.DataOutputStream dos) throws java.io.IOException
dos
-
java.io.IOException
public static java.io.DataInputStream openInputStream(java.lang.String filename) throws java.io.IOException, java.io.FileNotFoundException
filename
-
java.io.FileNotFoundException
java.io.IOException
public static void closeInputStream(java.io.DataInputStream dis) throws java.io.IOException
dis
-
java.io.IOException
public static void saveShades(java.lang.String filename, double[][] a)
filename
- a
- public static void saveTransposedShades(java.lang.String filename, double[][] a)
filename
- a
- matrix with equal cols in each row
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |