Skip to content

api: let host() copy sparse arrays as dense - #3723

Draft
melonakos wants to merge 2 commits into
masterfrom
fix/3703-sparse-host
Draft

melonakos wants to merge 2 commits into
masterfrom
fix/3703-sparse-host

Conversation

@melonakos

@melonakos melonakos commented Sep 10, 2026

Copy link
Copy Markdown
Member

Calling host() on a sparse array threw:

Invalid argument at index 0
Expected: info->isSparse() == false

host() sizes its buffer from elements(), which already reports the dense shape for a sparse array, so af_get_data_ptr now converts CSR and COO arrays to dense and copies that. CSC to dense is not implemented anywhere, so a CSC array fails with AF_ERR_NOT_SUPPORTED and a message saying to convert to CSR or COO first; the C++ and C docs say the same. Callers who relied on the old error to detect sparse arrays now get data instead, which is worth a line in the release notes. Tests cover the reported case and compare host() against the dense source for CSR and COO; the sparse suite passes on the CPU backend (88 tests). Fixes #3703.

host() sizes its buffer from elements(), which reports the dense shape for a sparse array, but af_get_data_ptr then rejected the array with "Expected: info->isSparse() == false". Convert to dense first and copy that, and say so in the docs. Fixes #3703.
CSC to dense is not implemented, so host() on a CSC array now fails with AF_ERR_NOT_SUPPORTED and a message instead of an argument error from deep inside the conversion. The docs say CSR and COO. The test gains an fp64 guard and a case that compares host() against the dense source for CSR and COO and expects the CSC rejection.
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.

[BUG] Sparse host call throws

1 participant