pub fn transpose(self) -> Self
    where
        T: Send + Sync + Copy,
    {
        match &self.shape {
            Shape::Scalar(_) => self,
            Shape::Vector([n]) => Self::new_with_values([*n, 1], self.values).unwrap(),
            Shape::Matrix([m, n]) => {
                let mut values = self.values.clone();
                matrix::transpose_mat([*m as usize, *n as usize], &self.values, &mut values);
                Self::new_with_values(Shape::Matrix([*n, *m]), values).unwrap()
            }
            shape @ Shape::Tensor(_) => {
                // inner matrix tmp
                let shape_len = shape.as_slice().len();
                let [n, m] = shape.last_two().unwrap();
                let [m, n] = [m as usize, n as usize];
                let mut tmp = Vec::with_capacity(n * m);
                tmp.extend_from_slice(&self.values[..n * m]);

                // TODO
                // 2 million iq move: copy the first slice then use the first slice as the tmp
                //   array

                let mut values = Data::with_capacity(shape.span());
                for submat in ColumnIter::new(&self.values, n * m) {
                    matrix::transpose_mat([n, m], submat, &mut tmp);
                    values.extend_from_slice(&tmp);
                }

                let mut shape = shape.clone();
                shape[shape_len - 1] = n as u32;
                shape[shape_len - 2] = m as u32;

                Self::new_with_values(shape, values).unwrap()
            }
        }
    }
/// In the case of Tensors transpose the inner matrices
/// e.g. Shape `[3, 4, 5]` becomes `[3, 5, 4]`
In the case of Tensors transpose the inner matrices
e.g.
In the case of Tensors transpose the inner matrices e . g .
pub fn transpose(self) -> Self
    where
        T: Send + Sync + Copy,
    {
        match &self.shape {
            Shape::Scalar(_) => self,
            Shape::Vector([n]) => Self::new_with_values([*n, 1], self.values).unwrap(),
            Shape::Matrix([m, n]) => {
                let mut values = self.values.clone();
                matrix::transpose_mat([*m as usize, *n as usize], &self.values, &mut values);
                Self::new_with_values(Shape::Matrix([*n, *m]), values).unwrap()
            }
            shape @ Shape::Tensor(_) => {
                // inner matrix tmp
                let shape_len = shape.as_slice().len();
                let [n, m] = shape.last_two().unwrap();
                let [m, n] = [m as usize, n as usize];
                let mut tmp = Vec::with_capacity(n * m);
                tmp.extend_from_slice(&self.values[..n * m]);
                // TODO
                // 2 million iq move: copy the first slice then use the first slice as the tmp
                //   array
                let mut values = Data::with_capacity(shape.span());
                for submat in ColumnIter::new(&self.values, n * m) {
                    matrix::transpose_mat([n, m], submat, &mut tmp);
                    values.extend_from_slice(&tmp);
                }
                let mut shape = shape.clone();
                shape[shape_len - 1] = n as u32;
                shape[shape_len - 2] = m as u32;
                Self::new_with_values(shape, values).unwrap()
            }
        }
    }
pub fn transpose ( self ) -> Self where T : Send + Sync + Copy , { match & self . shape { Shape :: Scalar ( _ ) => self , Shape :: Vector ( [ n ] ) => Self :: new_with_values ( [ * n , 1 ] , self . values ) . unwrap ( ) , Shape :: Matrix ( [ m , n ] ) => { let mut values = self . values . clone ( ) ; matrix :: transpose_mat ( [ * m as usize , * n as usize ] , & self . values , & mut values ) ; Self :: new_with_values ( Shape :: Matrix ( [ * n , * m ] ) , values ) . unwrap ( ) } shape @ Shape :: Tensor ( _ ) => { // inner matrix tmp let shape_len = shape . as_slice ( ) . len ( ) ; let [ n , m ] = shape . last_two ( ) . unwrap ( ) ; let [ m , n ] = [ m as usize , n as usize ] ; let mut tmp = Vec :: with_capacity ( n * m ) ; tmp . extend_from_slice ( & self . values [ .. n * m ] ) ; // TODO // 2 million iq move: copy the first slice then use the first slice as the tmp //   array let mut values = Data :: with_capacity ( shape . span ( ) ) ; for submat in ColumnIter :: new ( & self . values , n * m ) { matrix :: transpose_mat ( [ n , m ] , submat , & mut tmp ) ; values . extend_from_slice ( & tmp ) ; } let mut shape = shape . clone ( ) ; shape [ shape_len - 1 ] = n as u32 ; shape [ shape_len - 2 ] = m as u32 ; Self :: new_with_values ( shape , values ) . unwrap ( ) } } }
In the case of Tensors transpose the inner matrices
e.g.
In the case of Tensors transpose the inner matrices e . g .
self