@@ -1701,6 +1701,39 @@ where
17011701 }
17021702 }
17031703
1704+ pub fn into_shape_clone < E > ( self , shape : E ) -> Result < ArrayBase < S , E :: Dim > , ShapeError >
1705+ where
1706+ S : DataOwned ,
1707+ A : Clone ,
1708+ E : ShapeArg ,
1709+ {
1710+ let ( shape, order) = shape. into_shape_and_order ( ) ;
1711+ let order = order. unwrap_or ( Order :: RowMajor ) ;
1712+
1713+ if size_of_shape_checked ( & shape) != Ok ( self . dim . size ( ) ) {
1714+ return Err ( error:: incompatible_shapes ( & self . dim , & shape) ) ;
1715+ }
1716+ let layout = self . layout_impl ( ) ;
1717+
1718+ unsafe {
1719+ if layout. is ( Layout :: CORDER ) && order == Order :: RowMajor {
1720+ // safe because arrays are contiguous and len is unchanged
1721+ Ok ( self . with_strides_dim ( shape. default_strides ( ) , shape) )
1722+ } else if layout. is ( Layout :: FORDER ) && order == Order :: ColumnMajor {
1723+ // safe because arrays are contiguous and len is unchanged
1724+ Ok ( self . with_strides_dim ( shape. fortran_strides ( ) , shape) )
1725+ } else {
1726+ let ( shape, view) = match order {
1727+ Order :: RowMajor => ( shape. set_f ( false ) , self . view ( ) ) ,
1728+ Order :: ColumnMajor => ( shape. set_f ( true ) , self . t ( ) ) ,
1729+ } ;
1730+
1731+ Ok ( ArrayBase :: from_shape_trusted_iter_unchecked (
1732+ shape, view. into_iter ( ) , A :: clone) )
1733+ }
1734+ }
1735+ }
1736+
17041737 /// *Note: Reshape is for `ArcArray` only. Use `.into_shape()` for
17051738 /// other arrays and array views.*
17061739 ///
0 commit comments