mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 05:22:45 +00:00
Compare commits
37 Commits
travis
...
boost-1.64
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d3df3d3a7 | ||
|
|
df16e3e55e | ||
|
|
ae747521b0 | ||
|
|
3066c73c09 | ||
|
|
edd890bd2b | ||
|
|
352792c90a | ||
|
|
47faef65ee | ||
|
|
5e4b44e0af | ||
|
|
5121fc11f9 | ||
|
|
07b1489f3b | ||
|
|
471e6181b2 | ||
|
|
44ea0562b2 | ||
|
|
60fba03e99 | ||
|
|
398e7f02b8 | ||
|
|
1e315242ce | ||
|
|
77ee91d5c5 | ||
|
|
e3c9dd78aa | ||
|
|
e670de2795 | ||
|
|
367b793ac9 | ||
|
|
8c170d9193 | ||
|
|
bd7b8ecba5 | ||
|
|
0224f54ae0 | ||
|
|
d14b8cf411 | ||
|
|
4e0b96faa8 | ||
|
|
7178a70176 | ||
|
|
aaf9022770 | ||
|
|
36bbdde2fe | ||
|
|
1df6d84b80 | ||
|
|
e968329174 | ||
|
|
07c8cbe652 | ||
|
|
163e469bc4 | ||
|
|
ac39d2ed69 | ||
|
|
264f6ae4b9 | ||
|
|
84c96447e2 | ||
|
|
dc8d68d3fc | ||
|
|
88ea1f9626 | ||
|
|
731ba745ca |
@@ -39,6 +39,7 @@ arch = ARGUMENTS.get('arch', platform.machine())
|
||||
env_vars = {}
|
||||
if 'CXX' in os.environ: env_vars['CXX'] = os.environ['CXX']
|
||||
if 'CXXFLAGS' in os.environ: env_vars['CXXFLAGS'] = os.environ['CXXFLAGS'].split()
|
||||
env_vars['ENV'] = os.environ #{'PATH': os.environ['PATH'], 'TMP' : os.environ['TMP']}
|
||||
env = Environment(toolpath=['config/tools'],
|
||||
tools=['default', 'libs', 'tests', 'doc', 'sphinx4scons'],
|
||||
variables=vars,
|
||||
|
||||
@@ -69,13 +69,15 @@ install:
|
||||
# pip will build them from source using the MSVC compiler matching the
|
||||
# target Python version and architecture
|
||||
- easy_install scons
|
||||
- easy_install sphinx
|
||||
- pip install numpy
|
||||
#- "%CMD_IN_ENV% pip install -r dev-requirements.txt"
|
||||
|
||||
build_script:
|
||||
# Build the compiled extension
|
||||
#- "%CMD_IN_ENV% python setup.py build"
|
||||
- scons config arch=%ARCH% --boost-include=%BOOST_PREFIX%
|
||||
- scons arch=%ARCH%
|
||||
- scons arch=%ARCH% --verbose
|
||||
|
||||
test_script:
|
||||
# Run the project tests
|
||||
|
||||
125
build/Jamfile
125
build/Jamfile
@@ -6,6 +6,7 @@ import os ;
|
||||
import indirect ;
|
||||
import modules ;
|
||||
import feature ;
|
||||
import property ;
|
||||
|
||||
import python ;
|
||||
|
||||
@@ -30,52 +31,26 @@ else
|
||||
;
|
||||
}
|
||||
|
||||
rule find-py3-version
|
||||
{
|
||||
local versions = [ feature.values python ] ;
|
||||
local py3ver ;
|
||||
for local v in $(versions)
|
||||
{
|
||||
if $(v) >= 3.0
|
||||
{
|
||||
py3ver = $(v) ;
|
||||
}
|
||||
}
|
||||
return $(py3ver) ;
|
||||
}
|
||||
|
||||
py3-version = [ find-py3-version ] ;
|
||||
py2-version = [ py-version 2 ] ;
|
||||
py3-version = [ py-version 3 ] ;
|
||||
|
||||
project boost/python
|
||||
: source-location ../src
|
||||
: requirements
|
||||
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
|
||||
<tag>@$(__name__).tag
|
||||
;
|
||||
|
||||
rule tag ( name : type ? : property-set )
|
||||
{
|
||||
local result = $(name) ;
|
||||
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
|
||||
{
|
||||
if $(name) = boost_python && $(PYTHON_ID)
|
||||
{
|
||||
result = $(result)-$(PYTHON_ID) ;
|
||||
}
|
||||
}
|
||||
|
||||
# forward to the boost tagging rule
|
||||
return [ indirect.call $(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
|
||||
$(result) : $(type) : $(property-set) ] ;
|
||||
}
|
||||
|
||||
rule cond ( test ? : yes * : no * ) { if $(test) { return $(yes) ; } else { return $(no) ; } }
|
||||
rule unless ( test ? : yes * : no * ) { if ! $(test) { return $(yes) ; } else { return $(no) ; } }
|
||||
local rule eq ( a : b ) { if $(a) = $(b) { return 1 ; } }
|
||||
|
||||
rule lib_boost_python ( is-py3 ? )
|
||||
lib_boost_python(2) = boost_python ;
|
||||
lib_boost_python(3) = boost_python3 ;
|
||||
|
||||
lib_boost_python($(py2-version)) = $(lib_boost_python(2)) ;
|
||||
lib_boost_python($(py3-version)) = $(lib_boost_python(3)) ;
|
||||
|
||||
rule lib_boost_python ( version )
|
||||
{
|
||||
|
||||
lib [ cond $(is-py3) : boost_python3 : boost_python ]
|
||||
lib $(lib_boost_python($(version)))
|
||||
: # sources
|
||||
numeric.cpp
|
||||
list.cpp
|
||||
@@ -131,21 +106,83 @@ rule lib_boost_python ( is-py3 ? )
|
||||
<dependency>config-warning
|
||||
|
||||
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
|
||||
[ cond $(is-py3) : <python>$(py3-version) ]
|
||||
<python>$(version)
|
||||
|
||||
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
|
||||
<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).python-tag
|
||||
|
||||
<conditional>@python.require-py
|
||||
|
||||
: # default build
|
||||
<link>shared
|
||||
: # usage requirements
|
||||
<link>static:<define>BOOST_PYTHON_STATIC_LIB
|
||||
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
lib_boost_python ;
|
||||
boost-install boost_python ;
|
||||
lib_boost_numpy(2) = boost_numpy ;
|
||||
lib_boost_numpy(3) = boost_numpy3 ;
|
||||
|
||||
if $(py3-version)
|
||||
lib_boost_numpy($(py2-version)) = $(lib_boost_numpy(2)) ;
|
||||
lib_boost_numpy($(py3-version)) = $(lib_boost_numpy(3)) ;
|
||||
|
||||
rule lib_boost_numpy ( version )
|
||||
{
|
||||
lib_boost_python yes ;
|
||||
boost-install boost_python3 ;
|
||||
numpy-include = [ python.numpy-include ] ;
|
||||
lib $(lib_boost_numpy($(version)))
|
||||
: # sources
|
||||
numpy/dtype.cpp
|
||||
numpy/matrix.cpp
|
||||
numpy/ndarray.cpp
|
||||
numpy/numpy.cpp
|
||||
numpy/scalars.cpp
|
||||
numpy/ufunc.cpp
|
||||
: # requirements
|
||||
<link>static:<define>BOOST_NUMPY_STATIC_LIB
|
||||
<define>BOOST_NUMPY_SOURCE
|
||||
[ cond [ python.numpy ] : <library>/python//python_for_extensions ]
|
||||
[ unless [ python.numpy ] : <build>no ]
|
||||
<include>$(numpy-include)
|
||||
<library>$(lib_boost_python($(version)))
|
||||
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
|
||||
<python>$(version)
|
||||
|
||||
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
|
||||
<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).python-tag
|
||||
|
||||
<conditional>@python.require-py
|
||||
|
||||
: # default build
|
||||
<link>shared
|
||||
: # usage requirements
|
||||
<link>static:<define>BOOST_NUMPY_STATIC_LIB
|
||||
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
|
||||
;
|
||||
}
|
||||
|
||||
libraries = ;
|
||||
|
||||
for local N in 2 3
|
||||
{
|
||||
if $(py$(N)-version)
|
||||
{
|
||||
lib_boost_python $(py$(N)-version) ;
|
||||
libraries += $(lib_boost_python($(py$(N)-version))) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
alias $(lib_boost_python($(N))) ;
|
||||
}
|
||||
if $(py$(N)-version) && [ python.numpy ]
|
||||
{
|
||||
lib_boost_numpy $(py$(N)-version) ;
|
||||
libraries += $(lib_boost_numpy($(py$(N)-version))) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
alias $(lib_boost_numpy($(N))) ;
|
||||
}
|
||||
}
|
||||
|
||||
boost-install $(libraries) ;
|
||||
|
||||
21
doc/Jamfile
21
doc/Jamfile
@@ -4,10 +4,14 @@
|
||||
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import boostbook ;
|
||||
import quickbook ;
|
||||
import docutils ;
|
||||
import os ;
|
||||
|
||||
path-constant here : . ;
|
||||
path-constant images : html/images ;
|
||||
|
||||
|
||||
project python/doc
|
||||
: requirements
|
||||
-<xsl:param>boost.defaults=Boost
|
||||
@@ -17,9 +21,16 @@ project python/doc
|
||||
<format>html:<xsl:param>chunk.section.depth=1
|
||||
;
|
||||
|
||||
import boostbook ;
|
||||
import quickbook ;
|
||||
import docutils ;
|
||||
make numpy : numpy/index.rst : @sphinx-build ;
|
||||
|
||||
if [ os.name ] = NT
|
||||
{
|
||||
actions sphinx-build { chdir "$(>:D)" && make clean && make html}
|
||||
}
|
||||
else
|
||||
{
|
||||
actions sphinx-build { make -C "$(>:D)" clean html}
|
||||
}
|
||||
|
||||
boostbook python : python.qbk
|
||||
: <format>html:<name>$(here)/html
|
||||
@@ -51,5 +62,5 @@ html article : article.rst
|
||||
###############################################################################
|
||||
alias boostdoc ;
|
||||
explicit boostdoc ;
|
||||
alias boostrelease : python tutorial reference article ;
|
||||
alias boostrelease : python tutorial reference numpy article ;
|
||||
explicit boostrelease ;
|
||||
|
||||
@@ -6,6 +6,7 @@ SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
HTMLDIR = ../html/numpy
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
@@ -39,9 +40,9 @@ clean:
|
||||
-rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(HTMLDIR)
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
@echo "Build finished. The HTML pages are in $(HTMLDIR)."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
}
|
||||
|
||||
.admonition-title { font-weight: bold;}
|
||||
#table-of-contents
|
||||
.toctree-wrapper
|
||||
{
|
||||
border: 1px solid #dcdcdc;
|
||||
padding: 1em;
|
||||
margin: 0 2em;
|
||||
}
|
||||
#table-of-contents .caption,
|
||||
#table-of-contents .topic-title { font-weight: bold;}
|
||||
.toctree-wrapper .caption,
|
||||
.toctree-wrapper .topic-title { font-weight: bold;}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ Welcome to the documentation of the Boost.Python NumPy extension!
|
||||
=================================================================
|
||||
|
||||
.. toctree::
|
||||
:caption: Table of Contents
|
||||
:maxdepth: 2
|
||||
|
||||
Tutorial <tutorial/index>
|
||||
|
||||
@@ -6,6 +6,7 @@ if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=_build
|
||||
set HTMLDIR=../html/numpy
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
@@ -41,10 +42,10 @@ if "%1" == "clean" (
|
||||
)
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %HTMLDIR%
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
echo.Build finished. The HTML pages are in %HTMLDIR%.
|
||||
goto end
|
||||
)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ Boost.Python NumPy extension Reference
|
||||
======================================
|
||||
|
||||
.. toctree::
|
||||
:caption: Table of Contents
|
||||
:maxdepth: 2
|
||||
|
||||
dtype
|
||||
|
||||
@@ -2,7 +2,6 @@ Boost.Python NumPy extension Tutorial
|
||||
=====================================
|
||||
|
||||
.. toctree::
|
||||
:caption: Table of Contents
|
||||
:maxdepth: 2
|
||||
|
||||
simple
|
||||
|
||||
@@ -38,7 +38,7 @@ The `indexing_suite` class is the base class for the management of C++ container
|
||||
[[__iter__(self)]
|
||||
[This method is called when an iterator is required for a container. This method should return a new iterator object that can iterate over all the objects in the container. For mappings, it should iterate over the keys of the container, and should also be made available as the method iterkeys().
|
||||
|
||||
Iterator objects also need to implement this method; they are required to return themselves. For more information on iterator objects, see [@http://www.python.org/doc/current/lib/typeiter.html Iterator Types] in the [@http://www.python.org/doc/current/lib/lib.html Python Library Reference].]]
|
||||
Iterator objects also need to implement this method; they are required to return themselves. For more information on iterator objects, see [@https://docs.python.org/3/library/stdtypes.html#iterator-types Iterator Types] in the [@https://docs.python.org/3/library/index.html Python Library Reference].]]
|
||||
|
||||
[[__contains__(self, item)]
|
||||
[Called to implement membership test operators. Should return true if item is in self, false otherwise. For mapping objects, this should consider the keys of the mapping rather than the values or the key-item pairs.]]
|
||||
|
||||
@@ -4,7 +4,7 @@ Pickle is a Python module for object serialization, also known as persistence, m
|
||||
|
||||
It is often necessary to save and restore the contents of an object to a file. One approach to this problem is to write a pair of functions that read and write data from a file in a special format. A powerful alternative approach is to use Python's pickle module. Exploiting Python's ability for introspection, the pickle module recursively converts nearly arbitrary Python objects into a stream of bytes that can be written to a file.
|
||||
|
||||
The Boost Python Library supports the pickle module through the interface as described in detail in the [@http://www.python.org/doc/current/lib/module-pickle.html Python Library Reference for pickle]. This interface involves the special methods `__getinitargs__`, `__getstate__` and `__setstate__` as described in the following. Note that `Boost.Python` is also fully compatible with Python's cPickle module.
|
||||
The Boost Python Library supports the pickle module through the interface as described in detail in the [@https://docs.python.org/2/library/pickle.html Python Library Reference for pickle]. This interface involves the special methods `__getinitargs__`, `__getstate__` and `__setstate__` as described in the following. Note that `Boost.Python` is also fully compatible with Python's cPickle module.
|
||||
[endsect]
|
||||
[section The Pickle Interface]
|
||||
At the user level, the Boost.Python pickle interface involves three special methods:
|
||||
|
||||
@@ -1,43 +1,35 @@
|
||||
# Copyright David Abrahams 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
# Copyright Stefan Seefeld 2016.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Specify the path to the Boost project. If you move this project,
|
||||
# adjust this path to refer to the Boost root directory.
|
||||
use-project boost
|
||||
: ../../.. ;
|
||||
import python ;
|
||||
|
||||
# Set up the project-wide requirements that everything uses the
|
||||
# boost_python library from the project whose global ID is
|
||||
# /boost/python.
|
||||
project
|
||||
: requirements <library>/boost/python//boost_python
|
||||
<implicit-dependency>/boost//headers
|
||||
: usage-requirements <implicit-dependency>/boost//headers
|
||||
;
|
||||
|
||||
# Declare the three extension modules. You can specify multiple
|
||||
# source files after the colon separated by spaces.
|
||||
python-extension getting_started1 : getting_started1.cpp ;
|
||||
python-extension getting_started2 : getting_started2.cpp ;
|
||||
python-extension std_pair_ext : std_pair.cpp ;
|
||||
|
||||
# A little "rule" (function) to clean up the syntax of declaring tests
|
||||
# of these extension modules.
|
||||
local rule run-test ( test-name : sources + )
|
||||
if ! [ python.configured ]
|
||||
{
|
||||
import testing ;
|
||||
testing.make-test run-pyd : $(sources) : : $(test-name) ;
|
||||
ECHO "warning: no Python configured in user-config.jam" ;
|
||||
ECHO "warning: will use default configuration" ;
|
||||
using python ;
|
||||
}
|
||||
|
||||
# Declare test targets
|
||||
run-test test1 : getting_started1 test_getting_started1.py ;
|
||||
run-test test2 : getting_started2 test_getting_started2.py ;
|
||||
run-test test3 : std_pair_ext test_std_pair.py ;
|
||||
# Adjust the following if Boost.Python isn't installed in a default location
|
||||
lib boost_python ;
|
||||
|
||||
# A target that runs all the tests
|
||||
alias test : test1 test2 test3 ;
|
||||
project
|
||||
: requirements
|
||||
# <include>/path/to/boost/python
|
||||
<library>boost_python
|
||||
;
|
||||
|
||||
# Only run tests when explicitly requested
|
||||
explicit test test1 test2 test3 ;
|
||||
rule run-test ( test-name : sources + )
|
||||
{
|
||||
import testing ;
|
||||
testing.make-test run-pyd : $(sources) : : $(test-name) ;
|
||||
}
|
||||
|
||||
build-project quickstart ;
|
||||
build-project tutorial ;
|
||||
if [ python.numpy ]
|
||||
{
|
||||
build-project numpy ;
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
To get started with the Boost Python Library, use the examples
|
||||
getting_started1.cpp and getting_started2.cpp. Invoking
|
||||
|
||||
bjam --toolset=your-toolset test
|
||||
|
||||
in this directory will build and run the examples. See
|
||||
http://www.boost.org/more/getting_started.html for details about the
|
||||
--toolset= option.
|
||||
|
||||
If you move this example from its place in the Boost development tree
|
||||
you'll need to edit the two lines indicated in Jamroot and
|
||||
boost-build.jam.
|
||||
11
example/README.md
Normal file
11
example/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||

|
||||
|
||||
# Examples
|
||||
|
||||
This directory contains various examples using Boost.Python.
|
||||
You may compile these using the `bjam` command either in this directory
|
||||
or in any of the subdirectories.
|
||||
You may need to adjust the paths in the Jamroot file if Boost.Python
|
||||
is not installed in a default location.
|
||||
See http://boostorg.github.io/python/doc/html/building/no_install_quickstart.html
|
||||
for details.
|
||||
@@ -1,7 +0,0 @@
|
||||
# Copyright David Abrahams 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Edit this path to point at the tools/build/src subdirectory of your
|
||||
# Boost installation. Absolute paths work, too.
|
||||
boost-build ../../../tools/build/src ;
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright Ralf W. Grosse-Kunstleve 2002-2004. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace { // Avoid cluttering the global namespace.
|
||||
|
||||
// A couple of simple C++ functions that we want to expose to Python.
|
||||
std::string greet() { return "hello, world"; }
|
||||
int square(int number) { return number * number; }
|
||||
}
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
// Python requires an exported function called init<module-name> in every
|
||||
// extension module. This is where we build the module contents.
|
||||
BOOST_PYTHON_MODULE(getting_started1)
|
||||
{
|
||||
// Add regular functions to the module.
|
||||
python::def("greet", greet);
|
||||
python::def("square", square);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright Ralf W. Grosse-Kunstleve 2002-2004. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace { // Avoid cluttering the global namespace.
|
||||
|
||||
// A friendly class.
|
||||
class hello
|
||||
{
|
||||
public:
|
||||
hello(const std::string& country) { this->country = country; }
|
||||
std::string greet() const { return "Hello from " + country; }
|
||||
private:
|
||||
std::string country;
|
||||
};
|
||||
|
||||
// A function taking a hello object as an argument.
|
||||
std::string invite(const hello& w) {
|
||||
return w.greet() + "! Please come soon!";
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(getting_started2)
|
||||
{
|
||||
using namespace boost::python;
|
||||
class_<hello>("hello", init<std::string>())
|
||||
// Add a regular member function.
|
||||
.def("greet", &hello::greet)
|
||||
// Add invite() as a member of hello!
|
||||
.def("invite", invite)
|
||||
;
|
||||
|
||||
// Also add invite() as a regular function to the module.
|
||||
def("invite", invite);
|
||||
}
|
||||
29
example/numpy/Jamfile
Normal file
29
example/numpy/Jamfile
Normal file
@@ -0,0 +1,29 @@
|
||||
# Copyright Stefan Seefeld 2016.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import python ;
|
||||
|
||||
# Adjust the following if Boost.Python isn't installed in a default location
|
||||
lib boost_numpy
|
||||
:
|
||||
: <search>/usr/local/Boost/lib
|
||||
<include>/usr/local/Boost/include
|
||||
;
|
||||
|
||||
project numpy
|
||||
: requirements
|
||||
<include>/usr/local/Boost/include
|
||||
<library>boost_numpy
|
||||
<location>.
|
||||
;
|
||||
|
||||
exe simple : simple.cpp boost_numpy /python//python ;
|
||||
exe dtype : dtype.cpp boost_numpy /python//python ;
|
||||
exe ndarray : ndarray.cpp /python//python ;
|
||||
exe fromdata : fromdata.cpp /python//python ;
|
||||
exe ufunc : ufunc.cpp /python//python ;
|
||||
exe wrap : wrap.cpp /python//python ;
|
||||
|
||||
python-extension gaussian : gaussian.cpp ;
|
||||
@@ -12,11 +12,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <boost/numpy.hpp>
|
||||
#include <boost/python/numpy.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace p = boost::python;
|
||||
namespace np = boost::numpy;
|
||||
namespace np = boost::python::numpy;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
* manipulate data in either Python or C++ and have the changes reflected in both.
|
||||
*/
|
||||
|
||||
#include <boost/numpy.hpp>
|
||||
#include <boost/python/numpy.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace p = boost::python;
|
||||
namespace np = boost::numpy;
|
||||
namespace np = boost::python::numpy;
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/numpy.hpp>
|
||||
#include <boost/python/numpy.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
@@ -14,7 +14,7 @@ const double M_PI = boost::math::constants::pi<double>();
|
||||
#endif
|
||||
|
||||
namespace bp = boost::python;
|
||||
namespace bn = boost::numpy;
|
||||
namespace bn = boost::python::numpy;
|
||||
|
||||
/**
|
||||
* A 2x2 matrix class, purely for demonstration purposes.
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
* non-unit strides.
|
||||
*/
|
||||
|
||||
#include <boost/numpy.hpp>
|
||||
#include <boost/python/numpy.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace p = boost::python;
|
||||
namespace np = boost::numpy;
|
||||
namespace np = boost::python::numpy;
|
||||
|
||||
#if _MSC_VER
|
||||
using boost::uint8_t;
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/numpy.hpp>
|
||||
#include <boost/python/numpy.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace p = boost::python;
|
||||
namespace np = boost::numpy;
|
||||
namespace np = boost::python::numpy;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
* None of the methods like np::add, np::multiply etc are supported as yet
|
||||
*/
|
||||
|
||||
#include <boost/numpy.hpp>
|
||||
#include <boost/python/numpy.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace p = boost::python;
|
||||
namespace np = boost::numpy;
|
||||
namespace np = boost::python::numpy;
|
||||
|
||||
|
||||
// Create the structs necessary to implement the ufuncs
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
* Python. Again, see the Gaussian demo for an example.
|
||||
*/
|
||||
|
||||
#include <boost/numpy.hpp>
|
||||
#include <boost/python/numpy.hpp>
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace p = boost::python;
|
||||
namespace np = boost::numpy;
|
||||
namespace np = boost::python::numpy;
|
||||
|
||||
// This is roughly the most efficient way to write a C/C++ function that operates
|
||||
// on a 2-d NumPy array - operate directly on the array by incrementing a pointer
|
||||
|
||||
Binary file not shown.
@@ -1,23 +1,15 @@
|
||||
# Copyright David Abrahams 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
# Copyright Stefan Seefeld 2016.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Specify the path to the Boost project. If you move this project,
|
||||
# adjust the path to refer to the Boost root directory.
|
||||
use-project boost
|
||||
: ../../../.. ;
|
||||
|
||||
# Set up the project-wide requirements that everything uses the
|
||||
# boost_python library defined in the project whose global ID is
|
||||
# /boost/python.
|
||||
project boost-python-quickstart
|
||||
: requirements <library>/boost/python//boost_python
|
||||
<implicit-dependency>/boost//headers
|
||||
: usage-requirements <implicit-dependency>/boost//headers
|
||||
;
|
||||
|
||||
# Make the definition of the python-extension rule available
|
||||
import python ;
|
||||
import testing ;
|
||||
|
||||
project quickstart
|
||||
: requirements
|
||||
<location>.
|
||||
;
|
||||
|
||||
# Declare a Python extension called hello.
|
||||
python-extension extending : extending.cpp ;
|
||||
@@ -25,8 +17,6 @@ python-extension extending : extending.cpp ;
|
||||
# Declare an executable called embedding that embeds Python
|
||||
exe embedding : embedding.cpp /python//python ;
|
||||
|
||||
import testing ;
|
||||
|
||||
# Declare a test of the extension module
|
||||
testing.make-test run-pyd : extending test_extending.py : : test_ext ;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
# Copyright David Abrahams 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Edit this path to point at the tools/build/src subdirectory of your
|
||||
# Boost installation. Absolute paths work, too.
|
||||
boost-build ../../../../tools/build/src ;
|
||||
@@ -1,6 +1,7 @@
|
||||
#! /usr/bin/env python
|
||||
# Copyright Stefan Seefeld 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
print 'Hello World !'
|
||||
print('Hello World !')
|
||||
number = 42
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#! /usr/bin/env python
|
||||
# Copyright Ralf W. Grosse-Kunstleve 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
// Copyright Ralf W. Grosse-Kunstleve 2002-2004. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
#include <boost/python/tuple.hpp>
|
||||
#include <boost/python/to_python_converter.hpp>
|
||||
|
||||
namespace { // Avoid cluttering the global namespace.
|
||||
|
||||
// Converts a std::pair instance to a Python tuple.
|
||||
template <typename T1, typename T2>
|
||||
struct std_pair_to_tuple
|
||||
{
|
||||
static PyObject* convert(std::pair<T1, T2> const& p)
|
||||
{
|
||||
return boost::python::incref(
|
||||
boost::python::make_tuple(p.first, p.second).ptr());
|
||||
}
|
||||
static PyTypeObject const *get_pytype () {return &PyTuple_Type; }
|
||||
};
|
||||
|
||||
// Helper for convenience.
|
||||
template <typename T1, typename T2>
|
||||
struct std_pair_to_python_converter
|
||||
{
|
||||
std_pair_to_python_converter()
|
||||
{
|
||||
boost::python::to_python_converter<
|
||||
std::pair<T1, T2>,
|
||||
std_pair_to_tuple<T1, T2>,
|
||||
true //std_pair_to_tuple has get_pytype
|
||||
>();
|
||||
}
|
||||
};
|
||||
|
||||
// Example function returning a std::pair.
|
||||
std::pair<int, int>
|
||||
foo() { return std::pair<int, int>(3, 5); }
|
||||
|
||||
} // namespace anonymous
|
||||
|
||||
BOOST_PYTHON_MODULE(std_pair_ext)
|
||||
{
|
||||
using namespace boost::python;
|
||||
std_pair_to_python_converter<int, int>();
|
||||
def("foo", foo);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
# Copyright Ralf W. Grosse-Kunstleve 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
r'''>>> import getting_started1
|
||||
>>> print getting_started1.greet()
|
||||
hello, world
|
||||
>>> number = 11
|
||||
>>> print number, '*', number, '=', getting_started1.square(number)
|
||||
11 * 11 = 121
|
||||
'''
|
||||
|
||||
def run(args = None):
|
||||
if args is not None:
|
||||
import sys
|
||||
sys.argv = args
|
||||
import doctest, test_getting_started1
|
||||
return doctest.testmod(test_getting_started1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
sys.exit(run()[0])
|
||||
@@ -1,34 +0,0 @@
|
||||
# Copyright Ralf W. Grosse-Kunstleve 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
r'''>>> from getting_started2 import *
|
||||
>>> hi = hello('California')
|
||||
>>> hi.greet()
|
||||
'Hello from California'
|
||||
>>> invite(hi)
|
||||
'Hello from California! Please come soon!'
|
||||
>>> hi.invite()
|
||||
'Hello from California! Please come soon!'
|
||||
|
||||
>>> class wordy(hello):
|
||||
... def greet(self):
|
||||
... return hello.greet(self) + ', where the weather is fine'
|
||||
...
|
||||
>>> hi2 = wordy('Florida')
|
||||
>>> hi2.greet()
|
||||
'Hello from Florida, where the weather is fine'
|
||||
>>> invite(hi2)
|
||||
'Hello from Florida! Please come soon!'
|
||||
'''
|
||||
|
||||
def run(args = None):
|
||||
if args is not None:
|
||||
import sys
|
||||
sys.argv = args
|
||||
import doctest, test_getting_started2
|
||||
return doctest.testmod(test_getting_started2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
sys.exit(run()[0])
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# Copyright Ralf W. Grosse-Kunstleve 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
import std_pair_ext
|
||||
assert std_pair_ext.foo() == (3, 5)
|
||||
print "OK"
|
||||
19
example/tutorial/Jamfile
Normal file
19
example/tutorial/Jamfile
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright Stefan Seefeld 2016.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import python ;
|
||||
|
||||
project tutorial
|
||||
: requirements
|
||||
<location>.
|
||||
;
|
||||
|
||||
python-extension hello_ext : hello.cpp ;
|
||||
|
||||
run-test hello : hello_ext hello.py ;
|
||||
|
||||
alias test : hello ;
|
||||
explicit test ;
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
# Copyright David Abrahams 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import python ;
|
||||
|
||||
if ! [ python.configured ]
|
||||
{
|
||||
ECHO "notice: no Python configured in user-config.jam" ;
|
||||
ECHO "notice: will use default configuration" ;
|
||||
using python ;
|
||||
}
|
||||
|
||||
# Specify the path to the Boost project. If you move this project,
|
||||
# adjust this path to refer to the Boost root directory.
|
||||
use-project boost
|
||||
: ../../../.. ;
|
||||
|
||||
# Set up the project-wide requirements that everything uses the
|
||||
# boost_python library from the project whose global ID is
|
||||
# /boost/python.
|
||||
project
|
||||
: requirements <library>/boost/python//boost_python
|
||||
<implicit-dependency>/boost//headers
|
||||
: usage-requirements <implicit-dependency>/boost//headers
|
||||
;
|
||||
|
||||
# Declare the three extension modules. You can specify multiple
|
||||
# source files after the colon separated by spaces.
|
||||
python-extension hello_ext : hello.cpp ;
|
||||
|
||||
# Put the extension and Boost.Python DLL in the current directory, so
|
||||
# that running script by hand works.
|
||||
install convenient_copy
|
||||
: hello_ext
|
||||
: <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION
|
||||
<location>.
|
||||
;
|
||||
|
||||
# A little "rule" (function) to clean up the syntax of declaring tests
|
||||
# of these extension modules.
|
||||
local rule run-test ( test-name : sources + )
|
||||
{
|
||||
import testing ;
|
||||
testing.make-test run-pyd : $(sources) : : $(test-name) ;
|
||||
}
|
||||
|
||||
# Declare test targets
|
||||
run-test hello : hello_ext hello.py ;
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#! /usr/bin/env python
|
||||
# Copyright Joel de Guzman 2002-2007. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
# or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
# Hello World Example from the tutorial
|
||||
|
||||
import hello_ext
|
||||
print hello_ext.greet()
|
||||
print(hello_ext.greet())
|
||||
|
||||
@@ -9,8 +9,11 @@
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
BOOST_PYTHON_DECL PyObject* checked_downcast_impl(PyObject*, PyTypeObject*);
|
||||
|
||||
BOOST_PYTHON_DECL inline
|
||||
PyObject* checked_downcast_impl(PyObject *obj, PyTypeObject *type)
|
||||
{
|
||||
return (PyType_IsSubtype(Py_TYPE(obj), type) ? obj : NULL);
|
||||
}
|
||||
// Used as a base class for specializations which need to provide
|
||||
// Python type checking capability.
|
||||
template <class Object, PyTypeObject* pytype>
|
||||
|
||||
@@ -64,31 +64,18 @@
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_PYTHON_DYNAMIC_LIB)
|
||||
|
||||
# if !defined(_WIN32) && !defined(__CYGWIN__) \
|
||||
&& !defined(BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY) \
|
||||
&& BOOST_WORKAROUND(__GNUC__, >= 3) && (__GNUC_MINOR__ >=5 || __GNUC__ > 3)
|
||||
# define BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY 1
|
||||
# endif
|
||||
|
||||
# if BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY
|
||||
# if defined(BOOST_SYMBOL_EXPORT)
|
||||
# if defined(BOOST_PYTHON_SOURCE)
|
||||
# define BOOST_PYTHON_DECL __attribute__ ((__visibility__("default")))
|
||||
# define BOOST_PYTHON_DECL BOOST_SYMBOL_EXPORT
|
||||
# define BOOST_PYTHON_DECL_FORWARD BOOST_SYMBOL_FORWARD_EXPORT
|
||||
# define BOOST_PYTHON_DECL_EXCEPTION BOOST_EXCEPTION_EXPORT
|
||||
# define BOOST_PYTHON_BUILD_DLL
|
||||
# else
|
||||
# define BOOST_PYTHON_DECL
|
||||
# endif
|
||||
# define BOOST_PYTHON_DECL_FORWARD
|
||||
# define BOOST_PYTHON_DECL_EXCEPTION __attribute__ ((__visibility__("default")))
|
||||
# elif (defined(_WIN32) || defined(__CYGWIN__))
|
||||
# if defined(BOOST_PYTHON_SOURCE)
|
||||
# define BOOST_PYTHON_DECL __declspec(dllexport)
|
||||
# define BOOST_PYTHON_BUILD_DLL
|
||||
# else
|
||||
# define BOOST_PYTHON_DECL __declspec(dllimport)
|
||||
# define BOOST_PYTHON_DECL BOOST_SYMBOL_IMPORT
|
||||
# define BOOST_PYTHON_DECL_FORWARD BOOST_SYMBOL_FORWARD_IMPORT
|
||||
# define BOOST_PYTHON_DECL_EXCEPTION BOOST_EXCEPTION_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_DECL
|
||||
@@ -96,11 +83,11 @@
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_DECL_FORWARD
|
||||
# define BOOST_PYTHON_DECL_FORWARD BOOST_PYTHON_DECL
|
||||
# define BOOST_PYTHON_DECL_FORWARD
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_PYTHON_DECL_EXCEPTION
|
||||
# define BOOST_PYTHON_DECL_EXCEPTION BOOST_PYTHON_DECL
|
||||
# define BOOST_PYTHON_DECL_EXCEPTION
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct BOOST_PYTHON_DECL_FORWARD exception_handler;
|
||||
struct exception_handler;
|
||||
|
||||
typedef function2<bool, exception_handler const&, function0<void> const&> handler_function;
|
||||
|
||||
|
||||
2
include/boost/python/detail/wrapper_base.hpp
Executable file → Normal file
2
include/boost/python/detail/wrapper_base.hpp
Executable file → Normal file
@@ -14,7 +14,7 @@ class override;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
class BOOST_PYTHON_DECL_FORWARD wrapper_base;
|
||||
class wrapper_base;
|
||||
|
||||
namespace wrapper_base_ // ADL disabler
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct BOOST_PYTHON_DECL_EXCEPTION error_already_set
|
||||
struct BOOST_PYTHON_DECL error_already_set
|
||||
{
|
||||
virtual ~error_already_set();
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <boost/python/numpy/matrix.hpp>
|
||||
#include <boost/python/numpy/ufunc.hpp>
|
||||
#include <boost/python/numpy/invoke_matching.hpp>
|
||||
#include <boost/python/numpy/config.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace numpy {
|
||||
|
||||
@@ -26,7 +27,7 @@ namespace boost { namespace python { namespace numpy {
|
||||
* and "import_ufunc()", and then calls
|
||||
* dtype::register_scalar_converters().
|
||||
*/
|
||||
void initialize(bool register_scalar_converters=true);
|
||||
BOOST_NUMPY_DECL void initialize(bool register_scalar_converters=true);
|
||||
|
||||
}}} // namespace boost::python::numpy
|
||||
|
||||
|
||||
78
include/boost/python/numpy/config.hpp
Normal file
78
include/boost/python/numpy/config.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
// (C) Copyright Samuli-Petrus Korhonen 2017.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// The author gratefully acknowleges the support of NMR Solutions, Inc., in
|
||||
// producing this work.
|
||||
|
||||
// Revision History:
|
||||
// 15 Feb 17 Initial version
|
||||
|
||||
#ifndef CONFIG_NUMPY20170215_H_
|
||||
# define CONFIG_NUMPY20170215_H_
|
||||
|
||||
# include <boost/config.hpp>
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Set up dll import/export options:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
// backwards compatibility:
|
||||
#ifdef BOOST_NUMPY_STATIC_LIB
|
||||
# define BOOST_NUMPY_STATIC_LINK
|
||||
# elif !defined(BOOST_NUMPY_DYNAMIC_LIB)
|
||||
# define BOOST_NUMPY_DYNAMIC_LIB
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NUMPY_DYNAMIC_LIB)
|
||||
# if defined(BOOST_SYMBOL_EXPORT)
|
||||
# if defined(BOOST_NUMPY_SOURCE)
|
||||
# define BOOST_NUMPY_DECL BOOST_SYMBOL_EXPORT
|
||||
# define BOOST_NUMPY_DECL_FORWARD BOOST_SYMBOL_FORWARD_EXPORT
|
||||
# define BOOST_NUMPY_DECL_EXCEPTION BOOST_EXCEPTION_EXPORT
|
||||
# define BOOST_NUMPY_BUILD_DLL
|
||||
# else
|
||||
# define BOOST_NUMPY_DECL BOOST_SYMBOL_IMPORT
|
||||
# define BOOST_NUMPY_DECL_FORWARD BOOST_SYMBOL_FORWARD_IMPORT
|
||||
# define BOOST_NUMPY_DECL_EXCEPTION BOOST_EXCEPTION_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NUMPY_DECL
|
||||
# define BOOST_NUMPY_DECL
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NUMPY_DECL_FORWARD
|
||||
# define BOOST_NUMPY_DECL_FORWARD
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NUMPY_DECL_EXCEPTION
|
||||
# define BOOST_NUMPY_DECL_EXCEPTION
|
||||
#endif
|
||||
|
||||
// enable automatic library variant selection ------------------------------//
|
||||
|
||||
#if !defined(BOOST_NUMPY_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_NUMPY_NO_LIB)
|
||||
//
|
||||
// Set the name of our library, this will get undef'ed by auto_link.hpp
|
||||
// once it's done with it:
|
||||
//
|
||||
#define BOOST_LIB_NAME boost_numpy
|
||||
//
|
||||
// If we're importing code from a dll, then tell auto_link.hpp about it:
|
||||
//
|
||||
#ifdef BOOST_NUMPY_DYNAMIC_LIB
|
||||
# define BOOST_DYN_LINK
|
||||
#endif
|
||||
//
|
||||
// And include the header that does the work:
|
||||
//
|
||||
#include <boost/config/auto_link.hpp>
|
||||
#endif // auto-linking disabled
|
||||
|
||||
#endif // CONFIG_NUMPY20170215_H_
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/numpy/numpy_object_mgr_traits.hpp>
|
||||
#include <boost/python/numpy/config.hpp>
|
||||
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
#include <boost/type_traits/add_pointer.hpp>
|
||||
@@ -25,7 +26,7 @@ namespace boost { namespace python { namespace numpy {
|
||||
*
|
||||
* @todo This could have a lot more interesting accessors.
|
||||
*/
|
||||
class dtype : public object {
|
||||
class BOOST_NUMPY_DECL dtype : public object {
|
||||
static python::detail::new_reference convert(object::object_cref arg, bool align);
|
||||
public:
|
||||
|
||||
@@ -55,7 +56,7 @@ public:
|
||||
* This is more permissive than equality tests. For instance, if long and int are the same
|
||||
* size, the dtypes corresponding to each will be equivalent, but not equal.
|
||||
*/
|
||||
friend bool equivalent(dtype const & a, dtype const & b);
|
||||
friend BOOST_NUMPY_DECL bool equivalent(dtype const & a, dtype const & b);
|
||||
|
||||
/**
|
||||
* @brief Register from-Python converters for NumPy's built-in array scalar types.
|
||||
@@ -69,7 +70,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
bool equivalent(dtype const & a, dtype const & b);
|
||||
BOOST_NUMPY_DECL bool equivalent(dtype const & a, dtype const & b);
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace boost { namespace python { namespace numpy {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct add_pointer_meta
|
||||
struct BOOST_NUMPY_DECL add_pointer_meta
|
||||
{
|
||||
template <typename T>
|
||||
struct apply
|
||||
@@ -29,8 +29,8 @@ struct add_pointer_meta
|
||||
|
||||
};
|
||||
|
||||
struct dtype_template_match_found {};
|
||||
struct nd_template_match_found {};
|
||||
struct BOOST_NUMPY_DECL dtype_template_match_found {};
|
||||
struct BOOST_NUMPY_DECL nd_template_match_found {};
|
||||
|
||||
template <typename Function>
|
||||
struct dtype_template_invoker
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/numpy/numpy_object_mgr_traits.hpp>
|
||||
#include <boost/python/numpy/ndarray.hpp>
|
||||
#include <boost/python/numpy/config.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace python { namespace numpy {
|
||||
|
||||
@@ -27,7 +29,7 @@ namespace boost { namespace python { namespace numpy {
|
||||
* bad things happen when Python shuts down. I think this solution is safe, but I'd
|
||||
* love to get that confirmed.
|
||||
*/
|
||||
class matrix : public ndarray
|
||||
class BOOST_NUMPY_DECL matrix : public ndarray
|
||||
{
|
||||
static object construct(object_cref obj, dtype const & dt, bool copy);
|
||||
static object construct(object_cref obj, bool copy);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/python/numpy/numpy_object_mgr_traits.hpp>
|
||||
#include <boost/python/numpy/dtype.hpp>
|
||||
#include <boost/python/numpy/config.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace python { namespace numpy {
|
||||
@@ -26,7 +28,8 @@ namespace boost { namespace python { namespace numpy {
|
||||
* @todo This could have a lot more functionality (like boost::python::numeric::array).
|
||||
* Right now all that exists is what was needed to move raw data between C++ and Python.
|
||||
*/
|
||||
class ndarray : public object
|
||||
|
||||
class BOOST_NUMPY_DECL ndarray : public object
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -139,32 +142,32 @@ public:
|
||||
/**
|
||||
* @brief Construct a new array with the given shape and data type, with data initialized to zero.
|
||||
*/
|
||||
ndarray zeros(python::tuple const & shape, dtype const & dt);
|
||||
ndarray zeros(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
BOOST_NUMPY_DECL ndarray zeros(python::tuple const & shape, dtype const & dt);
|
||||
BOOST_NUMPY_DECL ndarray zeros(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
|
||||
/**
|
||||
* @brief Construct a new array with the given shape and data type, with data left uninitialized.
|
||||
*/
|
||||
ndarray empty(python::tuple const & shape, dtype const & dt);
|
||||
ndarray empty(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
BOOST_NUMPY_DECL ndarray empty(python::tuple const & shape, dtype const & dt);
|
||||
BOOST_NUMPY_DECL ndarray empty(int nd, Py_intptr_t const * shape, dtype const & dt);
|
||||
|
||||
/**
|
||||
* @brief Construct a new array from an arbitrary Python sequence.
|
||||
*
|
||||
* @todo This does't seem to handle ndarray subtypes the same way that "numpy.array" does in Python.
|
||||
*/
|
||||
ndarray array(object const & obj);
|
||||
ndarray array(object const & obj, dtype const & dt);
|
||||
BOOST_NUMPY_DECL ndarray array(object const & obj);
|
||||
BOOST_NUMPY_DECL ndarray array(object const & obj, dtype const & dt);
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
ndarray from_data_impl(void * data,
|
||||
dtype const & dt,
|
||||
std::vector<Py_intptr_t> const & shape,
|
||||
std::vector<Py_intptr_t> const & strides,
|
||||
object const & owner,
|
||||
bool writeable);
|
||||
BOOST_NUMPY_DECL ndarray from_data_impl(void * data,
|
||||
dtype const & dt,
|
||||
std::vector<Py_intptr_t> const & shape,
|
||||
std::vector<Py_intptr_t> const & strides,
|
||||
object const & owner,
|
||||
bool writeable);
|
||||
|
||||
template <typename Container>
|
||||
ndarray from_data_impl(void * data,
|
||||
@@ -180,12 +183,12 @@ ndarray from_data_impl(void * data,
|
||||
return from_data_impl(data, dt, shape_, strides_, owner, writeable);
|
||||
}
|
||||
|
||||
ndarray from_data_impl(void * data,
|
||||
dtype const & dt,
|
||||
object const & shape,
|
||||
object const & strides,
|
||||
object const & owner,
|
||||
bool writeable);
|
||||
BOOST_NUMPY_DECL ndarray from_data_impl(void * data,
|
||||
dtype const & dt,
|
||||
object const & shape,
|
||||
object const & strides,
|
||||
object const & owner,
|
||||
bool writeable);
|
||||
|
||||
} // namespace boost::python::numpy::detail
|
||||
|
||||
@@ -247,39 +250,53 @@ inline ndarray from_data(void const * data,
|
||||
* @param[in] nd_max Maximum number of dimensions.
|
||||
* @param[in] flags Bitwise OR of flags specifying additional requirements.
|
||||
*/
|
||||
ndarray from_object(object const & obj, dtype const & dt,
|
||||
int nd_min, int nd_max, ndarray::bitflag flags=ndarray::NONE);
|
||||
BOOST_NUMPY_DECL ndarray from_object(object const & obj,
|
||||
dtype const & dt,
|
||||
int nd_min,
|
||||
int nd_max,
|
||||
ndarray::bitflag flags=ndarray::NONE);
|
||||
|
||||
inline ndarray from_object(object const & obj, dtype const & dt,
|
||||
int nd, ndarray::bitflag flags=ndarray::NONE)
|
||||
BOOST_NUMPY_DECL inline ndarray from_object(object const & obj,
|
||||
dtype const & dt,
|
||||
int nd,
|
||||
ndarray::bitflag flags=ndarray::NONE)
|
||||
{
|
||||
return from_object(obj, dt, nd, nd, flags);
|
||||
}
|
||||
|
||||
inline ndarray from_object(object const & obj, dtype const & dt, ndarray::bitflag flags=ndarray::NONE)
|
||||
BOOST_NUMPY_DECL inline ndarray from_object(object const & obj,
|
||||
dtype const & dt,
|
||||
ndarray::bitflag flags=ndarray::NONE)
|
||||
{
|
||||
return from_object(obj, dt, 0, 0, flags);
|
||||
}
|
||||
|
||||
ndarray from_object(object const & obj, int nd_min, int nd_max,
|
||||
ndarray::bitflag flags=ndarray::NONE);
|
||||
BOOST_NUMPY_DECL ndarray from_object(object const & obj,
|
||||
int nd_min,
|
||||
int nd_max,
|
||||
ndarray::bitflag flags=ndarray::NONE);
|
||||
|
||||
inline ndarray from_object(object const & obj, int nd, ndarray::bitflag flags=ndarray::NONE)
|
||||
BOOST_NUMPY_DECL inline ndarray from_object(object const & obj,
|
||||
int nd,
|
||||
ndarray::bitflag flags=ndarray::NONE)
|
||||
{
|
||||
return from_object(obj, nd, nd, flags);
|
||||
}
|
||||
|
||||
inline ndarray from_object(object const & obj, ndarray::bitflag flags=ndarray::NONE)
|
||||
BOOST_NUMPY_DECL inline ndarray from_object(object const & obj,
|
||||
ndarray::bitflag flags=ndarray::NONE)
|
||||
{
|
||||
return from_object(obj, 0, 0, flags);
|
||||
}
|
||||
|
||||
inline ndarray::bitflag operator|(ndarray::bitflag a, ndarray::bitflag b)
|
||||
BOOST_NUMPY_DECL inline ndarray::bitflag operator|(ndarray::bitflag a,
|
||||
ndarray::bitflag b)
|
||||
{
|
||||
return ndarray::bitflag(int(a) | int(b));
|
||||
}
|
||||
|
||||
inline ndarray::bitflag operator&(ndarray::bitflag a, ndarray::bitflag b)
|
||||
BOOST_NUMPY_DECL inline ndarray::bitflag operator&(ndarray::bitflag a,
|
||||
ndarray::bitflag b)
|
||||
{
|
||||
return ndarray::bitflag(int(a) & int(b));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#ifndef boost_python_numpy_numpy_object_mgr_traits_hpp_
|
||||
#define boost_python_numpy_numpy_object_mgr_traits_hpp_
|
||||
|
||||
#include <boost/python/numpy/config.hpp>
|
||||
|
||||
/**
|
||||
* @brief Macro that specializes object_manager_traits by requiring a
|
||||
* source-file implementation of get_pytype().
|
||||
@@ -14,7 +16,7 @@
|
||||
|
||||
#define NUMPY_OBJECT_MANAGER_TRAITS(manager) \
|
||||
template <> \
|
||||
struct object_manager_traits<manager> \
|
||||
struct BOOST_NUMPY_DECL object_manager_traits<manager> \
|
||||
{ \
|
||||
BOOST_STATIC_CONSTANT(bool, is_specialized = true); \
|
||||
static inline python::detail::new_reference adopt(PyObject* x) \
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace boost { namespace python { namespace numpy {
|
||||
*
|
||||
* @todo This could have a lot more functionality.
|
||||
*/
|
||||
class void_ : public object
|
||||
class BOOST_NUMPY_DECL void_ : public object
|
||||
{
|
||||
static python::detail::new_reference convert(object_cref arg, bool align);
|
||||
public:
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <boost/python/numpy/numpy_object_mgr_traits.hpp>
|
||||
#include <boost/python/numpy/dtype.hpp>
|
||||
#include <boost/python/numpy/ndarray.hpp>
|
||||
#include <boost/python/numpy/config.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace numpy {
|
||||
|
||||
@@ -34,7 +35,7 @@ namespace boost { namespace python { namespace numpy {
|
||||
* It's more dangerous than most object managers, however - maybe it actually belongs in
|
||||
* a detail namespace?
|
||||
*/
|
||||
class multi_iter : public object
|
||||
class BOOST_NUMPY_DECL multi_iter : public object
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -61,13 +62,13 @@ public:
|
||||
};
|
||||
|
||||
/// @brief Construct a multi_iter over a single sequence or scalar object.
|
||||
multi_iter make_multi_iter(object const & a1);
|
||||
BOOST_NUMPY_DECL multi_iter make_multi_iter(object const & a1);
|
||||
|
||||
/// @brief Construct a multi_iter by broadcasting two objects.
|
||||
multi_iter make_multi_iter(object const & a1, object const & a2);
|
||||
BOOST_NUMPY_DECL multi_iter make_multi_iter(object const & a1, object const & a2);
|
||||
|
||||
/// @brief Construct a multi_iter by broadcasting three objects.
|
||||
multi_iter make_multi_iter(object const & a1, object const & a2, object const & a3);
|
||||
BOOST_NUMPY_DECL multi_iter make_multi_iter(object const & a1, object const & a2, object const & a3);
|
||||
|
||||
/**
|
||||
* @brief Helps wrap a C++ functor taking a single scalar argument as a broadcasting ufunc-like
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace boost { namespace python
|
||||
{
|
||||
struct BOOST_PYTHON_DECL_FORWARD instance_holder;
|
||||
struct instance_holder;
|
||||
}} // namespace boost::python
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
Import('env')
|
||||
|
||||
env.AppendUnique(CPPDEFINES = ["${LINK_DYNAMIC and 'BOOST_PYTHON_DYN_LINK=1' or ''}"])
|
||||
env.AppendUnique(CPPDEFINES = ['BOOST_PYTHON_SOURCE'])
|
||||
|
||||
env.BoostLibrary(
|
||||
env1 = env.Clone()
|
||||
env1.AppendUnique(CPPDEFINES = ['BOOST_PYTHON_SOURCE'])
|
||||
|
||||
env1.BoostLibrary(
|
||||
'python',
|
||||
['numeric.cpp',
|
||||
'list.cpp',
|
||||
@@ -44,7 +46,13 @@ env.BoostLibrary(
|
||||
'object/function_doc_signature.cpp'])
|
||||
|
||||
if env['NUMPY']:
|
||||
env.BoostLibrary(
|
||||
env2 = env.Clone()
|
||||
env2.Append(CPPPATH=env['NUMPY_CPPPATH'])
|
||||
build_dir = env.Dir('$BOOST_CURRENT_VARIANT_DIR/src')
|
||||
env2.AppendUnique(CPPDEFINES = ['BOOST_NUMPY_SOURCE'],
|
||||
LIBPATH = [build_dir],
|
||||
LIBS='boost_python' + env["BOOST_SUFFIX"])
|
||||
env2.BoostLibrary(
|
||||
'numpy',
|
||||
['numpy/dtype.cpp',
|
||||
'numpy/matrix.cpp',
|
||||
|
||||
@@ -430,6 +430,22 @@ namespace
|
||||
// Remember that this will be used to construct the result object
|
||||
static std::wstring extract(PyObject* intermediate)
|
||||
{
|
||||
// On Windows, with Python >= 3.3, PyObject_Length cannot be used to get
|
||||
// the size of the wchar_t string, because it will count the number of
|
||||
// *code points*, but some characters not on the BMP will use two UTF-16
|
||||
// *code units* (surrogate pairs).
|
||||
// This is not a problem on Unix, since wchar_t is 32-bit.
|
||||
#if defined(_WIN32) && PY_VERSION_HEX >= 0x03030000
|
||||
BOOST_STATIC_ASSERT(sizeof(wchar_t) == 2);
|
||||
|
||||
Py_ssize_t size = 0;
|
||||
wchar_t *buf = PyUnicode_AsWideCharString(intermediate, &size);
|
||||
if (buf == NULL) {
|
||||
boost::python::throw_error_already_set();
|
||||
}
|
||||
std::wstring result(buf, size);
|
||||
PyMem_Free(buf);
|
||||
#else
|
||||
std::wstring result(::PyObject_Length(intermediate), L' ');
|
||||
if (!result.empty())
|
||||
{
|
||||
@@ -444,6 +460,7 @@ namespace
|
||||
if (err == -1)
|
||||
throw_error_already_set();
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
static PyTypeObject const* get_pytype() { return &PyUnicode_Type;}
|
||||
|
||||
10
test/Jamfile
10
test/Jamfile
@@ -237,4 +237,14 @@ bpl-test crossmod_opaque
|
||||
[ py-compile-fail ./as_to_python_function.cpp ]
|
||||
[ py-compile-fail ./object_fail1.cpp ]
|
||||
|
||||
# --- NumPy tests ---
|
||||
|
||||
[ numpy-test numpy/dtype ]
|
||||
[ numpy-test numpy/ufunc ]
|
||||
[ numpy-test numpy/templates ]
|
||||
[ numpy-test numpy/ndarray ]
|
||||
[ numpy-test numpy/indexing ]
|
||||
[ numpy-test numpy/shapes ]
|
||||
|
||||
|
||||
;
|
||||
|
||||
@@ -8,9 +8,18 @@
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import platform
|
||||
import sys
|
||||
|
||||
Import('env')
|
||||
|
||||
if sys.platform == 'win32':
|
||||
# HACK: This works around a bug in SCons.
|
||||
# subprocess.check_output will complain unless all environment
|
||||
# variables are strings.
|
||||
system_root = env['ENV']['SystemRoot']
|
||||
env['ENV']['SystemRoot'] = str(system_root)
|
||||
|
||||
|
||||
# libs needed for embedding
|
||||
ELIBS=env['LIBS'] + env['PYTHONLIBS']
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
import dtype_ext
|
||||
import unittest
|
||||
import numpy
|
||||
import sys
|
||||
if (sys.version_info.major >= 3):
|
||||
long = int
|
||||
|
||||
class DtypeTestCase(unittest.TestCase):
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
# Copyright David Abrahams 2004. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
import sys
|
||||
if (sys.version_info.major >= 3):
|
||||
long = int
|
||||
r"""
|
||||
>>> from builtin_converters_ext import *
|
||||
|
||||
@@ -136,6 +133,9 @@ True
|
||||
>>> print(rewrap_value_wstring(u'yo, wassup?'))
|
||||
yo, wassup?
|
||||
|
||||
>>> print(rewrap_value_wstring(u'\U0001f4a9'))
|
||||
\U0001f4a9
|
||||
|
||||
test that overloading on unicode works:
|
||||
|
||||
>>> print(rewrap_value_string(u'yo, wassup?'))
|
||||
@@ -283,6 +283,10 @@ Check that classic classes also work
|
||||
>>> assert return_null_handle() is None
|
||||
"""
|
||||
|
||||
import sys
|
||||
if (sys.version_info.major >= 3):
|
||||
long = int
|
||||
|
||||
def run(args = None):
|
||||
import sys
|
||||
import doctest
|
||||
|
||||
Reference in New Issue
Block a user