Re: [eigen] rvalue refs - std::swap

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Ok, I started looking into the correct implementation and here are my findings ... based on some samples.

These are the datatypes I will use in the following examples:

MatrixXf m,n;
VectorXf v;
RowVectorXf rv;

1) m.swap(n)

- calls Matrix::swap(MatrixBase<OtherDerived> & other) -> ei_matrix_storage::swap(ei_matrix_storage& other)
- does actually swap the data

2) m.swap(MatrixXf())

- calls Matrix::swap(MatrixBase<OtherDerived> && other) -> ei_matrix_storage::swap(ei_matrix_storage&& other)
- basically assigns the temporary storage to m

3) n./m.swap(MatrixXf::Random(5,10))

- calls Matrix::swap(MatrixBase<OtherDerived> const && other) -> Matrix::lazyAssign(const MatrixBase<OtherDerived>& other)
- the right hand side is const and thus we can simply assign it lazily to the left hand side

4) m.row(1).swap(m.row(2))

- calls MatrixBase::swap(MatrixBase const & other) which is currently untouched

5) rv.resize(10); rv.swap(m.row(2));

- calls Matrix::swap(MatrixBase<OtherDerived> && other) -> MatrixBase::swap(MatrixBase const & other)
- as before, calls MatrixBase::swap due to ei_matrix_swap_impl selection (rhs is not a Matrix)

6) v.resize(10); v.transpose().swap(m.row(2)) or v.resize(10); v.transpose().swap(m.row(2));

- calls Matrix::swap(MatrixBase<OtherDerived> && other) -> MatrixBase::swap(MatrixBase const & other)
- as before, calls MatrixBase::swap due to ei_matrix_swap_impl selection (rhs is not a Matrix)

6) m.swap(m*n);

- Well, this is bad. I am not sure how we can prevent this...

All required changes are in the patch attached to this mail. I did not yet push it, since the changes are big. Also, I am not sure whether

ei_matrix_swap_impl<...,...,false>::run(MatrixType& matrix, MatrixBase<OtherDerived>& other)

is required anymore. With my examples it is not but maybe I am simply too tired to think about a proper use case.

MatrixBase is not yet touched - I am not sure whether that is even required right now.

That's it so far... good night,

- Hauke

Attachment: rvalue_review.patch
Description: Binary data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/