Matlab vs Python (was RE: Discussion: Introducing new operators for matrix computation)

Gregory Lielens gregory.lielens at fft.be
Tue Jul 18 08:54:10 EDT 2000


> Yep. See code below.
> 
> > BTW, you meant
> >
> > (a.E*b.E).M*(c.E*d.E).M
> >
> > for otherwise it is equivalent to (a.*b).*(c.*d).
> 
> Actually, I was thinking that elementwise multiplication would return
> an object that does matrixwise multiplication (the idea being that
> elementwise is a special case, just as .* is used for it instead of *
> in Matlab).
> 
> > >But what if we assume that if one operand has .E, the other does also!
> > >Then we can write
> > >
> > >(a.E*b)*(c.E*d)
> >
> > This won't work.  It would introduce many hard-to-trace bugs.  Looking at
> >
> > (a*b)*(c*d)
> >
> > and you have to trace the program all the way down to figure out the
> > identities of a,b,c,d.  Note that in concept the identities of the objects
> > do not change.  We are changing their identities only as labels to help
> > picking different operators.  I can foresee great confusion in practice with
> > this approach.
> 
> I realize this. Note that you have to trace the program to tell that
> a,b,c,d are matrices anyway :-). A lot of this is removed by always
> having an operation return a Matrixwise object. 


I think that it is the more elegant solution if the introduction of new
operators is rejected...
This could turn to be even more elegant, if it allow something like
C = A.I*b  to be equivalent to Matlab's C = A\b, i.e. without any
inversion of matrix A.

This kind of "retarded" evaluation could even lead to further
optimizations, and I tink
that the trace-back problem is avoided if we can ensure that any new
matrix that is produced and returned
by an expression evaluation or a function is always in a "blank" state,
i.e. without any I, T, H,... flag
on...

A minor problem of this approach could be the time spend in checking the
flags, but the main problem I see is that it will make the code for
*,+,...more complex for optimized version. For any unoptimized function
or operator, something like a FlagReset method shoul be called for all
arguments, to have the updated matrices...
If the flags treatment prove to take significative time, one solution
should to move them in the C struct which
implement NumPy arrays, which will makes thing even more complex, I am
affraid...
But appart from this complexity, this is quite appealing imho...


Greg.



More information about the Python-list mailing list