Pected struct `na::VecStorage`, found struct `na::SliceStorage`


#1

Hi,

I create a matrix and it works

let X = DMatrix::from_iterator(
                rows,
                cols,
                temp
                .iter()
                .cloned(),
                );

I now need to take a slice using the below:

      let xx = X.rows(0,holdout_rows);

Here is my error:

                 return xx                                                                                                                                       
|                        ^^ expected struct `na::VecStorage`, found struct `na::SliceStorage`    

How so I get back to VecStorage?


#2

Hi!

To get back to a matrix backed by a VecStorage, you need to call xx.into_owned() or xx.into() equivalently.

This conversion step is necessary because a slice does not own its data (it contains an internal pointer to X). The .into_owned or .into methods will allocate a new new matrix and copy the selected rows into it.