Re: [eigen] Matrix assignment |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Matrix assignment
- From: Cristóvão Sousa <crisjss@xxxxxxxxx>
- Date: Tue, 21 Oct 2008 13:07:47 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :user-agent:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; bh=QUafrGmz5cYM7DBA98yWHybtRSK7lwYG+btvfM0vjqQ=; b=nqHe79yzmxQvHakiepvZI1a8CjxuF8qfeNCyCMrZ50E4cLIUc+iVe4NCMn+q0UHTCP zGBDtEn+aW/R5tFy9fK0tV6RZwUp0IL/4gEU6oM0Vz5XLBl2nLSdjuED9b4tg58c6I/2 Ge9MmE+//5ny3ySq6OidHjyMAsLX4VhcL44VE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:references:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :message-id; b=l/y7d1G2vb30+UzV139TqfabkXGz6r6W9bVtVK1CayMn/ADu3mvZUlOCh34lsCYTBn 4Y1g2ON4/eNHlPA5otimMkplwonciMut8/kMepIpPkUCmCxc5BivcRJDHyKc08zgvhmz IMhBjRviWRguBK/BUGgyTb0YRmzfi1cphWkGU=
> Now what about the automatic resizing of operator= ? Honestly
I would
> not be against removing this feature and enforcing that the
left-hand
> side has the correct size. This is also more consistent with
> fixed-size matrices which cannot be resized anyway. In that
case we
> could add the folfowing exception: the lhs will still be
automatically
> resized if its size is 0. Well, currently we cannot create
such an
> empty matrix, but I think that would be nice to allow that
regardless
> of the automatic resizing issue.
Well, if the auto re-size was removed from operator= then a
couple of checks would be removed, right? But, introducing auto
re-size for zero sized matrices would introduce a check...
I think that the need of an auto/non-auto re-size feature will
always be dependent on the application:
- In a Matlab like style the matrices should be automatically
re-sized.
- Also, in a more traditional C++ approach, coping an object to
an other should make the destination object "equal" to the
original, as is proposed to happen with zero sized matrices.
- But in many cases, as in my specific application needs, it is
desirable to maintain the destination matrix size unaltered,
raising an failure if matrices have different sizes and debug
mode is enabled. This can eliminate the overhead (if any) of
checking sizes in non debug mode, and is more consistent with
fixed-size matrices, as you said.
I did had not mentioned but when I realise that the operator=
re-sizes the destination matrix, the first solution, which did
not worked, that comes to my mind was to use the .cwise() in the
lhs matrix:
m0.cwise() = m1;
as in "m0.cwise() += scalar".
This can be a solution too, although it could turn to be not
very clear if the rhs expression should be a matrix with equal
size or a scalar.
Another solution that may be nice is to deny any resizing unless
you call some function, like:
m0.copy(m1);
or
m0.assign() = m1;
Cheers,
Cristóvão Sousa
---