Re: [eigen] Matrix::RowXpr::Nested is a reference... |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Matrix::RowXpr::Nested is a reference...
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Fri, 2 Oct 2009 08:15:17 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=HTsfip4pqL+ZhQ+8mAz2AZEcIEfnPS31dLES9oaFxGk=; b=E8klQ2CDH1NHH3UU4YABPbS7r1rceQklzfqDJWSri3JyeWsHiYd37FMhyBJxnXHjYi J1r2s4h5QK4SesMcq0bX0Jc4j1fw3HZOUfX9faS5hrMpvv6wDDAURFJFpWaNKsutT5jJ aSGsWzKCN56IDIvQdwUnb+LY+8QsCfMogZCW8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=a3+VMeRwRW/vpFFPsKY5jAniPvfapF1qc9FcM5cyApL3Y9NGlf0M1eIrZe9qGET1Nc h9kHLHlksI/vq8OZCZjZlH9D7E8K1qAQ4Ar6TB7p9nunOlqTx28wD/ZMVLoxDPHLcjSF sxyoycfeIIamrJWABnbR9xSZzXLJj/1d1w7BY=
Ah yes and for plain matrices, you really want to pass them by const
reference, so you'd still have to edit ei_nested to handle that case
separately, with a condition like:
ei_is_same_type<T, typename T::PlainMatrixType>::ret
Good luck ;)
Benoit
2009/10/2 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> 2009/10/1 Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>:
>> Is that correct as is?
>
> Yes. Check in Core/util/XprHelper.h:
>
> template< blabla > struct ei_nested
> {
> blabla
>
> typedef typename ei_meta_if<
> ei_must_nest_by_value<T>::ret,
> T,
> typename ei_meta_if<
> (int(ei_traits<T>::Flags) & EvalBeforeNestingBit)
> || ( int(CostEval) <= int(CostNoEval) ),
> PlainMatrixType,
> const T&
> >::ret
> >::ret type;
> };
>
> See the const T& above ? That's the solution used when doing
> ei_nested<RowXpr> by default.
>
>> In the following case
>>
>> Replicated<MatrixXd::RowXpr,2,1>(matrix.row(0))
>>
>> it means that it fails since matrix.row(0) returns a temporary to which a
>> reference is stored in Replicate.
>
> Yes, this is true.
>
> In most cases this is OK as the temporary is alive long enough.
>
> There are some corner cases where this is NOT OK for example if you
> want to write a function that returns such a Replicate object.
>
> For these corner cases, we have .nestByValue() which allows you to
> force that the row() object is nested by value.
>
> Now I don't remember for sure the exact reasons why we nest by
> reference by default, as indeed these are lightweight objects. I think
> that was just to avoid useless copying of objects which we feared
> would confuse the compiler. It's crucial that the compiler understands
> that it can inline all these objects and not actually construct them
> in memory.
>
> So it's that's only that, then, feel free with replacing const T& by T
> here and checking if the compiler still generates good code. If yes,
> then that sounds like great news, as we would then be able to get rid
> of NestByValue.
>
> Benoit
>
>>
>> I used this piece of code to verify my assumption:
>>
>> #include "Eigen/Core"
>>
>> #include "boost/type_traits/is_reference.hpp"
>>
>> void main()
>> {
>> typedef Eigen::MatrixXd::RowXpr::Nested type;
>>
>> std::cout << typeid(type).name();
>> if (boost::is_reference<type>::type::value == true) std::cout << "&";
>> std::cout << std::endl;
>> }
>>
>> Cheers,
>> Hauke
>>
>