Re: [eigen] a few updates... |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] a few updates...
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Wed, 22 Dec 2010 22:49:04 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=y1s0Ie6UmlLtG812k38ICdSPgo6wGftfit3d3crBSB0=; b=jiA2NrNRKKTS9oyugfUVbztUgeVcpAtptvrenQ+xUfTyWihjOcC1GpP1dQl78eCL0O yTz4t0Jg2RkTif1XaKcmGVMEKOwJ+36WBtRKfFkaYOfFgVOdBFfS2XUCDxs2GKuP8VAW 1wf9DA/2eSoG5T8hf8wP7Y6nW++EOCgdB7ma4=
- 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=JDTw9bMAyTSACeffSSSN32pxECHLYULnpySke3FfgpeBSeU++9buUahtsDCLOJTmWb aYHIDmoHxysFTwf7/uKrJ9HEZOIKPXy/aQycLnfL28itErqILg3W4OpkcfbNQGextm2r mjeuq+RPFbCRMaGNztC9j+QAOuYQUa/cl1m70=
2010/12/22 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> 2010/12/22 Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>:
>> On 22.12.2010 19:33, Benoit Jacob wrote:
>>> 2010/12/22 Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>:
>>>> Another possibility would be:
>>>> c) Pass argument to swap() by value if it is a Map/Block-expression.
>>>
>>> I tried that, using a enable-if trick to select abstract expressions
>>> vs. plain objects.
>>>
>>> The problem is that that doesn't solve the problem at all. By passing
>>> the expression by value, we completely forget its constness, so we
>>> can't prevent doing
>>> const Expression xpr;
>>> foo.swap(xpr);
>>
>> Well that's again all about bug54.
>
> You're right, see below...
>
>> Having, e.g., a `const ColXpr` does
>> not prevent modifying its data -- the constness must be encoded directly
>> in the type (as it is in `Map<const T>`). Otherwise you can do:
>>
>> const MatrixXd m;
>> MatrixXd::RowXpr r(m.row(0));
>
> Nope, that you can't do anymore with my changes, because row(Index)
> const now returns a Block<const T>...
>
> ...but you're still right, because there's nothing I can do to prevent this:
>
> const ExpressionType someConstXpr;
> ExpressionType someXpr(someConstXpr);
> someXpr.writeStuff();
>
> ...so, indeed, const on ExpressionType can't be enforced, the only
> enforceable constness for expression types is const on template
> parameters i.e. Block<const T>.
>
> In my local changes, all const-qualified expression-returning methods
> return such "inherently const" types (like Block<const T>). I just was
> under the wrong impression that we could do something to ensure that
> when the user writes a function like
>
> template<typename T> void foo(const DenseBase<T>& x)
> {
> ...
> }
>
> we could guarantee that x can't be written too, but thank you for
> reminding me why that isn't the case.
>
> So, thanks for reorienting this debate in the right direction:
> - this remaining const correctness issue is not specific to swap, and
> not specific to Eigen, but is inherent to expression templates and
> more generally, writable wrapper classes in c++.
> - there is no need for what i called 'solution b', it won't help with that.
>
>> Back to the swap-problem I can suggest another possibility:
>> d) Mark most methods of Map<T> and Block<T> as const (everything that
>> does not alter the Map or Block itself). Then have three possible
>> parameters for swap:
>> Matrix<...> &
>> const Block<T> &
>> const Map<T> &
>
> Don't worry, all of that is already done in my changes, but I didn't
> have to special-case Map and Block, it works for all expressions.
>
> I'll write about my changes as soon as I push them.
Pushed! But I really dont have time to write now.
Benoit
>
> Benoit
>
>>
>> where the latter two could be combined as soon as
>> direct-access-unification is done.
>>
>> Christoph
>>
>> --
>> ----------------------------------------------
>> Dipl.-Inf. Christoph Hertzberg
>> Cartesium 0.051
>> Universität Bremen
>> Enrique-Schmidt-Straße 5
>> 28359 Bremen
>>
>> Tel: (+49) 421-218-64252
>> ----------------------------------------------
>>
>>
>>
>