REFACTOR: Reorganize type hierarchy of sparse.py. Move array-level fu…#739
REFACTOR: Reorganize type hierarchy of sparse.py. Move array-level fu…#739
Conversation
…nctions to sparse.COO, and keep module-level functions to sp. Replaces xp() with xp.COO() to create sparse arrays when xp used to be callable and was used as a constructor.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #739 +/- ##
==========================================
+ Coverage 85.94% 86.07% +0.12%
==========================================
Files 85 86 +1
Lines 4924 4918 -6
Branches 637 637
==========================================
+ Hits 4232 4233 +1
+ Misses 491 486 -5
+ Partials 201 199 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a33f181. Configure here.
|
@jbogaardt, we decided that we need your review on this one, for your Sparse knowledge. I wrote a bunch of text, but the quick 1-sentence summary is that I'm trying to get |

Summary of Changes
COO.cumprod, and addedsp.sum = COO.sum.sparse.pyRelated GitHub Issue(s)
#737
#736
Paves the way towards creating a consistent abstract, maintainable backend which may be used to swap specific backends as fashions change. Inches closer towards accomplishing our ambitious backend dreams.
Additional Context for Reviewers
I'm anticipating some hesitation on calling
xp.COOwherexpmeans the result ofTriangle.get_array_module. However, this replaces instances whenxpwas called directly, which could only be done if the backend was sparse anyway. Therefore, the risk level is the same with this replacement, and there are already existing mechanisms in place that mention that the backend is sparse prior to the call. This reorganization ofsparse.pyis needed before we can tackle replacingxp.COOwith something more generalized likexp.BackendArray.Note
Medium Risk
Touches core sparse-backend construction paths (
Triangleinit, slicing/assignment, arithmetic, and regression) and changes howsparse.COOis instantiated/default fill values are handled, which could affect numerical results or edge cases. Scope is contained to the sparse backend and is backed by new unit tests for key wrappers.Overview
Standardizes sparse-backend array construction to always use
sp.COO/xp.COO(instead of treatingsp/xpas a callable constructor), and updates several call sites (Triangleinitialization,.loc/.atsparse assignment, arithmetic validation, andWeightedRegression) accordingly.Refactors
utils/sparse.pyto clarify the type hierarchy by exposingCOOexplicitly, moving/aligning defaults likeCOO.nan, and trimming unused wrapper signatures; also adds a focusedtest_sparse.pysuite coveringarrayfill-value behavior pluswhereand in-placefloorsemantics.Reviewed by Cursor Bugbot for commit 0715793. Bugbot is set up for automated code reviews on this repo. Configure here.