Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve to_ndarray with better dimensionality awareness #2

Closed
Enet4 opened this issue Oct 6, 2017 · 1 comment
Closed

Improve to_ndarray with better dimensionality awareness #2

Enet4 opened this issue Oct 6, 2017 · 1 comment

Comments

@Enet4
Copy link
Owner

Enet4 commented Oct 6, 2017

At the end of #1, there was a discussion of whether it would be possible to specify the dimensionality for the Array created with to_ndarray. In particular, it might be more useful to have this method prototype instead:

fn to_ndarray<T, D>(self) -> Result<Array<T, D>>
where
    T: ...,
    D: IntoDimension;

I will leave this issue for discussion on the feasibility of this. Basically, this requires a conversion (which can fail) from a dynamic shape to an arbitrary dimension type D. I haven't found a way to do this yet in ndarray. There is also the small drawback that one has to specify two parameter types instead of just one. IxDyn is a good default, but default type parameters do not work on functions (rust/#36887).

@Enet4
Copy link
Owner Author

Enet4 commented Jul 23, 2018

It turns out that there is .into_dimensionality(), which would make it significantly easier to obtain a fixed dimension array.

let arr = volume.to_ndarray()?.into_dimensionality::<Ix3>()?;

I would suggest leaving to_ndarray alone and advise users to rely on this method if so is desired.

@Enet4 Enet4 closed this as completed Sep 19, 2018
Enet4 pushed a commit that referenced this issue Jun 6, 2023
change the main branch name in the github workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant