Re: [eigen] Why do const accessors return by value? |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Why do const accessors return by value?*From*: Patrick Mihelich <patrick.mihelich@xxxxxxxxx>*Date*: Tue, 31 Mar 2009 23:27:52 -0700*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; bh=OimycVODmktjEbje8GP8HOnFFEan+lDdLOYUJYLRNk8=; b=lXHowvNG5CHgypk8qzwiYuiM4+6dpKHrpAgfKqqq2XUHDiFcxwh5ShbUPs1oYtQet5 dc2abtIrdVFWvLytv+GVOrLiRRoTSDnYxEYq/MNhohiatS/0reflQmATwnQrdcVaYLWS E89sUe6l+/gP187KAREJiabcclWdXOfzo8hJQ=*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; b=aH90QVYo7sb6IeILWSltrCyHBFn7qYUrI6Vdx0RUXlLfBLRuIB/F1U3Am7itCrCHxT FJIeLVa8Ojrkrva/E78E8V5Gu3Mvjzyk6y2YmpvQWKUXAuvgGxf4Y0PM8yk1nLVr+lRY KJ+rE4fDXUFpbv/GhHAZoDUYa//TSYsaPx/AY=

Great, thanks Benoit for the quick response.

Patrick

On Tue, Mar 31, 2009 at 5:45 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:

2009/3/31 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:

> 2009/3/31 Patrick Mihelich <patrick.mihelich@xxxxxxxxx>:It's done now (in trunk).

>> OK, right. But you do not always have to use the lowest-common-denominator

>> behavior (return by value). MatrixBase knows the Derived type and can return

>> by const-reference for Derived types with dense storage (Matrix, Map).

>

> ah right, good idea. I'll look into that.

>

>> OK but this is more verbose, and it's rather surprising that it doesn't do

>> the same thing as m(i,j) or even m.coeff(i,j). I do not think Matrix should

>> override the coeff() methods from MatrixBase with different signatures; more

>> generally I'd suggest that for any MatrixBase method foo, m.foo() and

>> m.derived().foo() should always behave identically.

>

> I understand. Good idea. I do that and I update you....

I have actually taken a shortcut compared to the traditional c++ way

of doing this as you exposed.

Namely, Eigen expressions already had a DirectAccess flag which means

that coeffRef is available and that the data is stored

piecewise-contiguously in memory (piecewise meaning that a "stride" is

allowed between consecutive rows/cols).

So what I did was define a CoeffReturnType in MatrixBase, that is

either "const Scalar&" or "Scalar" depending on whether the xpr has

the DirectAccess flag, that's all.

That has the advantage of being a small local modification and not

requiring any more boilerplate code in all xpr classes.

part of the same commit.

>

>> BTW, there is a mistake in MapBase: const Scalar coeff(int index) const

>> should return const Scalar&.

>

> woops, good catch !

Cheers,

Benoit

**References**:**Re: [eigen] Why do const accessors return by value?***From:*Benoit Jacob

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] LDLt and LLt fixes** - Next by Date:
**[eigen] Overflow in sum()** - Previous by thread:
**Re: [eigen] Why do const accessors return by value?** - Next by thread:
**Re: [eigen] LDLt and LLt fixes**

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