Skip to content

Add a dtype argument to to_scipy_sparse() - #51

Merged
aarmey merged 1 commit into
mainfrom
to-scipy-sparse-dtype
Sep 14, 2026
Merged

Add a dtype argument to to_scipy_sparse()#51
aarmey merged 1 commit into
mainfrom
to-scipy-sparse-dtype

Conversation

@aarmey

@aarmey aarmey commented Sep 14, 2026

Copy link
Copy Markdown
Member

Summary

  • to_scipy_sparse() always materialized its data array as float64, requiring a caller that wanted a smaller dtype (e.g. float32 to match a GPU backend's own precision) to materialize-then-.astype(), which briefly holds both the float64 and downcast copies in memory at once.
  • Adds a dtype parameter (default np.float64, unchanged behavior) so the numba materialization kernels write directly into an array of the requested dtype.
  • Motivated by a downstream project (BAL-Pf2) needing a float32 real sparse array for a GPU PARAFAC2 fit, previously done as a separate cast step after materializing at float64.

Test plan

  • New test: test_to_scipy_sparse_dtype_argument (both VCSR/VCSC, Hypothesis-generated matrices) -- values match the float64 reference within float32 tolerance, same nnz
  • Full suite: pytest -- 1257 passed (same 4 pre-existing, unrelated failures on degenerate all-constant-column matrices confirmed present on main without this change too)

🤖 Generated with Claude Code

https://claude.ai/code/session_014MHUrbvYnPr1naj92oYTab

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
@aarmey
aarmey merged commit 78e8cfa into main Sep 14, 2026
5 of 6 checks passed
@aarmey
aarmey deleted the to-scipy-sparse-dtype branch September 14, 2026 17:08
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