Class MatrixMarketWriter
java.lang.Object
org.flag4j.io.MatrixMarketWriter
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 Summary
Modifier and TypeMethodDescriptionstatic void
write
(String filePath, MatrixMixin<?, ?, ?, ?> mat, String... comments) Writes a matrix to a file in Matrix Market Exchange Format file.
-
Method Details
-
write
public static void write(String filePath, MatrixMixin<?, ?, throws IOException?, ?> mat, String... comments) 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 benull
; in this case the parameter will be ignored.- Throws:
IOException
- If an I/O error occurs.IllegalArgumentException
- Ifmat
is not a supported matrix type for writing to a Matrix Market Exchange Format file.
-