Skip to content

Fix a hang in write_matrix_market_csc #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rafal-c
Copy link

@rafal-c rafal-c commented Mar 10, 2025

Calling write_matrix_market_csc on a sparse array with no explicit values hangs indefinitely. This is caused by the fact that inside csc_formatter::chunk::next_chunk, there is a division by nnz_per_column, which happens to be 0. for such arrays.

The fix I propose here is to set ptr_chunk_end to the end of range in the problematic case, avoiding division by zero.

An alternative fix could be to call write_body inside write_matrix_market_csc only if nnz > 0, but it doesn't really solve the problem within the csc_formatter.

I also updated unit tests to cover the case of a csc matrix with no explicit values and non-zero dimensions.

rafal-c added 2 commits March 10, 2025 18:00
…tter::chunk::next_chunk. Trying to calculate the chunk size with nnz_per_columns being 0, which may happen for sparse arrays with no explicit values, results in an undefined behavior (division by 0).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant