-
Notifications
You must be signed in to change notification settings - Fork 311
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
Toggle row and column major layouts #603
Comments
I just realized there is a way, which is however pretty ugly: let a = Array::from_shape_vec((3,3), v.clone()).unwrap();
let e = Array::from_iter(a.t().iter().cloned()).into_shape((3,3)).unwrap().t().to_owned();
dbg!(a);
dbg!(e); Giving:
This also reveals one major deficiency of |
And finally a slightly cleaner version of the last example which is still very noisy: let a = Array::from_shape_vec((3,3), v.clone()).unwrap();
let f = Array::from_shape_vec((3,3).f(), a.t().iter().cloned().collect()).unwrap(); |
I use this extension trait in my own code: pub trait ToOwnedF<A, D> {
fn to_owned_f(&self) -> Array<A, D>;
}
impl<A, S, D> ToOwnedF<A, D> for ArrayBase<S, D>
where
A: Copy + Clone,
S: Data<Elem = A>,
D: Dimension,
{
fn to_owned_f(&self) -> Array<A, D> {
let mut tmp = unsafe { Array::uninitialized(self.dim().f()) };
tmp.assign(self);
tmp
}
} There probably should be a built-in way to this kind of thing. You may also be interested in #390, which discusses a closely-related problem. I think we should add a |
This will be covered by #390. |
I have an array in row major layout and I want to transpose its rows and columns such that it ends up in column major layout.
This, however, requires exchanging the elements and memory locations
(i,j)
and(j,i)
, which currently does not seem to be possible with ndarray. Or is it and I have overlooked a method?Take this example, which shows several different ways of creating a column major array:
This will give the result:
What I, however, require is:
The text was updated successfully, but these errors were encountered: