[C++-sig] Expression templates in python

Stefan Seefeld seefeld at sympatico.ca
Mon Oct 10 16:52:24 CEST 2005

David Welch wrote:
> Hi,
> I am new to python and thought I would write a vector / matrix class in 
> c++ and export to python.
> Is it possible to have vector operations done in python evaluate to some 
> form of intermediate calculation object which can then be passed to the 
> c++ code for evaluation?
> ie,
> 	V1 = [0.1,0.2,0.3]
> 	V2 = [0.7,0.4,0.7]
> 	V3 = V1*4 - V2*V1

Not really, at least not with that straight forward syntax. The reason
is that the 'V1' name above is bound to the object '[0.1,0.2,0.3]',
which has type 'list', i.e. python is 'dynamically typed'.

May be you could play games if 'V1' is an attribute of an object,
for which you overload the 'setattr' method ?


More information about the Cplusplus-sig mailing list