Package org.ejml.ops
Class MatrixIO
java.lang.Object
org.ejml.ops.MatrixIO
Provides simple to use routines for reading and writing matrices to and from files.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends DMatrix>
TReads a matrix in which has been encoded using a Column Space Value (CSV) file format.static DMatrixRMajReads 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 DMatrixRMajloadMatrixMarketDDRM(Reader reader) Reads a stream in Matrix Market Coordinate formatstatic DMatrixSparseTripletloadMatrixMarketDSTR(Reader reader) Reads a stream in Matrix Market Coordinate formatstatic FMatrixRMajloadMatrixMarketFDRM(Reader reader) Reads a stream in Matrix Market Coordinate formatstatic FMatrixSparseTripletloadMatrixMarketFSTR(Reader reader) Reads a stream in Matrix Market Coordinate formatstatic 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 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 voidsaveMatrixMarket(DMatrixRMaj matrix, String floatFormat, Writer writer) Writes a stream using the Matrix Market Coordinate format.static voidsaveMatrixMarket(DMatrixSparse matrix, String floatFormat, Writer writer) Writes a stream using the Matrix Market Coordinate format.static voidsaveMatrixMarket(FMatrixRMaj matrix, String floatFormat, Writer writer) Writes a stream using the Matrix Market Coordinate format.static voidsaveMatrixMarket(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:
-
DEFAULT_LENGTH
public static final int DEFAULT_LENGTHNumber of digits in pretty format- See Also:
-
MATLAB_FORMAT
Specified the printf format used when printing out in Matlab format -
local
Local used by printf(). In general you want this to be US so that it stays standard compliant
-
-
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 -
saveMatrixMarket
Writes a stream using the Matrix Market Coordinate format.
See NIST MatrixMarket- Parameters:
matrix- The matrix to be writtenfloatFormat- The format used by printf. "%.4e" is suggestedwriter- The writer
-
saveMatrixMarket
Writes a stream using the Matrix Market Coordinate format.
See NIST MatrixMarket- Parameters:
matrix- The matrix to be writtenfloatFormat- The format used by printf. "%.4e" is suggestedwriter- The writer
-
saveMatrixMarket
Writes a stream using the Matrix Market Coordinate format.
See NIST MatrixMarket- Parameters:
matrix- The matrix to be writtenfloatFormat- The format used by printf. "%.4e" is suggestedwriter- The writer
-
saveMatrixMarket
Writes a stream using the Matrix Market Coordinate format.
See NIST MatrixMarket- Parameters:
matrix- The matrix to be writtenfloatFormat- The format used by printf. "%.4e" is suggestedwriter- The writer
-
loadMatrixMarketDSTR
Reads a stream in Matrix Market Coordinate format
Matrix Market- Parameters:
reader- Input reader- Returns:
- DMatrixSparseTriplet
-
loadMatrixMarketDDRM
Reads a stream in Matrix Market Coordinate format
Matrix Market- Parameters:
reader- Input reader- Returns:
- DMatrixRMaj
-
loadMatrixMarketFSTR
Reads a stream in Matrix Market Coordinate format
Matrix Market- Parameters:
reader- Input reader- Returns:
- FMatrixSparseTriplet
-
loadMatrixMarketFDRM
Reads a stream in Matrix Market Coordinate format
Matrix Market- Parameters:
reader- Input reader- Returns:
- FMatrixRMaj
-
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
- 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 IOException 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'.output- Output Matrix. Automatically matched if null. Modified.- Returns:
- Matrix
- 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 IOException Reads 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
-