Skip to content

feat: add Dimension::from_slice - #1608

Merged
akern40 merged 1 commit into
rust-ndarray:masterfrom
SomeB1oody:dimension-from-slice
Oct 19, 2026
Merged

akern40 merged 1 commit into
rust-ndarray:masterfrom
SomeB1oody:dimension-from-slice

Conversation

@SomeB1oody

Copy link
Copy Markdown
Contributor

Closes #1330

Summary

Add Dimension::from_slice(&[Ix]) -> Option<Self>, which returns None when Self::NDIM.is_some_and(|n| n != ix.len()) (the fixed-size types require an exact length match and IxDyn accepts any length)

from_dimension now uses Self::from_slice(d.slice())

Tests

Added from_slice to tests/dimension.rs. cargo test passes.

Add a public `from_slice` that returns `None` when the slice length does not match the type's dimensionality (`IxDyn` accepts any length). Now `from_dimension` uses `from_slice`
@akern40
akern40 force-pushed the dimension-from-slice branch from 814fbe5 to 9ea47a6 Compare October 19, 2026 01:18
@akern40
akern40 merged commit 4ada8b9 into rust-ndarray:master Oct 19, 2026
15 checks passed
@akern40

akern40 commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the contribution and your patience!

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.

add associated constructor to Dimension trait

2 participants