CoW permute_axes #1026
-
I believe like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think what you're asking for is already available. use ndarray::prelude::*;
fn main() {
let a = array![[0., 1., 2.], [3., 4., 5.]];
assert_eq!(a.shape(), &[2, 3]);
let mut b = CowArray::from(a.view()).permuted_axes([1, 0]);
assert_eq!(b.shape(), &[3, 2]);
assert_eq!(b, array![[0., 3.], [1., 4.], [2., 5.]]);
assert!(b.is_view());
b[[0, 0]] = 6.;
assert!(b.is_owned());
assert_eq!(a, array![[0., 1., 2.], [3., 4., 5.]]);
assert_eq!(b, array![[6., 3.], [1., 4.], [2., 5.]]);
} Does that meet your needs? |
Beta Was this translation helpful? Give feedback.
I think what you're asking for is already available.
CowArray
andArcArray
have copy-on-write behavior, and.permuted_axes()
doesn't require a copy of the data, so you can just create aCowArray
orArcArray
and permute its axes. Here's an example usingCowArray
: