Re: [eigen] new tutorial on writing functions taking Eigen types as paramters |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] new tutorial on writing functions taking Eigen types as paramters
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Mon, 16 Aug 2010 15:23:13 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=BXwjWEUbHo2JsAxMyLzLyQGJStHwpwUwmoHWyuj915U=; b=qtOJntohXEp+kPkjXFaTfuHaOxJQtoseVUgZGj6ZMfuh2VVDUq6Zkkzo7fHvJC9yPr 2PukrKRz3D1gf8sePVtFvmQiR9myjlA4DPnQX34RzlCeUwifEsL6NcZuDx0Rgo/hu7yn NnQUcpM3QRu9WpUVoHaJM8Kxs9F4JyAjjHNNU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=meQLsXsjTLBg0VtEZkPincoSo+1ke/zIahHnCEodMOIbTavggI8yXru6rhowoRBXsJ 4igo1db5qMrf1SBkaRYI18VDwEitNBnFT+U1su1XefhaHdfB2pvAdQ+cZjjOu7LR5hHd y1kqzFuR50awxUoNNA/geBIJjenMiy0aM99WU=
On Mon, Aug 16, 2010 at 12:13 PM, Hauke Heibel
<hauke.heibel@xxxxxxxxxxxxxx> wrote:
> On Mon, Aug 16, 2010 at 11:55 AM, Gael Guennebaud
> <gael.guennebaud@xxxxxxxxx> wrote:
>> On Thu, Aug 5, 2010 at 3:48 AM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
>>> - mention Nested (at the end of the page! it's an advanced topic, but
>>> it's important for advanced users).
>>
>> I don't think this is an advanced topic, and to be safe, every
>> argument should be systematically converted to their nested type:
>
>> template<typename Derived> void foo(const MatrixBase<Derived>& _x)
>> {
>> typename Derived::Nested x (_x);
>> // use x, not _x
>> }
>
> Do we need this as a safeguard for types that require evaluation
> before nesting? Here it would be more like "require evaluation before
> further usage".
>
> But is it really true, that we need something like this? Could you
> maybe help me out with a use case? When somebody were passing a
> product, that would anyways use it's internal temporary, right?
yes, for instance for products, or the objects returned by the solve
functions. Here is an example:
template<typename Derived> void foo(const MatrixBase<Derived>& x)
{
if(x(0,0) >0) ...
}
This code will work most of the time but not always.
Another issue is when the argument is used multiple time and it is en
expensive operation... In this case the function writer has to use the
internal ei_nested<> helper class... My opinion is that we should come
up with a simple mechanism/rule to declare and use arguments, and
encourage user to always use it, e.g.:
EIGEN_ARG(DerivedA, _a, a, 2);
EIGEN_ARG(DerivedB, _b, b, 1);
EIGEN_ARG(<type>, argument_name, variable_name,
number_of_time_each_coeff_of_the_argument_is_read);
^^ this is just a poor proposal to get the idea.
The alternative would be to "fix" Eigen itself, but I don't know how to do so...
>
>> For advanced user we should also explain ei_nested which is preferred
>> if the argument is used more than once. Since ei_nested is mostly
>> internal, maybe we should also add a slightly higher level public
>> wrapper....
>
> Should not ei_nested<Derived> in theory be the same as Derived::Nested?
Yes, they are the same, but ei_nested is more powerful since it allows
you to tell how many time the object is being used, and more...
gael
>
> - Hauke
>
>
>