alugowski / fast_matrix_market

Fast and full-featured Matrix Market I/O library for C++, Python, and R
BSD 2-Clause "Simplified" License
75 stars 7 forks source link

`fmm.mmread(stream)` closes stream (`scipy.io.mmread(stream)` does not) #9

Closed eriknw closed 1 year ago

eriknw commented 1 year ago

I discovered a small difference between fmm.mmread and scipy.io.mmread:

import fast_matrix_market as fmm
import scipy
from io import StringIO

text = """%%MatrixMarket matrix coordinate real general
3 3 4
1 3 1
2 2 2
3 1 3
3 1 4"""
stream = StringIO(text)
A1 = scipy.io.mmread(stream)
stream.seek(0)  # works after using scipy.io.mmread
A2 = fmm.mmread(stream)
stream.seek(0)  # <-- ValueError: I/O operation on closed file

This isn't particularly important or urgent, but I thought you would like to know differences between fmm.mmread and scipy.io.mmread.

alugowski commented 1 year ago

Good find!

The solution was tricky to locate as nothing was explicitly calling a close() method, and the problem didn't manifest while debugging. Turns out the string-to-bytes converter was based on a class that had an implicit close(). Fixed :)