Re: [eigen] rvalue refs - std::swap |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: Eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: [eigen] rvalue refs - std::swap
- From: Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>
- Date: Wed, 28 Oct 2009 01:59:51 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=mSAeGL+vO9le0Bgu5AXX4sSyheJWFrwYFiOBTObGl5M=; b=Elsq6H9TkAsrUdcV42ldmeLlIcIegUxXKDS0pw6sbzsJslw9VCqTu+y/DUHA3RV0wb J9KJjTu6OjtW1j7oMd06ZBZQyOJ5Y0KiwCFeRYdUr8M6DGn1Gq8WWc/vt4gIBSO3Bajk nMLm6iGT5GUHAcsoKr8vT1j3pepMRll2bALwg=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=G1BWhkTuZtdqCo1pJI6OlL7eYdvVOSGvrVZTK9VZGWQV8Yp/CoMp8xQlBfrcemyOsN +IdE9SuDsH09FfaHn2VmUetybeW9awLXp9/ELY+I9PKebwpiaqndeDxIB2t5br7V4mxb x28fZ5da5RR56vOhe4wlUBXY7e5hYx8V8wPOc=
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