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 Details

    • DEFAULT_FLOAT_FORMAT

      public static final String DEFAULT_FLOAT_FORMAT
      Default printf float format
      See Also:
    • DEFAULT_LENGTH

      public static final int DEFAULT_LENGTH
      Number of digits in pretty format
      See Also:
    • MATLAB_FORMAT

      public static String MATLAB_FORMAT
      Specified the printf format used when printing out in Matlab format
    • local

      public static Locale 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

      public static DMatrixRMaj matlabToDDRM(String text)
      Converts a text string in matlab format into a DDRM matrix
    • matlabToFDRM

      public static FMatrixRMaj matlabToFDRM(String text)
      Converts a text string in matlab format into a DDRM matrix
    • saveMatrixMarket

      public static void saveMatrixMarket(DMatrixSparse matrix, String floatFormat, Writer writer)

      Writes a stream using the Matrix Market Coordinate format.

      See NIST MatrixMarket
      Parameters:
      matrix - The matrix to be written
      floatFormat - The format used by printf. "%.4e" is suggested
      writer - The writer
    • saveMatrixMarket

      public static void saveMatrixMarket(FMatrixSparse matrix, String floatFormat, Writer writer)

      Writes a stream using the Matrix Market Coordinate format.

      See NIST MatrixMarket
      Parameters:
      matrix - The matrix to be written
      floatFormat - The format used by printf. "%.4e" is suggested
      writer - The writer
    • saveMatrixMarket

      public static void saveMatrixMarket(DMatrixRMaj matrix, String floatFormat, Writer writer)

      Writes a stream using the Matrix Market Coordinate format.

      See NIST MatrixMarket
      Parameters:
      matrix - The matrix to be written
      floatFormat - The format used by printf. "%.4e" is suggested
      writer - The writer
    • saveMatrixMarket

      public static void saveMatrixMarket(FMatrixRMaj matrix, String floatFormat, Writer writer)

      Writes a stream using the Matrix Market Coordinate format.

      See NIST MatrixMarket
      Parameters:
      matrix - The matrix to be written
      floatFormat - The format used by printf. "%.4e" is suggested
      writer - The writer
    • loadMatrixMarketDSTR

      public static DMatrixSparseTriplet loadMatrixMarketDSTR(Reader reader)

      Reads a stream in Matrix Market Coordinate format

      Matrix Market
      Parameters:
      reader - Input reader
      Returns:
      DMatrixSparseTriplet
    • loadMatrixMarketDDRM

      public static DMatrixRMaj loadMatrixMarketDDRM(Reader reader)

      Reads a stream in Matrix Market Coordinate format

      Matrix Market
      Parameters:
      reader - Input reader
      Returns:
      DMatrixRMaj
    • loadMatrixMarketFSTR

      public static FMatrixSparseTriplet loadMatrixMarketFSTR(Reader reader)

      Reads a stream in Matrix Market Coordinate format

      Matrix Market
      Parameters:
      reader - Input reader
      Returns:
      FMatrixSparseTriplet
    • loadMatrixMarketFDRM

      public static FMatrixRMaj loadMatrixMarketFDRM(Reader reader)

      Reads a stream in Matrix Market Coordinate format

      Matrix Market
      Parameters:
      reader - Input reader
      Returns:
      FMatrixRMaj
    • saveMatlab

      public static void saveMatlab(Matrix A, String fileName) throws IOException

      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
      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

      public static <T extends Matrix> T loadMatlab(String fileName) throws IOException
      Loads a Matrix 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 a Matrix 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

      public static void saveDenseCSV(DMatrix A, String fileName) throws IOException
      Saves a matrix to disk using in a Column Space Value (CSV) format. For a description of the format see loadCSV(String, boolean).
      Parameters:
      A - The matrix being saved.
      fileName - Name of the file its being saved at.
      Throws:
      IOException
    • saveSparseCSV

      public static void saveSparseCSV(DMatrixSparseTriplet A, String fileName) throws IOException
      Saves a matrix to disk using in a Column Space Value (CSV) format. For a description of the format see loadCSV(String, boolean).
      Parameters:
      A - The matrix being saved.
      fileName - Name of the file its being saved at.
      Throws:
      IOException
    • saveSparseCSV

      public static void saveSparseCSV(FMatrixSparseTriplet A, String fileName) throws IOException
      Saves a matrix to disk using in a Column Space Value (CSV) format. For a description of the format see loadCSV(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

      public static DMatrixRMaj loadCSV(String fileName, int numRows, int numCols) throws IOException
      Reads a matrix in which has been encoded using a Column Space Value (CSV) file format. For a description of the format see loadCSV(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

      public static void printFancy(PrintStream out, DMatrix mat, int length)
    • printFancy

      public static void printFancy(PrintStream out, FMatrix mat, int length)
    • printFancy

      public static void printFancy(PrintStream out, ZMatrix mat, int length)
    • printFancy

      public static void printFancy(PrintStream out, CMatrix mat, int length)
    • printFancy

      public static void printFancy(PrintStream out, DMatrixSparseCSC m, int length)
    • print

      public static void print(PrintStream out, Matrix mat)
    • print

      public static void print(PrintStream out, DMatrix mat)
    • print

      public static void print(PrintStream out, DMatrix mat, String format)
      Prints the matrix out in a text format. The format is specified using notation from String.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 stream
      mat - Matrix to be printed
      format - printf style or 'matlab'
    • printMatlab

      public static void printMatlab(PrintStream out, DMatrix mat)
    • printMatlab

      public static void printMatlab(PrintStream out, FMatrix mat)
    • print

      public static void print(PrintStream out, DMatrixSparseCSC m, String format)
      Prints the matrix out in a text format. The format is specified using notation from String.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 stream
      m - Matrix to be printed
      format - printf style or 'matlab'
    • print

      public static void print(PrintStream out, FMatrixSparseCSC m, String format)
    • print

      public static void print(PrintStream out, DMatrixSparseTriplet m, String format)
    • print

      public static void print(PrintStream out, FMatrixSparseTriplet m, String format)
    • printJava

      public static void printJava(PrintStream out, DMatrix mat, String format)
    • print

      public static void print(PrintStream out, FMatrix mat)
    • print

      public static void print(PrintStream out, FMatrix mat, String format)
    • print

      public static void print(PrintStream out, DMatrix mat, String format, int row0, int row1, int col0, int col1)
    • printJava

      public static void printJava(PrintStream out, FMatrix mat, String format)
    • print

      public static void print(PrintStream out, FMatrix mat, String format, int row0, int row1, int col0, int col1)
    • print

      public static void print(PrintStream out, ZMatrix mat, String format)
    • print

      public static void print(PrintStream out, CMatrix mat, String format)