Add a dtype argument to to_scipy_sparse() - #51
Merged
Conversation
Materializes the normalized view's Delta term directly in the requested dtype instead of always at float64. Lets a caller that only wants a lower-precision array (e.g. float32 to match a GPU backend's own working precision) get it without a separate materialize-then-astype step, which briefly holds both the float64 and downcast copies in memory at once for no benefit. Defaults to float64, matching the previous behavior. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MHUrbvYnPr1naj92oYTab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
to_scipy_sparse()always materialized itsdataarray asfloat64, requiring a caller that wanted a smaller dtype (e.g.float32to match a GPU backend's own precision) to materialize-then-.astype(), which briefly holds both the float64 and downcast copies in memory at once.dtypeparameter (defaultnp.float64, unchanged behavior) so the numba materialization kernels write directly into an array of the requested dtype.Test plan
test_to_scipy_sparse_dtype_argument(both VCSR/VCSC, Hypothesis-generated matrices) -- values match the float64 reference within float32 tolerance, same nnzpytest-- 1257 passed (same 4 pre-existing, unrelated failures on degenerate all-constant-column matrices confirmed present onmainwithout this change too)🤖 Generated with Claude Code
https://claude.ai/code/session_014MHUrbvYnPr1naj92oYTab