Skip to content

Fix ndarray from_iterator for column-major input - #483

Merged
Mec-iS merged 3 commits into
smartcorelib:mainfrom
jolars:fix/ndarray-from-iterator
Oct 12, 2026
Merged

Mec-iS merged 3 commits into
smartcorelib:mainfrom
jolars:fix/ndarray-from-iterator

Conversation

@jolars

@jolars jolars commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #482

I've pulled this fix out of #480 so we can review and merge it on its own.

Current behaviour

The ndarray implementation of from_iterator first builds a row-major array, then reverses its axes and reshapes it for column-major input. That reshape can panic for rectangular matrices. For example, from_iterator(1..=6, 2, 3, 1) fails instead of producing [[1, 3, 5], [2, 4, 6]]. This also affects callers such as h_stack.

New expected behaviour

The constructor uses the requested order directly: row-major for axis = 0 and column-major for axis = 1. Column-major input now produces a column-major array with the expected values and dimensions.

Change logs

Validation

I ran these checks locally with Rust 1.99.0:

cargo build --all-features
cargo test --all-features
cargo fmt --all -- --check
cargo clippy --all-features -- -Drust-2018-idioms -Drust-2024-compatibility -Dwarnings

Checklist

  • My branch is up-to-date with main branch.
  • Everything works and tested on latest stable Rust.
  • Coverage and Linting have been applied.

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.44%. Comparing base (9eaae9e) to head (e501c94).
⚠️ Report is 199 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #483       +/-   ##
===========================================
+ Coverage   43.97%   85.44%   +41.47%     
===========================================
  Files          85       96       +11     
  Lines        7281     9367     +2086     
===========================================
+ Hits         3202     8004     +4802     
+ Misses       4079     1363     -2716     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Mec-iS

Mec-iS commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

@Mec-iS
Mec-iS merged commit f9a5496 into smartcorelib:main Oct 12, 2026
13 checks passed
@Mec-iS Mec-iS mentioned this pull request Oct 12, 2026
3 tasks done
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.

ndarray from_iterator panics on rectangular column-major input

2 participants