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

Huaiyu Zhu hzhu at localhost.localdomain
Mon Jul 17 21:20:16 EDT 2000


On Mon, 17 Jul 2000 19:22:31 -0500, Paul Prescod <paul at prescod.net> wrote:

>I don't think you need __getattr__
>
>class Matrix:
>	def __init__( self, ....):
>		self.T=Transpose( self )
>		self.H=Hermitian( self )
>		self.I=Inverse( self )
>		self.C=Conjugate( self )
>		self.E=Elementwise( self )
>		self.M=self # matrixwise is default
>	... other matrix-like methods ...
>
>class Transpose:
>	def __init__( self, mymatrix ):
>		self.mymatrix=mymatrix
>	... other matrix-like methods, but transposed ...
>
>Notice that no computation (e.g. actual transposition) needs to be done
>until you actually need to calculate a value. Maybe you can find
>optimizations that allow only tiny parts of matrices to be computed.

This is interesting.  I suppose the computational cost is minimum. What
about implementation?  Do I have to write everything five times?  Right now
I'm even using .T() to avoid writing both left and right computations.  It
cost some computation but saves a lot of implementation and maintainence.
Note that even one liners are relatively big cost because most of the
current functions are just one liners.

Huaiyu



More information about the Python-list mailing list