From: Allen B. <al...@vr...> - 2003-03-31 05:13:56
|
Patrick Hartling wrote: > Allen Bierbaum wrote: > >> Patrick Hartling wrote: >> >>> Allen Bierbaum wrote: >>> >>>> Patrick Hartling wrote: >>>> >>>>> I have spent many hours today working on exposing GMTL classes and >>>>> functions for use with Python, and while I have made a ton of >>>>> progress, I have reached something of an impasse. While it is >>>>> possible to instantiate and manipulate matrices, vectors, etc. in >>>>> Python, it is not possible at this moment to read any data from >>>>> them. The GMTL interface is built up around C++ data access >>>>> idioms, and some of those (operator[] in particular) do not >>>>> translate to Python. The biggest issue I face is that there is no >>>>> way (at this time) to map a C-style array to Python using >>>>> Boost.Python. Even if there were a way to do that, Python doesn't >>>>> have a data structure with exactly the same semantics as a C-style >>>>> array. The only GMTL class that is even close to having its data >>>>> be readable is gmtl::Matrix<>, and that's only because it overloads >>>>> operator(), one of the few class operators that can be overloaded >>>>> in Python. Of course, I can't get the relevant Boost.Python code >>>>> to compile, so the point is moot. >>>> >>>> >>>> >>>> >>>> >>>> Why can't we use python's [] operator? Is there something about >>>> Boost::Python that prevents this overload from taking place or is >>>> the problem related to slicing? >>> >>> >>> >>> >>> I don't know how to overload that operator. Pyste didn't do it >>> automatically, and I have been having trouble making sense of how >>> Boost.Python does operator overloading. My suspicion is that Python >>> itself doesn't allow that operator to be overloaded, but I could be >>> wrong. >> >> >> >> the python methods are: >> >> __getitem__ __setitem___ and __delitem__ > > > What documentation did you read to find out about these? Methods like > this seem like a mystery to me, and I don't know where to look to read > more about them. Searches on Google seem to turn up more about Jython > than anything else. Maybe that's not such a bad start, though ... I am just looking at standard language references. In the python.org docs you can find the ones I am talking about at: http://www.python.org/doc/current/ref/sequence-types.html Basically there are just specific named methods that are used for operator based access in python. The *item methods are the ones to do the container type access similar to op[] in C++. > >> We probably only need to define the first two of them. There may also >> be some issues to take into account to support slicing, but we could >> ignore those in the first pass at the interface. > > > Are these issues in the documentation you're reading? A little bit of a mention of it but nothing conclusive. I think we just need to try it and see how it works. -Allen > -Patrick > > -- -- Allen Bierbaum al...@vr... -- PhD Candidate txtmsg - 515...@us... -- VR Juggler Team www.vrjuggler.org -- Virtual Reality Applications Center www.vrac.iastate.edu |