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
-
Constructor Summary
-
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 DMatrixRMaj
Reads a matrix in which has been encoded using a Column Space Value (CSV) file format.static <T extends Matrix>
TloadMatlab
(String fileName) Loads aMatrix
which has been saved to file using MATLAB's MAT-File Format (Level 5) serialization.static <T extends Matrix>
TloadMatlab
(String fileName, T output) Loads aMatrix
which has been saved to file using MATLAB's MAT-File Format (Level 5) serialization.static DMatrixRMaj
loadMatrixMarketDDRM
(Reader reader) Reads a stream in Matrix Market Coordinate formatstatic DMatrixSparseTriplet
loadMatrixMarketDSTR
(Reader reader) Reads a stream in Matrix Market Coordinate formatstatic FMatrixRMaj
loadMatrixMarketFDRM
(Reader reader) Reads a stream in Matrix Market Coordinate formatstatic FMatrixSparseTriplet
loadMatrixMarketFSTR
(Reader reader) Reads a stream in Matrix Market Coordinate formatstatic DMatrixRMaj
matlabToDDRM
(String text) Converts a text string in matlab format into a DDRM matrixstatic FMatrixRMaj
matlabToFDRM
(String text) Converts a text string in matlab format into a DDRM matrixstatic void
print
(PrintStream out, CMatrix mat, String format) static void
print
(PrintStream out, DMatrix mat) static void
print
(PrintStream out, DMatrix mat, String format) Prints the matrix out in a text format.static void
print
(PrintStream out, DMatrix mat, String format, int row0, int row1, int col0, int col1) static void
print
(PrintStream out, DMatrixSparseCSC m, String format) Prints the matrix out in a text format.static void
print
(PrintStream out, DMatrixSparseTriplet m, String format) static void
print
(PrintStream out, FMatrix mat) static void
print
(PrintStream out, FMatrix mat, String format) static void
print
(PrintStream out, FMatrix mat, String format, int row0, int row1, int col0, int col1) static void
print
(PrintStream out, FMatrixSparseCSC m, String format) static void
print
(PrintStream out, FMatrixSparseTriplet m, String format) static void
print
(PrintStream out, Matrix mat) static void
print
(PrintStream out, ZMatrix mat, String format) static void
printFancy
(PrintStream out, CMatrix mat, int length) static void
printFancy
(PrintStream out, DMatrix mat, int length) static void
printFancy
(PrintStream out, DMatrixSparseCSC m, int length) static void
printFancy
(PrintStream out, FMatrix mat, int length) static void
printFancy
(PrintStream out, ZMatrix mat, int length) static void
printJava
(PrintStream out, DMatrix mat, String format) static void
printJava
(PrintStream out, FMatrix mat, String format) static void
printMatlab
(PrintStream out, DMatrix mat) static void
printMatlab
(PrintStream out, FMatrix mat) static void
saveDenseCSV
(DMatrix A, String fileName) Saves a matrix to disk using in a Column Space Value (CSV) format.static void
saveMatlab
(Matrix A, String fileName) Saves a matrix to disk using MATLAB's MAT-File Format (Level 5) binary serialization.static void
saveMatrixMarket
(DMatrixRMaj matrix, String floatFormat, Writer writer) Writes a stream using the Matrix Market Coordinate format.static void
saveMatrixMarket
(DMatrixSparse matrix, String floatFormat, Writer writer) Writes a stream using the Matrix Market Coordinate format.static void
saveMatrixMarket
(FMatrixRMaj matrix, String floatFormat, Writer writer) Writes a stream using the Matrix Market Coordinate format.static void
saveMatrixMarket
(FMatrixSparse matrix, String floatFormat, Writer writer) Writes a stream using the Matrix Market Coordinate format.static void
saveSparseCSV
(DMatrixSparseTriplet A, String fileName) Saves a matrix to disk using in a Column Space Value (CSV) format.static void
saveSparseCSV
(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'
FMatrixSparseCSC
get stored as sparse double matrices
- Parameters:
A
- The matrix being saved.fileName
- Name of the file its being saved at.- Throws:
IOException
-
loadMatlab
Loads aMatrix
which 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 aMatrix
which 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
-