Class MatrixMarketWriter

java.lang.Object
org.flag4j.io.MatrixMarketWriter

public final class MatrixMarketWriter extends Object

A utility class for writing matrices (from the Flag4j library) to a file in the Matrix Market Exchange Format.

This class supports writing both dense and sparse matrices (real or complex) to the Matrix Market format. Dense matrices are written in the array format, while sparse (both COO and CSR) matrices are written in the coordinate (COO) format.

All matrices are currently written in general form and the symmetry is not considered.

Currently Supported Matrix Types

  • Matrix (real dense)
  • CMatrix (complex dense)
  • CooMatrix (real sparse COO)
  • CsrMatrix (real sparse CSR, converted to COO)
  • CooCMatrix (complex sparse COO)
  • CsrCMatrix (complex sparse CSR, converted to COO)

Attempting to write a matrix type not listed above will result in an IllegalArgumentException.

See Also:
  • Method Details

    • write

      public static void write(String filePath, MatrixMixin<?,?,?,?> mat, String... comments) throws IOException

      Writes a matrix to a file in Matrix Market Exchange Format file.

      If mat is a CSR matrix, it will be converted to a COO matrix and saved as a coordinate matrix.

      Currently supported matrix types:

      • Matrix (real dense)
      • CMatrix (complex dense)
      • CooMatrix (real sparse COO)
      • CsrMatrix (real sparse CSR, converted to COO)
      • CooCMatrix (complex sparse COO)
      • CsrCMatrix (complex sparse CSR, converted to COO)
      Parameters:
      filePath - Path of the file to write to.
      mat - Matrix to write to file.
      comments - Comments to prepend to file. Each comment will be written to its own line. May be null; in this case the parameter will be ignored.
      Throws:
      IOException - If an I/O error occurs.
      IllegalArgumentException - If mat is not a supported matrix type for writing to a Matrix Market Exchange Format file.