Class MatrixMarketReader

java.lang.Object
org.flag4j.io.MatrixMarketReader

public class MatrixMarketReader extends Object

Instances of this class may be used to parse a file containing matrix or vector data in Matrix Market Exchange Format.

Currently, this class only supports the following subset of the Matrix Market Format:

  • Object: matrix
  • Format: coordinate, array
  • Field: real, integer, complex
  • MMSymmetry: general

Headers must be of the form:

 %%MatrixMarket matrix <coordinate | array> <real | integer | complex> general
 
See Also:
  • Constructor Details

    • MatrixMarketReader

      public MatrixMarketReader()
  • Method Details

    • read

      public AbstractTensor<?,?,?> read(String fileName) throws IOException

      Loads Matrix Market data from the file specified on instantiation of this MatrixMarketReader.

      Note, the value returned by this method is of type AbstractTensor. It is recommended to cast object to the desired matrix or vector type. For instance:

      
            MatrixMarketReader parser = new MatrixMarketReader("some_file.mtx");
            Matrix matrix;
            var mm = parser.load();
      
            try {
                matrix = (Matrix) mm;
            } catch(ClassCastException e) {
                // Handel exception.
            }
       
      Parameters:
      fileName - The name of the Matrix Market Format file to read.
      Returns:
      A matrix or vector containing the data in the specified Matrix Market file.
      Throws:
      IOException - If an I/O error occurs.
      Flag4jParsingException - If the Matrix Market Format file cannot be parsed.