You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe like to_shape (which is great btw, I really like using it!) it would be really handy to have a copy on write version of permute_axes, which only copies the matrix if it is written to. Would such a method be possible? I'm using permute_axes to do some tensor computations at the moment.
I think what you're asking for is already available. CowArray and ArcArray have copy-on-write behavior, and .permuted_axes() doesn't require a copy of the data, so you can just create a CowArray or ArcArray and permute its axes. Here's an example using CowArray:
use ndarray::prelude::*;fnmain(){let a = array![[0.,1.,2.],[3.,4.,5.]];assert_eq!(a.shape(),&[2,3]);letmut 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.]]);}
Activity
jturner314 commentedon Jun 5, 2021
I think what you're asking for is already available.
CowArrayandArcArrayhave copy-on-write behavior, and.permuted_axes()doesn't require a copy of the data, so you can just create aCowArrayorArcArrayand permute its axes. Here's an example usingCowArray: