Re: [C++-sig] Boost.Python NumPy extension

2016-10-09 Thread Stefan Seefeld
Hi Alex,

On 09.10.2016 00:40, Alex Mohr wrote:
> Cool!  Sorry, I don't have the expertise to help with the boost.build
> aspect, but I did have some questions and comments regarding the feature.
>
> Does this add a dependency of boost.python on numpy?  We'd love to be
> able to continue use boost.python without a numpy dependency.  We did
> a nontrivial amount of work to remove this dependency in USD
> (openusd.org, https://github.com/PixarAnimationStudios/USD), a C++
> library that provides python bindings via boost.python, so adding it
> back would be a problem for us.
>
> Instead of depending on numpy, we made our array structures implement
> the python buffer protocol.  This lets clients that wish to use numpy
> do so easily, since numpy supports the buffer protocol, but it does
> not burden those that don't with the numpy dependency.  We did this
> manually of course but supporting the buffer protocol would be a cool
> feature for boost.python.

Short answer: The dependency on NumPy is only added to the extension
(compiled into a separate library); Boost.Python without that extension
remains exactly the same.

Somewhat longer answer: it all depends how Boost.Python is installed.
There is a configure flag to decide whether to build with or without
NumPy support. Building with NumPy support will yield two libraries:
libboost_python.so and libboost_numpy.so, so I expect downstream
packagers to wrap both into separate packages. (The new headers are
likewise kept separate for the same reason.)

Stefan


-- 

  ...ich hab' noch einen Koffer in Berlin...

___
Cplusplus-sig mailing list
[email protected]
https://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Boost.Python NumPy extension

2016-10-09 Thread Jim Bosch
On Sun, Oct 9, 2016 at 12:40 AM, Alex Mohr  wrote:

>
> Instead of depending on numpy, we made our array structures implement the
> python buffer protocol.  This lets clients that wish to use numpy do so
> easily, since numpy supports the buffer protocol, but it does not burden
> those that don't with the numpy dependency.  We did this manually of course
> but supporting the buffer protocol would be a cool feature for boost.python.


I think this is a very good idea - it wasn't available as an option back
when these NumPy bindings were written, but it's certainly the way I'd
recommend writing them now if we were starting over.  That would also
eliminate the need to call an initialization function in any Python modules
that use the NumPy bindings - failure to do that is by far the most common
problem people have in using the NumPy bindings.

That said, I think it'd be a fair amount of work to rewrite most of the
library's functionality with no NumPy dependency, and I think some parts of
it - like constructing numpy.dtype objects that correspond to C++ types -
would probably be impossible to do without access to the NumPy C API, so
we'd have to remove some functionality as well.


Jim
___
Cplusplus-sig mailing list
[email protected]
https://mail.python.org/mailman/listinfo/cplusplus-sig