Skip to content

feat: support Fortran order in COO.flatten - #964

Merged
hameerabbasi merged 1 commit into
pydata:mainfrom
Doribelove:feat/fortran-flatten
Oct 7, 2026
Merged

hameerabbasi merged 1 commit into
pydata:mainfrom
Doribelove:feat/fortran-flatten

Conversation

@Doribelove

Copy link
Copy Markdown
Contributor

COO.flatten(order="F") currently raises NotImplementedError, preventing column-major flattening of multidimensional sparse arrays. This adds the transpose-then-flatten implementation suggested in #603; for example, [[0, 1, 2], [3, 4, 5]] now becomes [0, 3, 1, 4, 2, 5].

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • 🪄 Feature
  • 🐞 Bug Fix
  • 🔧 Optimization
  • 📚 Documentation
  • 🧪 Test
  • 🛠️ Other

Related issues

Closes #603.

Checklist

  • Code follows style guide
  • Tests added
  • Documented the changes

Please explain your changes below.

For order="F", reverse the COO axes before using the existing C-order reshape. This operates on sparse coordinates and data, preserves the fill value, and keeps the existing behavior for the default order, "C", and None. Document the supported orders and add a column-major doctest. The change is limited to COO.flatten; reshape and GCXS order support are unchanged.

Regression coverage includes multidimensional, singleton, scalar and empty shapes; zero, nonzero and NaN fill values; arrays with no stored entries; narrow coordinate dtype promotion; and alternating C/F calls with caching enabled. A three-entry array with a logical size of 10^12 checks the resulting coordinates and values while rejecting dense conversion.

Validation on Python 3.12.14, NumPy 2.5.3, Numba 0.67.0 and SciPy 1.18.1:

  • New regression suite against the original implementation: 27 failed, 48 passed; failures were unsupported F-order calls.
  • Updated implementation: 75 flatten tests passed.
  • Full Numba unit tests and doctests: 6,431 passed, 15 skipped, 95 xfailed, 62 non-strict xpassed, with 2 warnings and no failures.
  • Repository pre-commit checks passed; both added executable lines were exercised by the coverage run.

AI assistance was used for implementation, tests, and drafting. The validation above was executed locally against this patch.

@github-actions github-actions Bot added the enhancement Indicates new feature requests label Sep 22, 2026
@Doribelove

Copy link
Copy Markdown
Contributor Author

CI triage for this PR: the Numba/Finch/MLIR test matrix, examples, notebooks, experimental tests, docs, and codecov/patch pass. The two red checks reproduce on other PRs that do not touch COO.flatten:

This branch changes only sparse/numba_backend/_coo/core.py and its COO tests. These comparisons suggest the red checks are not introduced by the flatten change; I am not claiming the overall CI is green. If a reviewer sees a PR-specific failure, I will address it.

AI assistance was used to prepare this CI comparison; I checked the linked GitHub Actions and Codecov check results.

@hameerabbasi
hameerabbasi merged commit ce8e567 into pydata:main Oct 7, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Indicates new feature requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Fortran order in COO.flatten()

2 participants