Package org.ejml.ops
Class MatrixIO
java.lang.Object
org.ejml.ops.MatrixIO
public class MatrixIO extends Object
Provides simple to use routines for reading and writing matrices to and from files.
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_FLOAT_FORMATDefault printf float formatstatic intDEFAULT_LENGTHNumber of digits in pretty formatstatic StringMATLAB_FORMATSpecified the printf format used when printing out in Matlab format -
Constructor Summary
Constructors Constructor Description MatrixIO() -
Method Summary
Modifier and Type Method Description static <T extends DMatrix>
TloadBin(String fileName)Deprecated.This will be removed in the future due to how unsafe readObject() is.static <T extends DMatrix>
TloadCSV(String fileName, boolean doublePrecision)Reads a matrix in which has been encoded using a Column Space Value (CSV) file format.static DMatrixRMajloadCSV(String fileName, int numRows, int numCols)Reads a matrix in which has been encoded using a Column Space Value (CSV) file format.static <T extends Matrix>
TloadMatlab(String fileName)Loads aMatrixwhich has been saved to file using MATLAB's MAT-File Format (Level 5) serialization.static <T extends Matrix>
TloadMatlab(String fileName, T output)Loads aMatrixwhich has been saved to file using MATLAB's MAT-File Format (Level 5) serialization.static DMatrixSparseTripletloadMatrixMarketD(Reader reader)Reads a stream in Matrix Market Coordinate format https://math.nist.gov/MatrixMarket/formats.htmlstatic FMatrixSparseTripletloadMatrixMarketF(InputStream streamIn)Reads a stream in Matrix Market Coordinate format https://math.nist.gov/MatrixMarket/formats.htmlstatic FMatrixSparseTripletloadMatrixMarketF(Reader reader)Reads a stream in Matrix Market Coordinate format https://math.nist.gov/MatrixMarket/formats.htmlstatic DMatrixRMajmatlabToDDRM(String text)Converts a text string in matlab format into a DDRM matrixstatic FMatrixRMajmatlabToFDRM(String text)Converts a text string in matlab format into a DDRM matrixstatic voidprint(PrintStream out, CMatrix mat, String format)static voidprint(PrintStream out, DMatrix mat)static voidprint(PrintStream out, DMatrix mat, String format)Prints the matrix out in a text format.static voidprint(PrintStream out, DMatrix mat, String format, int row0, int row1, int col0, int col1)static voidprint(PrintStream out, DMatrixSparseCSC m, String format)Prints the matrix out in a text format.static voidprint(PrintStream out, DMatrixSparseTriplet m, String format)static voidprint(PrintStream out, FMatrix mat)static voidprint(PrintStream out, FMatrix mat, String format)static voidprint(PrintStream out, FMatrix mat, String format, int row0, int row1, int col0, int col1)static voidprint(PrintStream out, FMatrixSparseCSC m, String format)static voidprint(PrintStream out, FMatrixSparseTriplet m, String format)static voidprint(PrintStream out, Matrix mat)static voidprint(PrintStream out, ZMatrix mat, String format)static voidprintFancy(PrintStream out, CMatrix mat, int length)static voidprintFancy(PrintStream out, DMatrix mat, int length)static voidprintFancy(PrintStream out, DMatrixSparseCSC m, int length)static voidprintFancy(PrintStream out, FMatrix mat, int length)static voidprintFancy(PrintStream out, ZMatrix mat, int length)static voidprintJava(PrintStream out, DMatrix mat, String format)static voidprintJava(PrintStream out, FMatrix mat, String format)static voidprintMatlab(PrintStream out, DMatrix mat)static voidprintMatlab(PrintStream out, FMatrix mat)static voidsaveBin(DMatrix A, String fileName)Saves a matrix to disk using Java binary serialization.static voidsaveDenseCSV(DMatrix A, String fileName)Saves a matrix to disk using in a Column Space Value (CSV) format.static voidsaveMatlab(Matrix A, String fileName)Saves a matrix to disk using MATLAB's MAT-File Format (Level 5) binary serialization.static voidsaveMatrixMarketD(DMatrixSparse matrix, String floatFormat, Writer writer)Writes a stream using the Matrix Market Coordinate format.static voidsaveMatrixMarketF(FMatrixSparse matrix, String floatFormat, Writer writer)Writes a stream using the Matrix Market Coordinate format.static voidsaveSparseCSV(DMatrixSparseTriplet A, String fileName)Saves a matrix to disk using in a Column Space Value (CSV) format.static voidsaveSparseCSV(FMatrixSparseTriplet A, String fileName)Saves a matrix to disk using in a Column Space Value (CSV) format.
-
Field Details
-
DEFAULT_FLOAT_FORMAT
Default printf float format- See Also:
- Constant Field Values
-
DEFAULT_LENGTH
public static final int DEFAULT_LENGTHNumber of digits in pretty format- See Also:
- Constant Field Values
-
MATLAB_FORMAT
Specified the printf format used when printing out in Matlab format
-
-
Constructor Details
-
MatrixIO
public MatrixIO()
-
-
Method Details
-
matlabToDDRM
Converts a text string in matlab format into a DDRM matrix -
matlabToFDRM
Converts a text string in matlab format into a DDRM matrix -
saveMatrixMarketD
Writes a stream using the Matrix Market Coordinate format. https://math.nist.gov/MatrixMarket/formats.html- Parameters:
matrix- The matrix to be writtenfloatFormat- The format used by printf. "%.4e" is suggestedwriter- The writer
-
saveMatrixMarketF
Writes a stream using the Matrix Market Coordinate format. https://math.nist.gov/MatrixMarket/formats.html- Parameters:
matrix- The matrix to be writtenfloatFormat- The format used by printf. "%.4e" is suggestedwriter- The writer
-
loadMatrixMarketD
Reads a stream in Matrix Market Coordinate format https://math.nist.gov/MatrixMarket/formats.html- Parameters:
reader- Input reader- Returns:
- Matrix in triplet format
-
loadMatrixMarketF
Reads a stream in Matrix Market Coordinate format https://math.nist.gov/MatrixMarket/formats.html- Parameters:
reader- Input reader- Returns:
- Matrix in triplet format
-
loadMatrixMarketF
Reads a stream in Matrix Market Coordinate format https://math.nist.gov/MatrixMarket/formats.html- Parameters:
streamIn- Input stream- Returns:
- Matrix in triplet format
-
saveMatlab
Saves a matrix to disk using MATLAB's MAT-File Format (Level 5) binary serialization. Notes: * The matrix gets stored as a single root level entry named 'ejmlMatrix' *FMatrixSparseCSCget stored as sparse double matrices See MAT File Library matfile_format.pdf- Parameters:
A- The matrix being saved.fileName- Name of the file its being saved at.- Throws:
IOException
-
loadMatlab
Loads aMatrixwhich has been saved to file using MATLAB's MAT-File Format (Level 5) serialization.- Parameters:
fileName- The file being loaded. It is expected to contain a root level entry named 'ejmlMatrix'.- Returns:
- Matrix A matrix of the type that best matches the serialized data
- Throws:
IOException
-
loadMatlab
public static <T extends Matrix> T loadMatlab(String fileName, @Nullable T output) throws IOExceptionLoads aMatrixwhich has been saved to file using MATLAB's MAT-File Format (Level 5) serialization.- Parameters:
fileName- The file being loaded. It is expected to contain a root level entry named 'ejmlMatrix'.output- Output Matrix. Automatically matched if null. Modified.- Returns:
- Matrix
- Throws:
IOException
-
saveBin
Saves a matrix to disk using Java binary serialization.- Parameters:
A- The matrix being saved.fileName- Name of the file its being saved at.- Throws:
IOException
-
loadBin
Deprecated.This will be removed in the future due to how unsafe readObject() is.Loads aDMatrixwhich has been saved to file using Java binary serialization.- Parameters:
fileName- The file being loaded.- Returns:
- DMatrixRMaj
- Throws:
IOException
-
saveDenseCSV
Saves a matrix to disk using in a Column Space Value (CSV) format. For a description of the format seeloadCSV(String, boolean).- Parameters:
A- The matrix being saved.fileName- Name of the file its being saved at.- Throws:
IOException
-
saveSparseCSV
Saves a matrix to disk using in a Column Space Value (CSV) format. For a description of the format seeloadCSV(String, boolean).- Parameters:
A- The matrix being saved.fileName- Name of the file its being saved at.- Throws:
IOException
-
saveSparseCSV
Saves a matrix to disk using in a Column Space Value (CSV) format. For a description of the format seeloadCSV(String, boolean).- Parameters:
A- The matrix being saved.fileName- Name of the file its being saved at.- Throws:
IOException
-
loadCSV
public static <T extends DMatrix> T loadCSV(String fileName, boolean doublePrecision) throws IOExceptionReads a matrix in which has been encoded using a Column Space Value (CSV) file format. The number of rows and columns are read in on the first line. Then each row is read in the subsequent lines. Works with dense and sparse matrices.- Parameters:
fileName- The file being loaded.- Returns:
- DMatrix
- Throws:
IOException
-
loadCSV
Reads a matrix in which has been encoded using a Column Space Value (CSV) file format. For a description of the format seeloadCSV(String, boolean).- Parameters:
fileName- The file being loaded.numRows- number of rows in the matrix.numCols- number of columns in the matrix.- Returns:
- DMatrixRMaj
- Throws:
IOException
-
printFancy
-
printFancy
-
printFancy
-
printFancy
-
printFancy
-
print
-
print
-
print
Prints the matrix out in a text format. The format is specified using notation fromString.format(String, Object...). Unless the format is set to 'matlab' then it will print it out in a format that's understood by Matlab. 'java' will print a java 2D array.- Parameters:
out- Output streammat- Matrix to be printedformat- printf style or 'matlab'
-
printMatlab
-
printMatlab
-
print
Prints the matrix out in a text format. The format is specified using notation fromString.format(String, Object...). Unless the format is set to 'matlab' then it will print it out in a format that's understood by Matlab.- Parameters:
out- Output streamm- Matrix to be printedformat- printf style or 'matlab'
-
print
-
print
-
print
-
printJava
-
print
-
print
-
print
public static void print(PrintStream out, DMatrix mat, String format, int row0, int row1, int col0, int col1) -
printJava
-
print
public static void print(PrintStream out, FMatrix mat, String format, int row0, int row1, int col0, int col1) -
print
-
print
-