[C++-sig] Cplusplus-sig Digest, Vol 13, Issue 11

Pim Schellart p.schellart at gmail.com
Tue Oct 13 12:18:32 CEST 2009


Dear Ravi,

thanks for the link. I'll be sure to try that.
Any chance this will be included (and documented) in boost python?
Numpy is needed for just about any scientific software package using
Python and it would be a real plus if boost Python had an easy to use
interface to C++ for it.

Kind regards,

Pim Schellart

2009/10/13  <cplusplus-sig-request at python.org>:
> Send Cplusplus-sig mailing list submissions to
>        cplusplus-sig at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.python.org/mailman/listinfo/cplusplus-sig
> or, via email, send a message with subject or body 'help' to
>        cplusplus-sig-request at python.org
>
> You can reach the person managing the list at
>        cplusplus-sig-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Cplusplus-sig digest..."
>
>
> Today's Topics:
>
>   1. Re: [Py++] How to wrap default arg as enum with   complicated
>      scope? (Roman Yakovenko)
>   2. Re: [python] Function objects in place of member functions (Ravi)
>   3. Re: Numpy ndarray as argument or return value using boost
>      python (Ravi)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 13 Oct 2009 00:39:04 +0200
> From: Roman Yakovenko <roman.yakovenko at gmail.com>
> To: "Development of Python/C++ integration" <cplusplus-sig at python.org>
> Subject: Re: [C++-sig] [Py++] How to wrap default arg as enum with
>        complicated scope?
> Message-ID:
>        <7465b6170910121539i4b16cc8am5ab1d38b42fc474 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Mon, Oct 12, 2009 at 10:51 PM, Christopher Bruns
> <cmbruns at stanford.edu> wrote:
>> Below is a simplified example of a tricky wrapping problem I have
>> encountered. ?The example remains somewhat complicated, but further
>> simplification results in a file that causes no trouble.
>> I get a compile error when I try to build the boost python code
>> generated by the following case:
>>
>> #### test_enum.h ####
>> struct System {
>> ? ?struct ProjectOptions {
>> ? ? ? ?enum Option {
>> ? ? ? ? ? ?All = 1
>> ? ? ? ?};
>> ? ? ? ?ProjectOptions(Option);
>> ? ?};
>> ? ?void project(ProjectOptions = ProjectOptions::All);
>> };
>> #### end test_enum.h ####
>>
>> The trouble comes from the default value ('ProjectOptions::All') for
>> the project() method. ?Notice also the constructor for ProjectOptions
>> from Options. ?That is required for reproducing the trouble here.
>>
>> The resulting boost.python code is as follows:
>> ...
>> #### test_wrap_enum2.cpp ####
>>
>> The symbol "All" in the line ", ( bp::arg("arg0")=All ) );" is out of
>> scope here. ?If I change the line from
>>
>> ?, ( bp::arg("arg0")=All ) ); // compile failure
>>
>> to
>>
>> ?, ( bp::arg("arg0")=System::ProjectOptions::All ) ); // works
>>
>> it compiles fine.
>>
>> Is there any way to instruct pyplusplus to generate the default
>> argument value for the project() method with the scope
>> "System::ProjectOptions::All"?
>
> Yes:
>
> mb = module_builder_t(...)
> project = mb.mem_fun( 'project' )
> project.arguments[0].default_value = "System::ProjectOptions::All"
>
>> Any enlightenment is much appreciated.
>
> Basically this is GCCXML limitations. The default argument could be
> full-blown C++ expression. GCCXML doesn't handles\dumps them. It do
> writes something for default arguments and Py++(pygccxml) try to
> decode what it is.
>
> May be the following link could help you:
> http://language-binding.net/pygccxml/upgrade_issues.html
> http://language-binding.net/pyplusplus/documentation/functions/functions.html
>
> Also try google, this problem was discussed on this, pygccxml and
> gccxml mailing lists.
>
> HTH
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 12 Oct 2009 21:04:46 -0400
> From: Ravi <lists_ravi at lavabit.com>
> To: "Development of Python/C++ integration" <cplusplus-sig at python.org>
> Subject: Re: [C++-sig] [python] Function objects in place of member
>        functions
> Message-ID: <200910122104.46505.lists_ravi at lavabit.com>
> Content-Type: Text/Plain;  charset="iso-8859-1"
>
> On Monday 12 October 2009 08:47:22 troy d. straszheim wrote:
>> >>    boost::function<int(X*, int)> bf0(fobj);
>> >
>> >
>> > Why do you need to use boost::function here? Shouldn't the type be
>> > deduced  automatically?
>> >
>>
>> Note that the .def() of the various boost::function objects work without
>> requiring the user to specialize get_signature, (since this modified
>> get_signature metafunction knows about boost::function objects).
>
> [snip]
>
>> I think interoperability with boost::function is a Good Thing, but in
>> the example above (and the previous), all it does is give def() a way to
>> tell what the signature of the function object is at compile time, and
>> it does so at a runtime cost.
>
> At least for my case, that extra virtual function call is a killer.
>
>> A specialization of get_signature works,
>> but strikes me as kinda ugly (it should at least be moved out of
>> 'detail' if it is a user customization point).  How about something like
>>
>>    class_<T>("T")
>>      .def("f1", f1, sig<void(T*, double)>)
>>      .def<void(T*, double)>("fi", f1)
>
> I'd rather have something along the lines of
>      .def< mpl::vector<void,T*,double> >("f1",f1)
> by using function_types to compose the currect function signature.
> Alternatively, one could have the sig<> template above be a def_visitor and
> take the appropriate template arguments without the need to modify class_::def
> at all.
>
>> >> I'm fairly new to the internals of boost.python, and only just now got
>> >> this working...  Do you see problems with this, specifically the
>> >> conversion of get_signature from function to metafunction?
>> >
>> >
>> > I don't see any problems with the conversion of get_signature to a
>> > metafunction. Do compile times get any longer?
>>
>> I haven't checked this yet.  I have other concerns re typechecking and
>> automatic conversions...
>
> Care to elaborate?
>
> Regards,
> Ravi
>
>
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 12 Oct 2009 21:11:44 -0400
> From: Ravi <lists_ravi at lavabit.com>
> To: "Development of Python/C++ integration" <cplusplus-sig at python.org>
> Subject: Re: [C++-sig] Numpy ndarray as argument or return value using
>        boost   python
> Message-ID: <200910122111.44171.lists_ravi at lavabit.com>
> Content-Type: Text/Plain;  charset="iso-8859-1"
>
> On Monday 12 October 2009 11:36:20 Pim Schellart wrote:
>> 1. Is boost python still maintained or should I switch to another tool.
>> 2. Is numpy supported, and if so,
>> 3. can someone give me a basic example of how to use it.
>
> Please see
>  http://mail.python.org/pipermail/cplusplus-sig/2008-October/013825.html
> which supports numpy arrays with and without copying, along with pass by
> reference and pass by value.
>
> Regards,
> Ravi
>
>
>
> ------------------------------
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
> End of Cplusplus-sig Digest, Vol 13, Issue 11
> *********************************************
>


More information about the Cplusplus-sig mailing list