Re: [eigen] matrix / scalar

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


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
> ----------------------------------------------
>
>
>



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