stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

Support for I/O of standard formats

Open perazz opened this issue 5 months ago • 10 comments

Motivation

As linear algebra support develops, it would be useful to have simple interfaces to access test matrices to/from standard formats into the stdlib formats.

Prior Art

  • Matrix Market: https://math.nist.gov/MatrixMarket/ https://math.nist.gov/MatrixMarket/mmio/f/mmiof77.html
  • Harwell-Boeing: https://math.nist.gov/MatrixMarket/formats.html#hb-code
  • NumPy: https://numpy.org/doc/stable/reference/generated/numpy.load.html
  • https://help.imsl.com/java/5.0.1/api/com/imsl/math/SparseMatrixEx2.html
  • https://help.imsl.com/c/7.0/html/cmath/default.htm?turl=matrixstoragemodes.htm

Additional Information

cc #749 cc #486 cc @minhqdao

perazz avatar Jan 16 '24 08:01 perazz

For reference, the SciPy IO API: https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.mmwrite.html#scipy.io.mmwrite the TACO library also offers an API of the sorts for C++ and Python: http://tensor-compiler.org/docs/scientific_computing.html

jalvesz avatar Jan 16 '24 13:01 jalvesz

I've added #486 which is also relevant. I would be keen to have the SciPy .npz format supported, which is also used to pass sparse matrices.

ivan-pi avatar Jan 17 '24 09:01 ivan-pi

the TACO library also offers an API of the sorts for C++ and Python: http://tensor-compiler.org/docs/scientific_computing.html

The formats supported by TACO are:

ivan-pi avatar Jan 17 '24 11:01 ivan-pi

There is also a naive text format that MATLAB uses, described under

I've used it in the past, to quickly output a matrix and import it into MATLAB for inspection (spy) and calculating the spectral radius.

ivan-pi avatar Jan 17 '24 11:01 ivan-pi

I've also used the same format locally to then use matplotlib's spy https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.spy.html So basically take whichever sparse format > transform to COO > dump a file <name>.dat

jalvesz avatar Jan 17 '24 11:01 jalvesz

Can we use the MatrixMarket routines from NIST (potentially, wrapped in a nicer interface)? Or should we do a clean-room design and implementation?

ivan-pi avatar Jan 17 '24 13:01 ivan-pi

It could be good to have them for comparison, but it could be the occasion to make a clean-room design. Maybe decided on the style for the signature of IO procedures, this could already enable focusing on individual implementations that should respect the decided signature.

I had in mind something like this:

subroutine matrix_<save/load>_<format>( matrix_type , file_name , ...optionals... )
end subroutine

jalvesz avatar Jan 17 '24 14:01 jalvesz

Can we use the MatrixMarket routines from NIST (potentially, wrapped in a nicer interface)?

If their licenses permit it, I would say yes. It might be good to contact them, before using their codes (e.g., like it was done for the hash and some sort procedures).

jvdp1 avatar Jan 17 '24 17:01 jvdp1

I will ask @minhqdao if he plans to take care of this issue.

perazz avatar Jan 22 '24 10:01 perazz

Thanks, @perazz, for opening this issue and all of you for your input and adding the references. I'll take care of it over the next few weeks.

minhqdao avatar Jan 22 '24 20:01 minhqdao