On Sun, 27 Jul 2008 02:23:11 am [EMAIL PROTECTED] wrote:

> How about just making a matrix multiply function that can take many
> arguments?  I think this is pretty readable:
>
> mmul(a, b, c, d)
>
> Additionally, mmul could then optimize the order of the
> multiplications (e.g., depending the dimensions of the matrices, it
> may be much more efficient to perform a*((b*c)*d) rather than
> ((a*b)*c)*d).

But be careful there: matrix multiplication is associative, so that 
a*b*c = (a*b)*c = a*(b*c), but that doesn't necessarily apply once the 
elements of the matrices are floats. For instance, a*(b*c) might 
underflow some elements to zero, while multiplying (a*b)*c does not. As 
a general rule, compilers should not mess with the order of floating 
point calculations.

Also, some classes that people might want to multiply may not be 
associative even in principle. E.g. the vector cross product:

(a*b)*c != a*(b*c) in general.

I think a product() function that multiplies the arguments from left to 
right would be useful. But it won't solve the problems that people want 
custom operators to solve. I'm not even sure if it will solve the 
problem of matrix multiplication.


-- 
Steven.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to