[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Ideas for auto BSX
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Ideas for auto BSX |
Date: |
Fri, 30 Sep 2011 14:11:00 -0500 |
Because we don't use the bug tracker mailing list anymore. I'm
forwarding the following discussion to the maintainers' list.
---------- Forwarded message ----------
From: Dr. Alexander Klein <address@hidden>
Date: 2011/9/30
Subject: Re: [bug #34441] Weird bug with vector subtraction
To: Jordi Gutiérrez Hermoso <address@hidden>
Cc: Michael D Godfrey <address@hidden>, address@hidden
(Sorry for the duplicate, I forgot to include the bug-tracker address.)
Am 30.09.2011 um 20:55 schrieb Jordi Gutiérrez Hermoso:
> It's not a bug. It's a feature I implemented recently. It's equivalent to
>
> bsxfun(@minus, [1 2 3], [1 2 3]')
Jordi,
thanks for replying, I see what you mean, and it's really an interesting option.
However, this can lead to serious headaches when debugging code with a
lot of linear algebra. Here's an example.
Suppose you mistakenly write:
octave:1> a=[1 2 3];b=[3 4 5]';c=[6 7 8]';
octave:2> (a-b)*c
error: operator -: nonconformant arguments (op1 is 1x3, op2 is 3x1)
The old version will give you an error.
With the new semantics this gets expanded to matrix * vector:
octave:1> a=[1 2 3];b=[3 4 5]';c=[6 7 8]';
octave:2> (a-b)*c
ans =
-19
-40
-61
Now, if the erroneous transposition of b happens somewhere far away in
the code, and you rely on "-" failing due to the dimension mismatch,
this error will be virtually impossible to spot.
So, while I think this is quite useful, it should by no means be
called "-" in my opinion. Perhaps ".-" would do? I've never seen
anyone use this.
Kind regards,
Alex
--
Dr. Alexander Klein, Diplom-Mathematiker
Physiologisches Institut | TransMIT Zentrum
Raum 543 | für Numerische Methoden
Aulweg 129 | Heinrich-Buff-Ring 44
35392 Giessen | 35392 Giessen