@@ -1921,6 +1921,39 @@ where
19211921 }
19221922 }
19231923
1924+ pub fn into_shape_clone < E > ( self , shape : E ) -> Result < ArrayBase < S , E :: Dim > , ShapeError >
1925+ where
1926+ S : DataOwned ,
1927+ A : Clone ,
1928+ E : ShapeArg ,
1929+ {
1930+ let ( shape, order) = shape. into_shape_and_order ( ) ;
1931+ let order = order. unwrap_or ( Order :: RowMajor ) ;
1932+
1933+ if size_of_shape_checked ( & shape) != Ok ( self . dim . size ( ) ) {
1934+ return Err ( error:: incompatible_shapes ( & self . dim , & shape) ) ;
1935+ }
1936+ let layout = self . layout_impl ( ) ;
1937+
1938+ unsafe {
1939+ if layout. is ( Layout :: CORDER ) && order == Order :: RowMajor {
1940+ // safe because arrays are contiguous and len is unchanged
1941+ Ok ( self . with_strides_dim ( shape. default_strides ( ) , shape) )
1942+ } else if layout. is ( Layout :: FORDER ) && order == Order :: ColumnMajor {
1943+ // safe because arrays are contiguous and len is unchanged
1944+ Ok ( self . with_strides_dim ( shape. fortran_strides ( ) , shape) )
1945+ } else {
1946+ let ( shape, view) = match order {
1947+ Order :: RowMajor => ( shape. set_f ( false ) , self . view ( ) ) ,
1948+ Order :: ColumnMajor => ( shape. set_f ( true ) , self . t ( ) ) ,
1949+ } ;
1950+
1951+ Ok ( ArrayBase :: from_shape_trusted_iter_unchecked (
1952+ shape, view. into_iter ( ) , A :: clone) )
1953+ }
1954+ }
1955+ }
1956+
19241957 /// *Note: Reshape is for `ArcArray` only. Use `.into_shape()` for
19251958 /// other arrays and array views.*
19261959 ///
0 commit comments