Re: [eigen] matrix / scalar |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] matrix / scalar
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Sat, 4 Dec 2010 08:28:57 -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=dGPsCxw+bJb36JU3Q9WjKtLDE9PaBDP8IWlZPW4ksjs=; b=vqBLTtvSPn9hBMACnaM0MCmc+T0zRe+lU43j5DrI+D3kdu/vcsMkIIazoSN8y77DXk 4/I+WxwPCCwyL7MYhD5QswaDcMyIqBD1esl76KmrbhBD3DsT9XHsSnxetHDq7IMDVY4a UsrWnvLujFpg+wIT9ccNl5HPo7eGntgQshlFk=
- 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=M/NiSobwLj/8sUce3zzvdz3wzx997jHfiQmw1KBZQAUPGIIyeo/u17S2tbb+GnzIr8 JDZl894TDSwTNSP7c4J2MinRP1Jjsn9T0Ivz805FeMzYAu0b+PILKoFGouJ/AIQNQRn1 1BCYlhaCT0Dxc4bzphZQZ/s94iIhms8VHI+rA=
2010/12/4 Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>:
> On 04.12.2010 08:50, Andy Somogyi wrote:
>> Hi. I was just thinking that it might be nicer to do
>> MatrixXi mat = ...;
>> mat = 5;
>>
>> instead of
>>
>> mat.setConstant(5);
>>
>> and
>>
>> mat += 5;
>>
>> is nicer than
>>
>> mat.array() += 5;
>>
>> The matrix interface supports scalar multiply but not scalar add/sub. To get scalar add/sub, I have to pull out the array class.
>>
>> No big deal either way, just thought it would be nicer syntax.
>
> I'm against that, because if it was implemented I'd expect + and * to be
> somewhat distributive, i.e.,
> MatrixXd A, B;
> double s;
> (A + s) * B == A*B + s*B;
>
> That means for matrices I would prefer A + d == A + d*eye(), but as this
> might be confusing I rather prefer not to have Matrix + scalar
> implemented at all. (Just my 0.02€ ...)
Exactly. This was discusseed many times but that was a long time ago,
and that was indeed the argument. There are two different worlds here:
on the one hand, matrices, subject to the rules of linear algebra,
where the multiplicative unit is the identity matrix; on the other
hand, arrays, where arithmetic is performed coefficient-wise and
therefore the multiplicative unit is the array filled with 1's. So if
we allowed "mat+1" at all, it should give mat+identity. That's what a
mathematician would expect here. However, since that would be
surprising to many people, we don't allow it (rule #298 of api design:
don't be surprising).
Benoit
>
> If you need this a lot, why not use Array in the first place?
>
> Christoph
>
> --
> ----------------------------------------------
> Dipl.-Inf. Christoph Hertzberg
> Cartesium 0.051
> Universität Bremen
> Enrique-Schmidt-Straße 5
> 28359 Bremen
>
> Tel: (+49) 421-218-64252
> ----------------------------------------------
>
>
>