Re: [C++-sig] Re: init function not found [was Re: Problem with
Thanks raul that was a silly mistake :( ... I should have noticed that ..
I didn't know that VC7.0 support had been dropped - at least, not deliberately!
Well that link that you sent in the some mail (on feb 03) (the status of the compilers) showed that there were couple of problems with the VC7.0 but nothing reported for 7.1.. I got the CVS version compiled on Linux .. :)
This looks very confusing to me, because the error message doesn't seem to match up to what you "did" in Python. Maybe the problem is very simple though. If you create a shared object called register_ptr.so you can import it with "from register_ptr import ....". Python then looks for a Python module or shared object that matches that name, and in the case of a shared object loads it and looks for a function called something like initregister_ptr. The BOOST_PYTHON_MODULE(register_ptr) macro gives you this function, correctly named.
____________
Problem solved !! Thanks! regards, Aashish ___________________________________
C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig
__________________________________________________________________________ Aashish Chaudhary Research Assistant Iowa State University E-Mail: aashish@iastate.edu Ames, Iowa Telephone: +1 515-441-1178
Hi, I need to pass a dictionary from python to C++ function which is defined as void setVariables(ValueMapPtr variables); where I have typedef ValueMapPtr as //a shared ptr of a value map typedef boost::shared_ptr< ValueMap > ValueMapPtr; // And typedef std::map< std::string, std::vector<double> > ValueMap; Is it possible?? Do I need to use register_ptr_to_python ? Any help is highly appreciated. Thanks, Aashish
"aashish" <aashish@vrac.iastate.edu> writes:
Hi,
I need to pass a dictionary from python to C++ function which is defined as
void setVariables(ValueMapPtr variables);
where I have typedef ValueMapPtr as
//a shared ptr of a value map typedef boost::shared_ptr< ValueMap > ValueMapPtr;
// And typedef std::map< std::string, std::vector<double> > ValueMap;
Is it possible??
Yes.
Do I need to use register_ptr_to_python ?
No; if it's truly a Python dictionary on the Python side, you need to build a custom rvalue from-python converter, per http://www.boost.org/libs/python/doc/v2/faq.html#question2 http://article.gmane.org/gmane.comp.python.c%2B%2B/2161 I wish it were easier; sorry! -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams <dave@boost-consulting.com> writes:
"aashish" <aashish@vrac.iastate.edu> writes:
Hi,
I need to pass a dictionary from python to C++ function which is defined as
void setVariables(ValueMapPtr variables);
where I have typedef ValueMapPtr as
//a shared ptr of a value map typedef boost::shared_ptr< ValueMap > ValueMapPtr;
// And typedef std::map< std::string, std::vector<double> > ValueMap;
Is it possible??
Yes.
Do I need to use register_ptr_to_python ?
No; if it's truly a Python dictionary on the Python side, you need to build a custom rvalue from-python converter, per
http://www.boost.org/libs/python/doc/v2/faq.html#question2 http://article.gmane.org/gmane.comp.python.c%2B%2B/2161
I wish it were easier; sorry!
There is an interesting trade off here, which I've thought about on a few occasions. If you want to share a container between Python and C++ code, I believe you have three choices: 1. Use a Python container and access it from C++ using the Python/C APIs like (e.g.) PyDict_GetItem 2. Use a C++ container and access it from Python using (e.g.) the indexing suite. 3. Use native containers on each side and convert from/to the different types at the interface. In terms of performance, which one is appropriate depends on the application, where most of the processing takes place and probably also on the size of the container. Option 1. means dealing with PyObjects from C++, instead of having the compiler know the static types of the elements. It introduces overheads on the C++ side, so isn't much good if the heavy processing is done here. Option 2. means the C++ code knows the static types of the elements, which gives you the fastest possible code for what you do in C++. It introduces overheads on the Python side, since every operation on the container requires a call through the Boost.Python code. For example, this wouldn't make much sense if you spend all the time filling the container from Python and then do one simple operation on it in C++. Option 3. means converting the whole container for each call (either from a C++ container to Python or vice versa). I guess it also introduces a problem if you want code on the non-native side to modify the container, since you'd then have to convert the container back and replace the original. As for which is the easiest to use, I would say probably option 2 would be, except that I haven't yet documented the new indexing suite properly, and I don't think the original suite has much std::map support. -- Raoul Gough. export LESS='-X'
Raoul Gough <RaoulGough@yahoo.co.uk> writes:
David Abrahams <dave@boost-consulting.com> writes:
"aashish" <aashish@vrac.iastate.edu> writes:
Hi,
I need to pass a dictionary from python to C++ function which is defined as
void setVariables(ValueMapPtr variables);
where I have typedef ValueMapPtr as
//a shared ptr of a value map typedef boost::shared_ptr< ValueMap > ValueMapPtr;
// And typedef std::map< std::string, std::vector<double> > ValueMap;
Is it possible??
Yes.
Do I need to use register_ptr_to_python ?
No; if it's truly a Python dictionary on the Python side, you need to build a custom rvalue from-python converter, per
http://www.boost.org/libs/python/doc/v2/faq.html#question2 http://article.gmane.org/gmane.comp.python.c%2B%2B/2161
I wish it were easier; sorry!
There is an interesting trade off here, which I've thought about on a few occasions. If you want to share a container between Python and C++ code, I believe you have three choices:
1. Use a Python container and access it from C++ using the Python/C APIs like (e.g.) PyDict_GetItem
2. Use a C++ container and access it from Python using (e.g.) the indexing suite.
3. Use native containers on each side and convert from/to the different types at the interface.
In terms of performance, which one is appropriate depends on the application, where most of the processing takes place and probably also on the size of the container.
Option 1. means dealing with PyObjects from C++, instead of having the compiler know the static types of the elements. It introduces overheads on the C++ side, so isn't much good if the heavy processing is done here.
Option 2. means the C++ code knows the static types of the elements, which gives you the fastest possible code for what you do in C++. It introduces overheads on the Python side, since every operation on the container requires a call through the Boost.Python code.
I'm not convinced these overheads you're referring to are real. Accessing a native Python dict or list from Python requires a call through Python's 'C' code that's much like Boost.Python's C++ code. There's probably one extra level of function indirection, but I doubt that counts for much in most cases.
For example, this wouldn't make much sense if you spend all the time filling the container from Python and then do one simple operation on it in C++.
Probably the reason, though, is the amount of effort you expend writing wrapping code in that case.
Option 3. means converting the whole container for each call (either from a C++ container to Python or vice versa). I guess it also introduces a problem if you want code on the non-native side to modify the container, since you'd then have to convert the container back and replace the original.
Right.
As for which is the easiest to use, I would say probably option 2 would be, except that I haven't yet documented the new indexing suite properly, and I don't think the original suite has much std::map support.
Mmm, I'm eagerly awaiting those docs. -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams <dave@boost-consulting.com> writes:
Raoul Gough <RaoulGough@yahoo.co.uk> writes: [snip]
Option 2. means the C++ code knows the static types of the elements, which gives you the fastest possible code for what you do in C++. It introduces overheads on the Python side, since every operation on the container requires a call through the Boost.Python code.
I'm not convinced these overheads you're referring to are real. Accessing a native Python dict or list from Python requires a call through Python's 'C' code that's much like Boost.Python's C++ code. There's probably one extra level of function indirection, but I doubt that counts for much in most cases.
Hmmm... I'd always assumed there was more to it than just an extra indirection, doesn't it have to search for a matching overload and do type compatibility checking as well? In particular, the purely Python solution doesn't care what kind of object you insert in a container, so it doesn't have to check types or look up a from-Python converter. I must admit I never really looked into in much detail, but I did see a substantial performance difference between filling a Python list from Python and filling a std::vector<int> from Python (about a factor of five). Is this more than you would expect? On the other hand, C++ code searching the vector or sorting it is about fifteen times faster than Python code doing the same on a Python list, so it really does depend on the mix of operations you're doing.
For example, this wouldn't make much sense if you spend all the time filling the container from Python and then do one simple operation on it in C++.
Probably the reason, though, is the amount of effort you expend writing wrapping code in that case.
Option 3. means converting the whole container for each call (either from a C++ container to Python or vice versa). I guess it also introduces a problem if you want code on the non-native side to modify the container, since you'd then have to convert the container back and replace the original.
Right.
As for which is the easiest to use, I would say probably option 2 would be, except that I haven't yet documented the new indexing suite properly, and I don't think the original suite has much std::map support.
Mmm, I'm eagerly awaiting those docs.
I've recently managed to get some paid employment, so I've had to put this work on the back burner for a while. I'm still hoping to get the docco ready by the end of next week (April 16) in time for the Python conference in Oxford. -- Raoul Gough. export LESS='-X'
Raoul Gough <RaoulGough@yahoo.co.uk> writes:
David Abrahams <dave@boost-consulting.com> writes:
Raoul Gough <RaoulGough@yahoo.co.uk> writes: [snip]
Option 2. means the C++ code knows the static types of the elements, which gives you the fastest possible code for what you do in C++. It introduces overheads on the Python side, since every operation on the container requires a call through the Boost.Python code.
I'm not convinced these overheads you're referring to are real. Accessing a native Python dict or list from Python requires a call through Python's 'C' code that's much like Boost.Python's C++ code. There's probably one extra level of function indirection, but I doubt that counts for much in most cases.
Hmmm... I'd always assumed there was more to it than just an extra indirection, doesn't it have to search for a matching overload
Yeah, but if there's only one overload that's free.
and do type compatibility checking as well?
Yeah, but Python has to look up a hash function depending on the key type.
In particular, the purely Python solution doesn't care what kind of object you insert in a container, so it doesn't have to check types or look up a from-Python converter.
from-Python lookups are usually cost-free.
I must admit I never really looked into in much detail, but I did see a substantial performance difference between filling a Python list from Python and filling a std::vector<int> from Python (about a factor of five). Is this more than you would expect?
OK, I can't argue with experimental data. You are correct, sir.
On the other hand, C++ code searching the vector or sorting it is about fifteen times faster than Python code doing the same on a Python list, so it really does depend on the mix of operations you're doing.
OK.
As for which is the easiest to use, I would say probably option 2 would be, except that I haven't yet documented the new indexing suite properly, and I don't think the original suite has much std::map support.
Mmm, I'm eagerly awaiting those docs.
I've recently managed to get some paid employment, so I've had to put this work on the back burner for a while. I'm still hoping to get the docco ready by the end of next week (April 16) in time for the Python conference in Oxford.
Great! Sorry I can't be there. -- Dave Abrahams Boost Consulting www.boost-consulting.com
Hi, I really appreciate e mails from two experts .. thaks a lot..... some questions ....
1. Use a Python container and access it from C++ using the Python/C APIs like (e.g.) PyDict_GetItem
2. Use a C++ container and access it from Python using (e.g.) the indexing suite.
I would prefer this option and I tried to use vector for starting. But is it possible same for the STL maps ?? Could you please inform me if there is some example ?? I couldn't find it ..... thanks, aashish
participants (5)
-
aashish -
Aashish Chaudhary -
aashish@iastate.edu -
David Abrahams -
Raoul Gough