2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-20 16:52:15 +00:00

Compare commits

..

421 Commits

Author SHA1 Message Date
Abhay Kumar
97402f7925 🐛 Fix broken link to Jamroot in example docs 2025-11-03 10:14:34 -05:00
Anton Gladky
668bc7c106 Include missing header boost/type_traits/is_unsigned.hpp
During the Debian Packaging of new version it was found that
this header is missing during the rebuild with GCC-15.
2025-11-03 10:13:40 -05:00
Eisuke Kawashima
5f5f38fa8a fix: fix quotation 2025-11-03 09:30:32 -05:00
Stefan Seefeld
cc873d9682 Fix documentation build error. 2025-11-03 08:40:38 -05:00
Stefan Seefeld
20de46cd0c Update faber 2025-11-03 08:40:38 -05:00
Stefan Seefeld
5d7b9a0648 Stop testing c++98 support 2025-11-03 08:40:38 -05:00
Tom Kent
608ec27c4d Updated to recent compilers/boost 2025-11-03 08:40:38 -05:00
Stefan Seefeld
7fd39323ac Don't rely on Py_REFCNT to test upcast. 2025-11-03 08:40:38 -05:00
Eisuke Kawashima
2b6f667e98 chore: remove meaningless comparison 2025-10-25 15:23:44 -04:00
Eisuke Kawashima
aa458d2ca9 fix(test.properties): use doctest.ELLIPSIS for traceback
Since python 3.11 (PEP 657) traceback info is changed
fix #460
2025-10-25 15:22:21 -04:00
Eisuke Kawashima
16627261f1 fix(test.pickle): fix for change in the return value of object.__reduce__()
https://docs.python.org/3.11/library/pickle.html#object.__reduce__

fix #461
2025-10-25 14:14:07 -04:00
Stefan Seefeld
303299e677 log commands 2025-10-25 13:25:52 -04:00
Stefan Seefeld
cb95b611bb Downgrade run-vcpkg dependency to avoid regression. 2025-10-25 13:25:52 -04:00
Eisuke Kawashima
b4fb28e99a ci: update GitHub Actions 2025-10-23 22:14:55 -04:00
Stefan Seefeld
867f0dddfe Fix windows header path. 2025-10-23 22:08:00 -04:00
Aditya Pillai
a40bb656ee Use Py_REFCNT instead of ob_refcnt on Python 3.9 and above 2025-10-23 19:38:05 -04:00
Eisuke Kawashima
f604eb8d0f fix(test.numpy/ufunc): fix import error and value comparison 2025-04-02 08:21:09 -04:00
Eisuke Kawashima
d30c1bb7a8 refactor: switch to python 3 2025-03-31 21:58:42 -04:00
Aditya Pillai
3e7be69e1e Conditionally use Py_REFCNT 2025-03-10 15:10:12 -04:00
Aditya Pillai
cbdf1ce2a1 Use Py_REFCNT instead of ->ob_refcnt
Py_REFCNT was stabilized in 3.9, uses this official API instead of the
`ob_refcnt` field that doesn't exist in the free-threaded build of 3.13.
2025-03-10 15:10:12 -04:00
Stefan Seefeld
4fe3403584 Make sure to pass C++ version to preprocessor as well. 2025-02-01 22:55:02 -05:00
Stefan Seefeld
b1b43f1e1a Fix homebrew include path. 2025-02-01 22:55:02 -05:00
Peter Dimov
7b1960446b Merge pull request #470 from boostorg/pr/fix-iterator-detail
Replace use of boost/iterator/detail/enable_if.hpp
2025-02-01 19:35:16 +02:00
Peter Dimov
2dc5a92727 Replace use of boost/iterator/detail/enable_if.hpp 2025-01-28 02:27:49 +02:00
sdarwin
4fc3afa3ac Support newer version of Sphinx 2024-10-10 09:28:59 -04:00
Vitaly Buka
ff0ae9b29d dynamic_cast before destructor
Call to the destructor ends lifetime of the object, including vptr
used by dynamic_cast.
2024-09-22 12:30:12 -04:00
Daniel Laügt
b988d70207 Alignment fixes 2024-09-21 21:56:41 -04:00
Stefan Seefeld
b3a28d7033 Use the expected return type. 2024-09-18 21:09:05 -04:00
Stefan Seefeld
3ea0cb8501 Upgrade CI platforms. 2024-09-18 21:09:05 -04:00
Jakob van Santen
95e53011d8 Conditionalize nested test for py2
__qualname__ didn't exist before python 3.3. Skip checks that depend on it if running in earlier Python versions
2024-09-18 10:36:45 -04:00
Jakob van Santen
301256cf1e Avoid setting __doc__ on instance methods 2024-09-18 10:36:45 -04:00
Jakob van Santen
c76d67ef3f Ensure that virtual default implementation has the same kwargs as dispatcher 2024-09-17 17:07:44 -04:00
Jakob van Santen
0102b31945 Unwrap back_reference in get_pytype()
This prevents back_reference parameters from decaying to "object" in py signatures
2024-09-17 17:07:44 -04:00
Jakob van Santen
4c6f40fb82 Add generated docstrings to property fget/fset 2024-09-17 17:07:44 -04:00
Jakob van Santen
d1910f3d65 Avoid degrading slice to object in generated sig 2024-09-17 17:07:44 -04:00
Jakob van Santen
c4e3b13dc2 Use qualname for enum repr 2024-09-17 17:07:44 -04:00
Jakob van Santen
a498e2458c Qualify types defined in other modules 2024-09-17 17:07:44 -04:00
Jakob van Santen
7a3cc07042 Emit qualfied names in docstrings 2024-09-17 17:07:44 -04:00
Jakob van Santen
58b1a010bb Set __qualname__ for Python >= 3.3 2024-09-17 17:07:44 -04:00
Rene Rivera
8ca8724ad9 Update build deps. 2024-08-18 13:16:00 -04:00
Rene Rivera
5a8d096135 Split b2 dependencies into public and private. 2024-08-18 13:16:00 -04:00
Rene Rivera
30bdbf3ae2 Move inter-lib dependencies to a project variable and into the build targets. 2024-08-18 13:16:00 -04:00
Rene Rivera
5a07cdb96b Bump B2 require to 5.2 2024-08-18 13:16:00 -04:00
Rene Rivera
06fa956fe8 Add requires-b2 check to top-level build file. 2024-08-18 13:16:00 -04:00
Rene Rivera
9ab1742c46 Add missing NO_LIB usage requirements. 2024-08-18 13:16:00 -04:00
Rene Rivera
071b0bc964 Switch to library requirements instead of source. As source puts extra source in install targets. 2024-08-18 13:16:00 -04:00
Rene Rivera
d8d9861036 Put back removing qualified boostcpp tag. As we need it until the Jamroot removes the qualified tag. 2024-08-18 13:16:00 -04:00
Rene Rivera
f6d20e1099 Make the library modular usable. 2024-08-18 13:16:00 -04:00
Billy K. Poon
99a5352b5c Another fix for numpy 2.0
- Compare pointers directly instead of using PyArray_EquivTypes
2024-07-16 14:15:12 -04:00
Konstantin Podsvirov
1fed0824ad Fix typo in numpy tutorial 2024-07-01 15:29:32 -04:00
Alexis DUBURCQ
0474de0f6c Support numpy 2.0.0b1 2024-05-06 09:51:13 +02:00
Peter Dimov
6c3f3ecacf Normalize static/dynamic link macros and avoid redefinition warnings 2023-12-22 08:14:53 -05:00
Stefan Seefeld
47d5bc76f6 Revert "Remove obsolete Jamfile" 2022-09-05 21:43:23 -04:00
Stefan Seefeld
508da1d198 Fix windows CI builds. 2022-08-24 13:02:31 -04:00
Stefan Seefeld
271bcea8bf Don't attempt to deploy documentation from PRs. 2022-08-24 13:02:31 -04:00
Stefan Seefeld
fdd3e8b2c1 Remove obsolete Jamfile 2022-08-24 13:02:31 -04:00
Victor Stinner
a218babc8d Fix enum_type_object type on Python 3.11
The enum_type_object type inherits from PyLong_Type which is not tracked
by the GC. Instances doesn't have to be tracked by the GC: remove the
Py_TPFLAGS_HAVE_GC flag.

The Python C API documentation says:

    "To create a container type, the tp_flags field of the type object
    must include the Py_TPFLAGS_HAVE_GC and provide an implementation of
    the tp_traverse handler."

https://docs.python.org/dev/c-api/gcsupport.html

The new exception was introduced in Python 3.11 by:
https://github.com/python/cpython/issues/88429
2022-04-26 09:42:26 -04:00
Denis Arnaud
41e208ecb5 Update call_method.hpp
Was missing from https://github.com/boostorg/python/pull/320
I've tested it on one of my projects with (that patch on) Boost.Python/Boost 1.76.0 and it works well. Without that patch, there is a deprecation error.
2022-03-19 13:06:49 -04:00
Hajo Kirchhoff
f028aa4076 -fix: issue #239 exec_file does not close the FILE handle. Note: Using FILE* is a bad choice here because of possible exceptions, but Py_RunFile is a C function. This fix works, because Py_RunFile - as a C function - does not throw exceptions. 2021-08-10 12:25:40 -04:00
Hajo Kirchhoff
a060d43bf2 -fix: boost::python::exec_file completely broken when PY_VERSION_HEX >= 0x03010000. Bug: char* f pointed to a temporary buffer returned by PyBytes_AsString. This buffer was released when Py_DECREF(fb) was called. As a result, f pointed to invalid memory when being passed to Py_RunFile. 2021-08-10 12:25:40 -04:00
Stefan Seefeld
8dd1511773 Use the /python//numpy target instead of [ numpy.include ] (fixes #361) 2021-07-04 15:29:43 -04:00
Peter Dimov
909a4d1530 Merge branch 'master' into develop 2021-06-10 02:46:19 +03:00
TaWeiTu
aee2667407 Fix deprecated usage of <boost/bind.hpp>
Replace <boost/bind.hpp> with <boost/bind/bind.hpp> and use namespace
boost::placeholders when necessary.
2021-06-09 07:16:19 -04:00
Peter Dimov
209179fa09 Add CMakeLists.txt 2021-06-04 03:10:21 +03:00
Stefan Seefeld
5e77eabb63 Revert previous commit until 'Boost.Build' is ready. 2021-05-26 07:46:42 -04:00
Peter Dimov
ecda18f01e Use the /python//numpy target instead of [ numpy.include ] (fixes #361) 2021-05-24 18:54:56 -04:00
Stefan Seefeld
2a82afdf6d Upgrade base image & build prerequisites. 2021-04-30 22:59:25 -04:00
Stefan Seefeld
aca3c80c4f Respect alignment of by-value storage. 2021-04-30 22:59:25 -04:00
Stefan Seefeld
68fa9dccde Merge branch 'develop' 2021-03-04 11:57:23 -05:00
Dmitry Bely
f5d14ef15e Fix issue #280 2021-02-07 23:07:30 -05:00
Dmitry Bely
f7254f5d8a Add a test case for issue #280 2021-02-07 23:07:30 -05:00
Edward Diener
bffcb99ae7 [skip ci] Add "cxxstd" json field. The "cxxstd" json field is being added to each Boost library's meta json information for libraries in order to specify the minumum C++ standard compilation level. The value of this field matches one of the values for 'cxxstd' in Boost.Build. The purpose of doing this is to provide information for the Boost website documentation for each library which will specify the minimum C++ standard compilation that an end-user must employ in order to use the particular library. This will aid end-users who want to know if they can successfully use a Boost library based on their C++ compiler's compilation level, without having to search the library's documentation to find this out. 2021-01-21 07:25:16 -05:00
Victor Stinner
cbd2d9f033 Fix compatibility with Python 3.10.0a4: fopen
Replace private _Py_fopen() with public fopen(): private _Py_fopen()
function was removed in 3.10.0a4:
https://bugs.python.org/issue32381
2021-01-06 07:55:48 -05:00
Cedric Schmeits
0f1945060f noncopyable is located in the boost namespace 2021-01-04 01:35:25 -05:00
Cedric Schmeits
30dd3fe8b1 added includes for call_method.hpp and def.hpp 2021-01-04 01:35:25 -05:00
Stefan Seefeld
500194edb7 Fix Python 3.10 (PEP-620) incompatibility. 2021-01-04 01:31:40 -05:00
Stefan Seefeld
cd953cff06 Replace appveyor by github actions. 2021-01-04 00:21:07 -05:00
Stefan Seefeld
5e4f6278e0 Remove travis-ci logic. 2020-12-26 14:53:19 -05:00
Stefan Seefeld
108c93f7c3 Deploy documentation via github actions. 2020-12-26 14:53:19 -05:00
Stefan Seefeld
3dd6bcf39f Add OSX tests. 2020-12-26 14:53:19 -05:00
Tom Kent
97a8550a9f Using docker images to execut the github actions for testing (#335)
Introduce github action-based test workflow for Ubuntu.
2020-12-22 16:56:09 -05:00
Thomas Kent
c9521a8ef5 Updated VS2019 to 16.8.3 2020-12-22 16:53:56 -05:00
Thomas Kent
8328a4f535 New VS2019 version on appveyor 2020-12-13 14:14:29 -05:00
Stefan Seefeld
cc973263c4 Merge branch 'develop' 2020-11-02 00:58:26 -05:00
Pat Riehecky
f1320bf30b Add pypy3 to TravisCI matrix 2020-10-16 12:35:44 -04:00
Pat Riehecky
d9f06052e2 Convert Python 3.1+ to use public C API for filenames 2020-10-16 12:35:44 -04:00
Pat Riehecky
9ad5298d0b Use python macros to stay on public API for new pythons 2020-10-16 12:35:44 -04:00
Pat Riehecky
944fa075b3 Stop using deprecated API calls (python-3.9) #319 2020-10-15 21:54:47 -04:00
Stefan Seefeld
b4fbf1840b Fix appveyor builds. 2020-10-15 12:45:35 -04:00
Stefan Seefeld
ec402ea0d7 Merge branch 'develop' 2020-08-14 15:59:10 -04:00
David Seifert
60405cc48c Remove Boost.Python-specific python-tag code 2020-08-08 02:32:07 -04:00
Austin Maliszewski
9e1132f4f5 Handle NULL from call to PyLong_Type
PyLong_Type raises an exception if the argument is not convertible to
long, therefore, this has to be handled as new_reference and not
new_non_null_reference, otherwise a segfault will occur.
2020-08-08 02:30:46 -04:00
Tyler Kieft
bf824c1b98 Ensure all doctests run 2020-08-08 02:19:03 -04:00
Andrey Semashev
01ab510585 Removed usage of deprecated header boost/detail/iterator.hpp.
The header is deprecated in favor of <iterator>. It generates compiler
warnings and will be removed in a future release.
2020-08-07 18:09:31 -04:00
Edward Diener
5e2d55d801 Revert back to original, as __cdecl is fine with the Embarcadero C++ clang-based compilers. 2020-08-07 17:35:12 -04:00
Edward Diener
17886fc296 Change __BORLANDC__ to BOOST_BORLANDC, which is defined in Boost config for the Embarcadero non-clang-based compilers. 2020-08-07 17:35:12 -04:00
Stefan Seefeld
15115eb1f8 Fix appveyor build failures. 2020-08-07 14:04:30 -04:00
Julien Schueller
1727b67a5a detail/caller.hpp:127:2: error: extra ';' [-Wpedantic] 2019-06-01 19:07:40 -04:00
Peter Dimov
0a9b687e9e Merge pull request #264 from boostorg/pr/fix-numpy-install
Only boost-install boost_numpy when it's being built
2019-04-17 15:08:15 -07:00
Peter Dimov
8c8b0dc215 Only boost-install boost_numpy when it's being built 2019-04-18 00:02:52 +03:00
Nikita Kniazev
fdc9ec760f Fixed module tests fail
Since recently lightweight_test introduced a sanitation to ensure that
`boost::report_errors()` is called, and it does not in module tests.

The problem could be fixed by exporting the function and calling it from
these python tests, but as it already done in other module tests I just
turned those usages lightweight_test to a regular assertation.
2019-03-31 20:36:56 -04:00
Stefan Seefeld
102acf1d34 Merge branch 'develop' 2019-03-29 09:41:46 -04:00
Nikita Kniazev
0b0c0536d6 The right hypot fix for MinGW 2019-03-26 15:56:03 -04:00
Owens
0d0cd711a7 Enable forward declaration of unwind_type() in msvc14.15 and later.
Name lookup in msvc has changed between 14.14 and 14.15 making it consistent with other compilers. Forward declaration of unwind_type() is now required as it is for other compilers.

Resolves compilation errors identified in:

https://github.com/boostorg/python/issues/228
2019-03-25 11:00:48 -04:00
Jonathan Wakely
72e254bf8b Fix name of file in tutorial
I think it's meant to refer to the Jamroot file being discussed, not Jamrules.
2019-03-23 20:38:29 -04:00
Nikita Kniazev
1f1b9b6aef Fix hypot issue on MinGW 2019-03-23 20:37:35 -04:00
Nikita Kniazev
6bd6d71850 Fix -Wregister error on Clang in C++17 mode
Suppresses the warning on GCC, Clang, and MSVC.
2019-03-21 16:40:41 -04:00
Stefan Seefeld
b9c0e58d57 Merge branch 'develop' 2019-03-05 21:39:52 -05:00
Tom Kent
4b01139720 Ssize t warning - trac #3353 (#21)
Fixes msvc unsafe type conversion warning - trac num: 3353
2019-03-03 22:02:57 -05:00
SPKorhonen
65bfec2d97 Fix static object initialization under Visual Studio 2017 (#208)
Fix static object initialization under VS 15.7.2
2019-03-03 21:59:48 -05:00
Orivej Desh
4f6d547c0a clear python exception after expected attribute lookup failure
Python 3.7.0 asserts that attribute lookup functions are called without outstanding exceptions:
https://github.com/python/cpython/blob/v3.7.0a2/Objects/typeobject.c#L3037
Motivation: https://bugs.python.org/issue34068#msg321262
Therefore the error set by the first PyObject_GetItem should be cleared before calling PyObject_GetAttrString.
2019-02-13 23:38:02 -05:00
Stefan Seefeld
90813b1ad7 Merge branch 'develop' 2019-01-10 18:45:39 -05:00
Peter Dimov
b644946368 Add comments explaining the stage/install targets in build/Jamfile 2018-10-12 14:34:15 -04:00
Peter Dimov
c7799aa44f Add empty stage/install targets when Python is not configured 2018-10-12 14:34:15 -04:00
Peter Dimov
02095af952 Use boost-install in build/Jamfile 2018-10-12 09:42:51 -04:00
Stefan Seefeld
6f72675bff Merge branch 'develop' 2018-07-11 19:25:10 -04:00
Moritz Wanzenböck
ed4776b59c Add missing return statement in numpy import
This adds a missing return statement in the python3 specific
import logic of boost.python.numpy.

For python3 wrap_import_array() needs to return a pointer value.
The import_array() macro only returns NULL in case of error. The
missing return statement is UB, so the compiler can assume it does
not happen. This means the compiler can assume the error branch
is always taken, so import_array must always fail.
2018-07-11 16:40:19 -04:00
Markus Gerstel
ac62db1cf1 Drop injector code example from tutorials.
This example depends on the behaviour of ```__metaclass__```. This has
changed in python 3, and the example no longer works. Removing example
code as suggested, see #210 for more details and possible alternatives.

Closes #210.
2018-06-08 14:59:41 -04:00
Stefan Seefeld
b4230e98f6 Fix auto-linking logic for boost_numpy (Windows only). 2018-06-04 09:34:00 -04:00
Stefan Seefeld
467a89eba7 Fix issue 198. 2018-05-06 13:35:16 -04:00
The Gitter Badger
28e2c6512c Add Gitter badge 2018-05-03 10:19:01 -04:00
Stefan Seefeld
b0f512c15a Merge branch 'develop' 2018-04-17 21:32:48 -04:00
Stefan Seefeld
77ff0d6bbc Fix CI OSX build failure. 2018-04-17 20:41:17 -04:00
Stefan Seefeld
24313709a7 Fix auto-linking logic (Windows only). 2018-04-12 23:39:22 -04:00
Stefan Seefeld
ac9fa536c8 Add OSX to CI test matrix. 2018-04-08 21:34:48 -04:00
Gaurav
7352c9c0f7 Remove not reachable condition.
Line no 138-139 suggest if condition satisfy if n_actual <=max_arity :
        if (n_actual + f->m_nkeyword_values >= min_arity
            && n_actual <= max_arity)
So condition at Line no 161 is not reachable.
2018-04-08 21:18:57 -04:00
Stefan Seefeld
26ac881b9d Fix CI links. 2018-04-08 20:41:51 -04:00
Stefan Seefeld
19f6c782aa Improve CI test coverage. 2018-04-08 18:21:22 -04:00
Stefan Seefeld
f3df1bf912 Remove redundant pragma once directives. 2018-04-07 17:05:18 -04:00
Stefan Seefeld
a383ecdd88 Fix build warning. 2018-03-19 13:58:48 -04:00
Stefan Seefeld
d515eb82c8 Fix build warning. 2018-03-15 15:29:06 -04:00
Stefan Seefeld
0021720a46 Conditionalize targets on Python configuration. 2018-03-11 10:31:21 -04:00
Stefan Seefeld
61591f7ad2 Enable more MSVC versions. 2018-03-09 13:17:24 -05:00
Stefan Seefeld
6b8ab7a5a3 Conditionalize tests. 2018-03-09 13:08:07 -05:00
Stefan Seefeld
02e079cf4d Merge branch 'develop' 2018-03-08 07:07:42 -05:00
Stefan Seefeld
9039286937 Remove references to scons from README. 2018-03-07 16:54:10 -05:00
Stefan Seefeld
429ac28c4a Streamline CI logic. 2018-03-07 15:09:02 -05:00
Stefan Seefeld
1db3871f50 Remove obsolete scons-based build logic. 2018-03-07 15:09:02 -05:00
Stefan Seefeld
66dad425aa Build docs with faber. 2018-03-07 15:09:02 -05:00
Stefan Seefeld
ed3cbf8a60 Start to collect release notes. 2018-02-25 17:39:18 -05:00
Stefan Seefeld
2f6e728de5 Fix misspelled operator name. 2018-02-20 16:43:58 -05:00
Stefan Seefeld
65be0e0f0f Only iterate over multiple calling conventions on x86. 2018-02-15 22:17:04 -05:00
Stefan Seefeld
d4d41d94ae Add Python version to library suffix. 2018-02-13 17:22:34 -05:00
Bernhard Rosenkränzer
660487c43f Fix build with Python 3.7
Python 3.7 changes the return type of _PyUnicode_AsString()
from void* to const char* -- causing the build of boost-python
to fail.

Signed-off-by: Bernhard Rosenkränzer <bero@lindev.ch>
2018-02-09 15:09:27 -05:00
Stefan Seefeld
d6d54ce483 This is an object, not a function declaration. Really. 2017-12-18 15:04:23 -05:00
Stefan Seefeld
7c33ff0c59 Merge branch 'develop' 2017-11-17 10:06:54 -05:00
Stefan Seefeld
b9d0d97499 Fix MSVC compilation failure. 2017-11-16 10:26:30 -05:00
Stefan Seefeld
fc978f085b Merge branch 'develop' 2017-11-11 08:04:54 -05:00
Stefan Seefeld
ebba009a9f First attempt at faber-based build system. 2017-11-10 07:41:21 -05:00
Stefan Seefeld
9ad3313d1f Fix deprecated elementwise comparison warning / error. 2017-11-07 19:43:16 -05:00
Stefan Seefeld
bf9a03399b Revert "Avoid multiple template instances of boost::python::details::get_signature when multiple calling conventions are enabled"
This reverts commit b49a186b6f.
2017-10-30 08:04:01 -04:00
Stefan Seefeld
2d9871fc5a Fix unresolved symbol error with MSVC. 2017-10-27 13:58:56 -04:00
Gary Furnish
30c9eb1fb6 Fix c++11 detection. 2017-10-25 08:07:17 -04:00
Gary Furnish
7c5e478432 Fix autoptr/unique_ptr ifdef for VS2017. 2017-10-25 08:07:17 -04:00
Krzysztof Trzciński
2b7842a39f Fix memory leaks in enum.cpp
Unfortunately due to optimised build of Python3 libraries and executable I got only partial stack from [http://clang.llvm.org/docs/AddressSanitizer.html], however digging into and reducing my code I tracked it down to be issue with `boost/libs/python/src/object/enum.cpp`.

It has to bits that leak (and comment mentioning there is one):

    PyObject *mod = PyObject_GetAttrString( self_, "__module__");

Leaks reference, as it never decreases it.
It also stores a new string object under object's `name` that ref count never gets decremented.

That commit fixes both issues.
2017-10-25 08:04:35 -04:00
Raffi Enficiaud
8d37630cc8 Fix warning: returning the proper type for object sizes 2017-10-25 08:03:18 -04:00
Marvin Schmidt
9d2903cd5e Fix symbol visibility of init method
This was properly an oversight when switching to the BOOST_SYMBOL_*
symbols from Boost.Config in commit 0224f54a (see #1)

Since Boost.Config is already doing the differentiation between
different platforms and compilers we can simplify this bit and just
use BOOST_SYMBOL_EXPORT
2017-10-24 20:18:59 -04:00
Frank Richter
b09d80a93e Fix exec(), eval() not passing through arguments 2017-10-18 07:37:03 -04:00
Mark Borgerding
135c025484 fixed nuisance warning when calling from_data(...,bob) with an ndarray bob, "FutureWarning: comparison to None will result in an elementwise object comparison in the future." 2017-09-25 09:08:38 -04:00
Mark Borgerding
ecf05c4a90 ndarray.shape(k),strides(k) act more like their python counterparts (negative indexing, bounds checking) (issue #157) 2017-09-25 09:08:14 -04:00
Edward Diener
00b7ed03a7 Remove executable attribute for files. 2017-09-18 08:21:30 -04:00
Stefan Seefeld
fed4f0d0f9 Fix version number. 2017-08-19 11:57:56 -04:00
Stefan Seefeld
39edfd45cf Fix traits qualification. 2017-08-19 11:57:39 -04:00
Stefan Seefeld
c2424bcc8f Fix version number. 2017-08-13 20:45:13 -04:00
Stefan Seefeld
b3b67273b0 Fix traits qualification. 2017-08-13 20:44:52 -04:00
Stefan Seefeld
8c2a808cbe Remove 'numeric' documentation. 2017-07-31 11:38:40 -04:00
Stefan Seefeld
31c8b7f1b4 Remove 'numeric' documentation. 2017-07-31 11:37:52 -04:00
Stefan Seefeld
aeedea409a Merge branch 'develop' 2017-07-20 13:04:44 -04:00
Stefan Seefeld
2d1f66fd19 Remove module as obsoleted by Boost.NumPy. 2017-07-20 11:39:58 -04:00
Stefan Seefeld
69e38d2186 Fix documentation. 2017-07-20 10:11:19 -04:00
Stefan Seefeld
df6926551e Merge branch 'develop' 2017-06-25 18:27:19 -04:00
Stefan Seefeld
8536e97c67 Use utf-8 encoding 2017-06-25 14:33:42 -04:00
shreyans800755
142661dac8 Use std type_traits instead of boost type_traits
Fixes https://github.com/boostorg/python/issues/106
2017-06-25 14:17:41 -04:00
John Kirkham
d6554d6c65 Handle BOOST_LIB_NAME for NumPy on Python 2/3
This was reusing the Python 2 name on Python 3, which is incorrect since
the Python 3 library for Boost.NumPy has a `3` in it. Hence this checks
against the Python version and defines this correctly.
2017-06-12 09:32:31 -04:00
John Kirkham
90829714cc Fix BOOST_LIB_NAME for Python 3
This was reusing the Python 2 name on Python 3, which is incorrect since
the Python 3 library for Boost.Python now has a `3` in it. Hence this
checks against the Python version and defines this correctly.
2017-06-12 09:32:31 -04:00
Stefan Seefeld
664d443df3 Fix Python3 compatibility bug. 2017-06-03 18:26:14 -04:00
Stefan Seefeld
c4fe369d69 Require NumPy 1.7 API. 2017-06-02 19:31:54 -04:00
Stefan Seefeld
7cfc47008e Rename test source 2017-06-02 19:31:54 -04:00
Raphael Isemann
1452dfe713 Reencoded a few headers that used Windows-1252 with UTF-8.
Nearly every header in the boost codebase is UTF-8, but here there
are a few headers which are using Windows-1252, which makes it impossible
for some tools to parse those files. This patch just reencodes them
with UTF-8 like the rest of the codebase. I checked that the name of the
author is still correct after this change.

No functional change intended.
2017-06-02 17:44:46 -04:00
Saliya
3613142839 Fixing compiling error 'error: ‘NPY_FLOAT16’ was not declared in this scope'
Signed-off-by: Saliya <hamparawa@gmail.com>
2017-06-02 15:35:04 -04:00
John Zwinck
b2f53e1acf exec/eval(): add overloads for char const*
Many times the caller may have a string created in C++,
so there is no need to wrap it in a Python object when
the only thing done with the object is extract<char*>.
2017-05-04 19:29:56 -04:00
Stefan Seefeld
3844c4fc5f Fix more missing symbols. 2017-04-14 13:14:05 -04:00
Stefan Seefeld
7d3df3d3a7 Merge branch 'develop' 2017-03-28 12:57:32 -04:00
Stefan Seefeld
df16e3e55e Fix typo. 2017-03-28 12:54:05 -04:00
Stefan Seefeld
ae747521b0 Merge branch 'develop' 2017-03-24 15:53:30 -04:00
Stefan Seefeld
3066c73c09 Fix Windows builds. 2017-03-24 15:39:13 -04:00
Stefan Seefeld
edd890bd2b More dllexport fixes 2017-03-24 15:39:13 -04:00
Stefan Seefeld
352792c90a Add more export symbols. 2017-03-16 20:14:39 -04:00
Stefan Seefeld
47faef65ee Fix documentation links. 2017-03-16 11:35:26 -04:00
Rene Rivera
5e4b44e0af Don't build numpy if there's no python version to target. 2017-03-06 10:39:01 -06:00
Rene Rivera
5121fc11f9 Don't build numpy if there's no python version to target. 2017-03-06 10:30:41 -06:00
Rene Rivera
07b1489f3b BPL builds targets need to always be defined. 2017-03-05 15:17:26 -06:00
Rene Rivera
471e6181b2 BPL builds targets need to always be defined. 2017-03-05 15:16:36 -06:00
Rene Rivera
44ea0562b2 Fix no pynumpy target when no numpy configured. 2017-03-05 09:00:27 -06:00
Rene Rivera
60fba03e99 Fix libs from referencing BPL when there is no python configured. 2017-03-05 09:00:10 -06:00
Rene Rivera
398e7f02b8 Fix no pynumpy target when no numpy configured. 2017-03-05 08:56:57 -06:00
Rene Rivera
1e315242ce Fix libs from referencing BPL when there is no python configured. 2017-03-03 22:28:22 -06:00
al3xst
77ee91d5c5 Updated python library reference url
Due to changes on the python website, the url to the pickle library reference page was invalid.
2017-03-03 18:29:05 -05:00
Stefan Seefeld
e3c9dd78aa Merge branch 'develop' 2017-03-03 18:07:49 -05:00
Rene Rivera
e670de2795 Fix empty numpy lib name caused by missing parens for lib name map. 2017-03-02 21:55:49 -06:00
Rene Rivera
367b793ac9 Merge branch 'develop' of https://github.com/boostorg/python.git into develop 2017-03-01 10:15:47 -06:00
Rene Rivera
8c170d9193 Fix building of multiple BPL libs even when the configured python does
not match.
2017-03-01 10:15:37 -06:00
SPKorhonen
bd7b8ecba5 Fix for missing export symbols, issue #98 (#110)
Fix for missing export symbols in shared library of boost::python::numpy
2017-02-15 11:53:28 -05:00
Jürgen Hunold
0224f54ae0 Switch^Cisibility support to BOOST_SYMBOL_EXPORT. Refs #2114 2017-02-13 10:43:23 -05:00
Stefan Seefeld
d14b8cf411 Fix library dependency with Python 3. 2017-01-03 21:17:51 -05:00
Tadeu Manoel
4e0b96faa8 Fix conversion of PyUnicodeObject to wstring (#93) 2016-12-14 07:58:07 -05:00
Tadeu Manoel
7178a70176 Fix a problem where test_builtin_converters.py is not being run (#94)
This was happening because the module docstring was not the first statement.
2016-12-14 07:54:37 -05:00
Stefan Seefeld
aaf9022770 Merge branch 'develop' 2016-11-02 14:12:45 -04:00
Vladimir Prus
36bbdde2fe Use Boost-global python tagging. 2016-10-28 11:56:15 +03:00
Stefan Seefeld
1df6d84b80 Fix Python 3 incompatibility. 2016-10-27 08:37:25 -04:00
Stefan Seefeld
e968329174 Clean up examples. 2016-10-23 21:34:16 -04:00
Stefan Seefeld
07c8cbe652 Adjust to Boost.Build changes. 2016-10-23 21:27:31 -04:00
Stefan Seefeld
163e469bc4 Minor fixes. 2016-10-19 11:25:48 -04:00
Stefan Seefeld
ac39d2ed69 Fix doc build. 2016-10-19 07:34:34 -04:00
Stefan Seefeld
264f6ae4b9 Work around a sphinx bug. 2016-10-18 21:14:47 -04:00
Stefan Seefeld
84c96447e2 Add NumPy support to the BB-based build logic. 2016-10-18 16:32:05 -04:00
Stefan Seefeld
dc8d68d3fc Fix id clash in hierarchical tocs. 2016-10-16 20:30:15 -04:00
Stefan Seefeld
91512a971d More doc fine-tuning. 2016-10-10 14:22:57 -04:00
Rene Rivera
88ea1f9626 Fix syntax error caused by merging. 2016-10-10 12:22:25 -05:00
Rene Rivera
731ba745ca Add, and update, documentation build targets. 2016-10-10 12:22:10 -05:00
Stefan Seefeld
080eb55be6 Fine-tune documentation formatting. 2016-10-10 12:02:28 -04:00
Rene Rivera
a3d8223b5d Fix syntax error caused by merging. 2016-10-09 11:04:38 -05:00
Stefan Seefeld
b9431cd326 Remove obsolete tests from build logic. 2016-10-09 09:19:20 -04:00
Stefan Seefeld
2ccf54f091 Minor doc touch-ups. 2016-10-09 00:02:39 -04:00
Stefan Seefeld
4ce4821111 Remove obsolete tests. 2016-10-08 15:29:56 -04:00
Rene Rivera
69ddfcae17 Add, and update, documentation build targets. 2016-10-08 15:16:38 -04:00
Stefan Seefeld
3ace4a0015 Adjust NumPy code to work with new directory / namespace structure. 2016-10-08 13:34:17 -04:00
Stefan Seefeld
cbb3851488 Merge NumPy extension from https://github.com/ndarray/Boost.NumPy/. 2016-10-07 20:03:12 -04:00
Stefan Seefeld
127cc20a1d Install documentation for development branch separately. 2016-10-07 18:17:43 -04:00
Stefan Seefeld
482219f20a Remove a bunch of obsolete files. 2016-09-29 23:18:00 -04:00
Wei-Ming Yang
061050c006 Fix a mistake in str::count() 2016-09-29 08:09:30 -04:00
Wei-Ming Yang
03adaee6d2 Implement str::endswith() 2016-09-29 08:08:46 -04:00
WKarel
bc2f77a3db Assert refcount before decrement (#64)
Assert reference count before decrementing it.
2016-09-29 07:48:46 -04:00
vmurashev
aaf0d220ae tests for python3 - get rid of 'from past.builtins import long' 2016-09-28 22:44:46 -04:00
vmurashev
bb6f52dc35 test/exec.cpp - register builtin module before call 'Py_Initialize' 2016-09-28 22:44:46 -04:00
Stefan Seefeld
d422058fb4 Adjust BB logic to shared_ptr test changes. 2016-09-28 16:59:44 -04:00
Stefan Seefeld
a60ab14b91 Fix doc upload. 2016-09-28 13:37:15 -04:00
Stefan Seefeld
e0ee734161 Update credentials to upload generated docs. 2016-09-28 08:31:12 -04:00
Stefan Seefeld
444c948abe Fix doc upload. 2016-09-27 20:13:38 -04:00
Stefan Seefeld
97e4b34a15 Add support for std::shared_ptr. 2016-09-27 13:53:37 -04:00
Stefan Seefeld
5029273ca8 Use std::unique_ptr instead of std::auto_ptr 2016-09-22 20:30:33 -04:00
Stefan Seefeld
63e3079a16 Merge pull request #43 from Flast/patch-1
Fix a compile error with obsoleted details.
2016-09-01 00:13:48 -04:00
Stefan Seefeld
adfac2d139 Bump version number. 2016-08-29 09:38:20 -04:00
Stefan Seefeld
d79b59616b Add logic to detect and discriminate C++-11. 2016-08-29 09:33:26 -04:00
Stefan Seefeld
8a58f716ac Complete 'install' target. 2016-08-22 22:57:23 -04:00
Stefan Seefeld
f3931cfc38 Add README 2016-08-08 11:51:01 -04:00
Stefan Seefeld
b0f6414269 Fix CI build environment. 2016-08-06 20:13:33 -04:00
Stefan Seefeld
76708620cb Add Appveyor support. 2016-08-06 18:56:34 -04:00
Stefan Seefeld
b877b98fee Automate documentation updates. 2016-08-05 18:17:02 -04:00
Stefan Seefeld
94dfa4c762 Add support for building documentation. 2016-08-05 18:14:40 -04:00
Stefan Seefeld
5c723e96ea Merge pull request #77 from cowo78/develop
Multiple calling conventions with MSVC14/amd64
2016-07-21 07:59:14 -04:00
Giuseppe Corbelli
b49a186b6f Avoid multiple template instances of boost::python::details::get_signature when multiple calling conventions are enabled 2016-07-21 10:28:43 +02:00
Stefan Seefeld
a5a08bfb7b Fix Windows testing support. 2016-06-27 21:20:05 -04:00
Stefan Seefeld
e53a68defd Merge pull request #74 from cowo78/develop
Module 'past' is not available in 2.x interpreters
2016-06-27 08:46:36 -04:00
Giuseppe Corbelli
f0d5bef32d Merge branch 'develop' of https://github.com/boostorg/python into develop 2016-06-27 09:33:44 +02:00
Giuseppe Corbelli
e820537f3b past module is not available in v2 interpreters 2016-06-27 09:24:16 +02:00
Stefan Seefeld
c2d144ab71 Augment test matrix with C++11. 2016-06-26 07:54:37 -04:00
Stefan Seefeld
55f283bf18 Fix header search path order. 2016-06-26 07:54:05 -04:00
Stefan Seefeld
2e8cd3d8f2 Suppress more unused typedef warnings. 2016-06-24 17:22:17 -04:00
Stefan Seefeld
b3e9290599 Merge pull request #66 from thtrummer/develop
Fix unused local typedef warnings for GCC
2016-06-24 16:50:53 -04:00
Stefan Seefeld
07dd8eaa55 A few build system fixes. 2016-06-24 16:43:07 -04:00
Stefan Seefeld
81b3263743 Merge pull request #73 from cowo78/develop
/MACHINE option for x86 is /MACHINE:X86
2016-06-24 16:41:21 -04:00
Giuseppe Corbelli
7b7c4b85d5 /MACHINE option for x86 is /MACHINE:X86 2016-06-24 11:31:04 +02:00
Stefan Seefeld
f7d7c54173 Merge pull request #71 from jhunold/test_fix
Add missing .py suffix
2016-06-18 05:47:02 -04:00
Jürgen Hunold
68400823db Add missing .py suffix 2016-06-18 11:36:20 +02:00
Stefan Seefeld
905b34210b Make tests Py3-compatible 2016-06-18 00:00:22 -04:00
Stefan Seefeld
400f3db73a Add CI support. 2016-06-17 22:23:55 -04:00
Stefan Seefeld
57cd933240 Add SCons-based build system. 2016-06-17 22:23:47 -04:00
Thomas Trummer
f399391be2 Fix unused local typedef warnings for GCC 2016-05-01 12:10:04 +02:00
Stefan Seefeld
5233f45da4 Merge pull request #49 from fatso83/develop
Add cygwin64 support to wrap_python.hpp
2016-03-06 15:13:06 -05:00
Stefan Seefeld
63323f020f Fix a number of wrong / invalid links. 2016-03-06 14:07:23 -05:00
Stefan Seefeld
e9c265a84a Merge pull request #59 from vslashg/patch-1
Fix auto-pointer registration in Boost Python 1.60.
2016-03-06 12:58:40 -05:00
vslashg
f2c465ffa5 Fix auto-pointer registration in Boost Python 1.60.
The conditional instantiation magic of maybe_register_pointer_to_python() assumes that use_value_holder and use_back_reference will be one of the boost::mpl::bool_ types, but this assumption is no longer true in Boost 1.60, where they can be standard library bool wrappers instead.

Explicitly defining these types as mpl::bool_ classes fixes https://github.com/boostorg/python/issues/56.
2016-02-29 13:33:35 -05:00
Chris Nixon
77bdbf0432 Add cygwin64 support to wrap_python.hpp
This patch adds 64 bit support.
2015-12-09 22:54:28 +01:00
Jim Bosch
26aaa5b62e Merge pull request #51 from willyd/vscompat
Visual Studio compatibility fixes
2015-11-21 18:36:38 -05:00
Stefan Seefeld
359b7f0473 Merge pull request #37 from nevion/trace_registry
fix a static initialization fiasco with ios_base
2015-10-16 23:59:18 -04:00
Stefan Seefeld
52b268a8c6 Merge pull request #25 from eldiener/develop
Remove unused deprecated header file
2015-10-16 23:55:49 -04:00
Kohei Takahashi
e3aacc64fe Fix a compile error with obsoleted details.
Because boost/detail/iterator.hpp is now obsoleted, see boostorg/iterator@b2b9ab1568 .
2015-10-10 13:19:14 +09:00
Guillaume Dumont
f753f4bc30 Visual Studio compatibility fixes
Static linking fix
2015-09-16 10:18:23 -04:00
Jim Bosch
9e53eb2c23 Fix some confusing magic numbers in docs for stride (#50).
Documentation here needs a bigger cleanup than I can give it
right now, but this at least removes the ambiguity as to whether
"4" means the shape or sizeof(int).
2015-09-09 23:55:28 -04:00
Jim Bosch
6c2e3fb487 Update README and convert it to Markdown. 2015-09-09 23:48:55 -04:00
Jim Bosch
fcbba59630 Enable tests in CMake build and fix relative path problems.
As reported in #46, tests were not being built with CMake due
to a typo.  But they were also broken, because the relative path
to the dynamic library used in the link commands for the test
Python modules wasn't appropriate for running the tests from
the source directory.  Instead, we now copy the Python test
scripts to the build directory and run them there.
2015-09-09 23:27:40 -04:00
Jim Bosch
61a399e80a Remove const from rvalue returns (#42).
I'd originally thought this was a useful way to prevent no-op
assignments to rvalues, but compilers now check for that
without using const, and it was probably only non-standard
compiler behavior that ever made it useful.
2015-09-09 22:38:50 -04:00
Stefan Seefeld
42b06fa3a3 Merge pull request #40 from jwakely/issue-39
Python: Fix condition for make_setter overload.
2015-09-02 08:07:49 -04:00
Jonathan Wakely
f410fbd64d Python: Fix condition for make_setter overload.
This fixes the regression caused by 42e7d7b.

Fixes #39
2015-09-02 13:02:12 +01:00
Jason Newton
d18c7787e6 fix a static initialization fiasco with ios_base
see http://stackoverflow.com/questions/12318693/c-segmentation-fault-
when-using-cout-in-static-variable-initialization for a reference of
what was happening when iostreams were used within boost.python
registry's global static ctors.
2015-08-16 05:40:49 -07:00
Stefan Seefeld
5dce79445d Merge pull request #33 from danieljames/doc-build
Unset 'boost.defaults' set in Jamroot.
2015-08-13 03:23:38 -04:00
Daniel James
c41a1e8531 Unset 'boost.defaults' set in Jamroot.
Not using '<format>html' as it seems it has to match the original
setting exactly.
2015-08-12 22:42:01 +01:00
Stefan Seefeld
41c61dd756 Fix typo. 2015-08-05 11:27:48 -04:00
Edward Diener
0a4c76b9ac Remove unused deprecated header file 2015-05-29 18:36:39 -04:00
Jim Bosch
a0e849ed91 Switch from int to Py_intptr_t for shape/stride returns. 2015-01-18 10:00:42 -05:00
Christoph Lassner
4dbb2784ee Removed unnecessary defaults. 2015-01-17 14:06:22 -05:00
Christoph Lassner
4d9ab505b0 Updated build system behaviour and comments for the --with-boost option. 2015-01-17 14:06:00 -05:00
Jim Bosch
3494381c01 Resolve dtype equivalence issue in MSVC 2014-11-23 12:39:57 -05:00
Christoph Lassner
bc13c4c600 Fixed unsigned long test error. 2014-11-23 12:39:57 -05:00
Christoph Lassner
73b8350e53 Switch SCons to use SConsChecks submodule for Windows support 2014-11-23 12:39:52 -05:00
Jim Bosch
c509a3ab01 Merge pull request #39 from termoshtt/cmake_python3
(with minor modification from Jim Bosch)
2014-11-23 12:05:52 -05:00
Toshiki Teramura
4c2070f39f Revise example/wrap.cpp for python3 2014-11-23 12:03:58 -05:00
Toshiki Teramura
e2c23fd5f9 Append python version detector
Slight modifications from Jim Bosch for more standard language in
build system language.
2014-11-23 12:03:15 -05:00
Jim Bosch
7ff5465e7d Merge pull request #36 from ChrislS/master
SCons change to build a static lib for Windows
2014-09-25 20:19:38 -04:00
Christoph Lassner
e747cc9422 * SCons change to build a static lib for Windows. 2014-09-25 18:25:05 +02:00
Jim Bosch
b46ccc4f51 Merge pull request #35 from karlssonper/master
Examples and tests optional to build in CMake
2014-08-26 14:12:02 -04:00
per
be72aab254 Examples and tests are now optional to build. The default behavior is the same as before where both are built. 2014-08-18 11:28:53 +02:00
Jim Bosch
5035f6e801 Merge pull request #34 from karlssonper/master
added the NPY_FLOAT16 dtype
2014-08-04 15:10:44 -06:00
Per
0b549aee88 added the NPY_FLOAT16 dtype 2014-08-04 16:38:02 +02:00
Jim Bosch
bf73da1bce Merge pull request #31 from nbecker/master
SCons build system updates to support Python 3
2014-06-02 21:52:21 -04:00
Neal D. Becker
ca8ce585b7 Use equivalent, but doesn't seem to help 2014-06-02 09:40:28 -04:00
Neal D. Becker
81551cf6b6 port to py3 2014-06-02 09:40:00 -04:00
Jim Bosch
e3bf3c6f51 Merge pull request #29 from coroa/master
cmake: switch from using deprecated linklibraries to target_linklibraries
2013-10-10 15:46:08 -07:00
Jonas Hoersch
c8798676f6 cmake: switch from using deprecated linklibraries to target_linklibraries
the total information duplication actually decreases and it
facilitates reusing CMake instructions from outer projects.
2013-10-06 20:03:51 +02:00
Jim Bosch
c9974daec2 Avoid Python 3 compile warnings in NumPy initialization 2013-08-24 18:08:01 -04:00
Jim Bosch
b46dfd9064 Qualify calls to template member functions in invoke_matching.
This is necessary to avoid a bug in which a template struct from another
namespace can be confused with the member function by the parser
(see gcc bug 55576; it's apparently a defect in the C++98 standard).
2013-03-19 11:38:08 -04:00
Jim Bosch
956606ef0c Update README to mention CMake build system. 2013-03-15 23:08:40 -04:00
Philip Miller
0b59058fa2 Add cmake build system, fix examples for Windows compatibility. 2013-03-15 23:08:16 -04:00
Jim Bosch
2a41c80c58 Fix embedding issues with statically-compiled Python, at least on Linux. Use LINKFLAGS instead of LDFLAGS (see also #23; patch from Luc Bourhis) 2013-03-07 09:41:10 -05:00
Jim Bosch
42a57978ee Merge pull request #17 from awishnick/master
Added astype to ndarray
2013-01-18 13:46:42 -08:00
Aaron Wishnick
4b99e6b83f Add astype to ndarray. 2013-01-11 15:16:29 -05:00
Jim Bosch
49b536fbd3 replace non-constant array sizes with scoped_array 2012-12-10 23:32:08 -05:00
Jim Bosch
2e47285fb5 Add license file and license header to source files. 2012-09-26 00:33:10 -04:00
Jim Bosch
45b588b85a Merge pull request #12 from barnabyrobson/patch-1
Update SConscript to print the correct message when Boost.Python config test cannot be run.
2012-09-25 20:14:19 -07:00
barnabyrobson
cce7dfcf17 Update SConscript
Fixing copy and pasted comment to say correct thing when program built against Boost.Python can not run.
2012-09-22 20:13:20 -07:00
Jim Bosch
2f7742ffec add more permissive equivalence test for dtypes, start using it in tests 2012-09-18 23:13:29 -04:00
Ilya Kolpakov
46b959cceb ufunc tests now ensure that return value is the same object as the 'output' (if it is provided) argument being the same object as the ufunc return value 2012-09-04 12:10:55 +02:00
Ilya Kolpakov
ca3526c76a ufunc test now uses assert_array_almost_equal instead of bitwise(?) comparison 2012-09-04 11:30:58 +02:00
Jim Bosch
4ec94c676b Add example (wrap.py) to demonstrate how to wrap simple functions that operate on C arrays into functions that operate on NumPy arrays (#6). 2012-05-13 17:51:48 -04:00
Jim Bosch
a35cbd1af1 Switch to use RPATH in test and example builds (#5). 2012-05-13 17:50:15 -04:00
Jim Bosch
28a9fab278 Overhauled how builtin dtype objects are accessed for better consistency, added converters for array scalars. 2012-05-13 13:03:10 -04:00
Jim Bosch
ab2225bcbd Remove unused special handling for bool dtype. 2012-05-12 12:15:32 -04:00
Jim Bosch
dbe4903887 fix LoadableModule suffix on darwin 2012-04-29 12:55:57 -04:00
Jim Bosch
405f99cd3c Fix bug in boost/numpy.hpp install location 2012-04-28 15:47:48 -04:00
Jim Bosch
313dcbb628 added as_matrix call policy 2012-04-21 16:46:28 -04:00
Jim Bosch
dca44829a6 untabify python test files 2012-04-21 16:34:01 -04:00
Jim Bosch
46f6382fe4 Change how external environment variables are propagated to SCons to allow it to find executables in $PATH. 2012-04-21 15:14:29 -04:00
Jim Bosch
99e6194620 more SCons refactoring 2012-04-21 00:50:53 -04:00
Jim Bosch
4c2850cbfd Make CheckLibs available to ndarray SConstruct file. 2012-04-19 23:28:41 -04:00
Jim Bosch
029eb385ed Prepend Boost paths rather than append them; puts explicit paths at a higher priority than paths pulled from distutils (patch from Neal Becker). 2012-04-17 23:03:58 -04:00
Jim Bosch
77b89341d0 Added support for specifying installation directories for headers and libraries separately (modified patch from Neal Becker).
Signed-off-by: Jim Bosch <jbosch@astro.princeton.edu>
2012-04-17 22:53:06 -04:00
Jim Bosch
588027252b Remove unnecessary shared_ptr in class_ for ufuncs (from Neal Becker).
Signed-off-by: Jim Bosch <jbosch@astro.princeton.edu>
2012-04-17 22:01:39 -04:00
Jim Bosch
d61d41a786 allow CCFLAGS to be passed on command line or through construction variable; default is now '-O2 -g' 2012-04-17 10:00:36 -04:00
Jim Bosch
1d3a535e53 switch to using LoadableModule instead of SharedLibrary for test Python modules 2012-04-16 23:58:34 -04:00
Jim Bosch
65dc91f3da add bang lines to Python unit test scripts 2012-04-16 23:50:46 -04:00
Jim Bosch
782ca7bf20 add custom rpath option to SCons builds 2012-04-16 23:43:57 -04:00
Jim Bosch
1a5a3e1701 modifications to SCons build system to be friendlier to ndarray 2012-04-16 00:53:38 -04:00
Jim Bosch
00c61f4767 fix GitHub URL in readme 2012-04-11 20:18:38 -04:00
Jim Bosch
c20af50ae3 added README file 2012-04-11 20:17:18 -04:00
Jim Bosch
38e68fa2ae overhauled scons scripts 2012-03-18 18:57:14 -04:00
Jim Bosch
35a62fea52 added .gitignore 2012-03-18 17:09:13 -04:00
Jim Bosch
b219376e24 fixed header order in gaussian example; Python.h should always come before system headers 2012-03-18 17:05:22 -04:00
Jim Bosch
1e66e33201 removed ublas dependency from gaussian example 2011-11-08 03:45:31 +00:00
Stefan Seefeld
8f909d55ac Refine style. 2011-10-31 22:56:38 +00:00
Stefan Seefeld
05c21bcae1 Refine style. 2011-10-31 22:55:22 +00:00
Stefan Seefeld
0cb3bd7aa5 Add navigation bar. 2011-10-30 22:25:34 +00:00
Stefan Seefeld
7a84a00673 build new 'gaussian.cpp' extension. 2011-10-30 20:54:20 +00:00
Jim Bosch
9d7dfd8449 added gaussian example, updated scons build 2011-10-30 14:43:53 +00:00
Stefan Seefeld
2a8823f745 Fix formatting issues in the Reference Manual. 2011-10-29 20:39:37 +00:00
Stefan Seefeld
beaa4b0e4d Remove implementation details from documentation. 2011-10-29 18:20:25 +00:00
Stefan Seefeld
55c3b0569e Restructure documentation sources to build with sphinx. 2011-10-27 14:12:14 +00:00
Ankit Daftery
2aca81bca9 Added temporary directory for Reference documentation 2011-08-31 12:35:56 +00:00
Jim Bosch
32d2135462 boost/numpy - enabled new unit tests in old SCons build system 2011-08-25 23:32:43 +00:00
Ankit Daftery
7064cf3186 Added tutorial for ufunc 2011-08-17 18:26:20 +00:00
Ankit Daftery
777e16e1d0 Added example for ufunc 2011-08-17 18:25:44 +00:00
Ankit Daftery
715e5cbc31 Added non-unit strides example 2011-08-14 06:49:08 +00:00
Ankit Daftery
67b5b07976 Added non-unit strides example 2011-08-14 06:48:46 +00:00
Ankit Daftery
7b088c9df2 Removed todo 2011-08-13 13:55:03 +00:00
Ankit Daftery
3dda62f8b8 Added tutorial for fromdata, i.e. copy free data access 2011-08-12 09:26:55 +00:00
Ankit Daftery
c33460c265 Made a few modifications 2011-08-12 09:26:22 +00:00
Ankit Daftery
4c12b004ec Added example for data access using pointers 2011-08-12 05:16:20 +00:00
Ankit Daftery
5bed132ff8 Added a line for zeros 2011-08-08 17:05:09 +00:00
Ankit Daftery
3ffcf3335a Added working custom dtype example 2011-08-06 21:13:13 +00:00
Ankit Daftery
c314274a56 Added working custom dtype exampel 2011-08-06 21:12:42 +00:00
Ankit Daftery
437373456f Added example for custom dtype 2011-08-05 17:04:29 +00:00
Ankit Daftery
7add755ae0 Added tutorial for dtype 2011-08-05 09:06:19 +00:00
Ankit Daftery
79182d7189 Added ndarray.rst 2011-08-04 17:47:09 +00:00
Ankit Daftery
36e9e38373 Tutorial for ndarrays 2011-08-04 17:45:00 +00:00
Ankit Daftery
45e52301e9 Added from_data implementation, zeros(..) examples 2011-08-04 17:39:04 +00:00
Ankit Daftery
37a73f344b Modified Jamfile 2011-08-03 20:07:40 +00:00
Ankit Daftery
bbd9aad6e9 New examples 2011-08-03 20:07:20 +00:00
Stefan Seefeld
8fa1f9db9e Add support for ReST docs. 2011-07-19 04:32:25 +00:00
Stefan Seefeld
9c56469358 Add example(s) 2011-07-05 14:20:57 +00:00
Stefan Seefeld
196c9e653f Fix indexing tests. 2011-07-03 20:36:55 +00:00
Stefan Seefeld
c572b4db73 Rename (and move) boost.python.numpy to boost.numpy. 2011-07-03 16:42:15 +00:00
Stefan Seefeld
b2519a25a9 Rename (and move) boost.python.numpy to boost.numpy. 2011-07-03 16:40:30 +00:00
Ankit Daftery
2979e4b062 Added index array and boolean tests 2011-06-30 02:50:40 +00:00
Stefan Seefeld
88dd5330d0 Tidy indexing tests. 2011-06-27 14:07:54 +00:00
Ankit Daftery
fa51b58cd6 Added test for slices with steps. Auto-detection of step not implemented yet 2011-06-27 04:09:12 +00:00
Ankit Daftery
419b6ec973 Added tests for indexing 2011-06-24 12:58:57 +00:00
Ankit Daftery
085f574d6e Added more tests for ndarray 2011-06-20 17:18:43 +00:00
Stefan Seefeld
69d9f34f3e Fix ndarray tests. 2011-06-19 20:16:06 +00:00
Stefan Seefeld
36ee7d23f9 Fix ndarray tests. 2011-06-19 20:08:48 +00:00
Ankit Daftery
b269b4b124 Adding test for ndarray.Fails as of now. 2011-06-19 19:38:51 +00:00
Ankit Daftery
20b68f2a2f Added build rule for shapes 2011-06-14 03:36:59 +00:00
Ankit Daftery
2794a9bd15 Test to check the shape of the ndarray 2011-06-14 03:32:10 +00:00
Stefan Seefeld
0a76801936 Move build system improvements 2011-05-30 20:39:43 +00:00
Stefan Seefeld
daf466a697 Work on numpy configuration 2011-05-30 01:18:16 +00:00
Ankit Daftery
718cfd468e First build of numpy.jam module to check for the location of the numpy build directory 2011-05-29 18:39:06 +00:00
Ankit Daftery
3796825523 Updated to include the numpy.jam module 2011-05-29 18:34:21 +00:00
Ankit Daftery
6904a166f7 Updated to include the numpy.jam module 2011-05-29 18:33:56 +00:00
Ankit Daftery
39b9047190 New addition to support boost.build 2011-05-28 12:53:03 +00:00
Ankit Daftery
930167e961 New addition to support boost.build 2011-05-28 12:52:29 +00:00
Ankit Daftery
64b2c1697b Patch to fix scons issue 2011-05-28 12:47:37 +00:00
Ankit Daftery
f0345b2521 New addition to support boost.build 2011-05-28 12:45:52 +00:00
Jim Bosch
77ec571511 Boost.Python.Numpy - moved convenience header one directory lower 2011-02-16 00:24:22 +00:00
Jim Bosch
70c7fbd1d8 Boost.Python.Numpy - removing malfunctioning variant build directories 2011-01-17 20:01:48 +00:00
Jim Bosch
91a1119070 Boost.Python.Numpy - cleaning up build system 2011-01-15 23:00:43 +00:00
Jim Bosch
a300f7cdd0 boost.python.numpy - updates to build system, added some svn:ignores 2011-01-07 23:39:45 +00:00
Jim Bosch
65db10061f numpy - (build system) fixed setting lib output path in tests 2011-01-06 19:37:28 +00:00
Jim Bosch
3d7f523384 numpy - added missing doxygen builder 2011-01-06 19:30:58 +00:00
Jim Bosch
252c3aa695 numpy - updates to site_scons, header documentation 2011-01-04 19:19:20 +00:00
Jim Bosch
584df88fb2 boost.python.numpy - switched to simpler syntax for invoke_matching_array 2010-10-06 22:40:41 +00:00
Jim Bosch
ba1416fff0 boost.python.numpy - moved dtype::invoke_matching_template into separate header, added similar code for invocation based on dimensionality 2010-10-06 19:05:20 +00:00
Jim Bosch
42ca807c82 boost.python.numpy - fixed missing bool instantiation for dtype::get_builtin 2010-10-06 00:31:09 +00:00
Jim Bosch
b988e8c45f boost.python.numpy - adding missing symbols, fixed constness in dtype 2010-07-25 00:18:18 +00:00
Jim Bosch
c7db44f617 boost.python.numpy - added ndarray::reshape 2010-06-29 07:55:33 +00:00
Jim Bosch
f3aecdf2f4 boost.python.numpy - added dtype template invoker 2010-06-24 22:20:55 +00:00
Jim Bosch
40bd0326f3 boost.python numpy - build system separates debug and standard builds 2010-06-08 01:44:59 +00:00
Jim Bosch
99d3a54ad5 boost.python numpy support - improvements to build system 2010-05-18 06:59:41 +00:00
Jim Bosch
c3d186e0bf boost python numpy extensions - updated source files to reflect previous header move 2010-05-15 03:44:45 +00:00
Jim Bosch
e0fa8ec619 numpy python extensions - moved main header file inside subdirectory 2010-05-14 23:43:38 +00:00
Jim Bosch
e2b2ebe862 numpy python extension - added basic SCons build system, started on unit tests 2010-05-14 22:47:14 +00:00
Jim Bosch
eef2eef7dd initial sandbox import for numpy utilities in boost.python 2010-03-08 21:50:13 +00:00
Jim Bosch
189915bc8b folder for new numpy project: improved boost.python bindings for numpy 2010-03-08 20:12:06 +00:00
1276 changed files with 56869 additions and 132117 deletions

7
.ci/faber Normal file
View File

@@ -0,0 +1,7 @@
# -*- python -*-
from faber.tools.boost import boostbook
from faber.tools.python import python
bb = boostbook(prefix='/usr/share/boostbook')
p = python(command='$PYTHON')

View File

@@ -0,0 +1,37 @@
name: deploy documentation
on: [push]
jobs:
deploy:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- name: setup
run: |
sudo apt-get update
sudo apt-get install \
libboost-tools-dev \
python3 \
python3-numpy \
python3-sphinx \
xsltproc \
docbook-xsl
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install faber
- name: build
run: |
sed -e "s/\$PYTHON/python3/g" .ci/faber > ~/.faber
faber --builddir=build doc.html
if [ "${GITHUB_REF##*/}" == master ]; then
echo "destination_dir=doc/html" >> $GITHUB_ENV
else
echo "destination_dir=doc/develop/html" >> $GITHUB_ENV
fi
- name: deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: build/doc/html
destination_dir: ${{ env.destination_dir }}
keep_files: true

50
.github/workflows/test-osx.yml vendored Normal file
View File

@@ -0,0 +1,50 @@
name: Test OSX
on: [push, pull_request]
jobs:
build:
runs-on: macOS-latest
strategy:
fail-fast: false
matrix:
python-version: [3.8.10]
cxx: [clang++]
std: [c++11, c++14] # TODO: c++17 is failing !
steps:
- uses: actions/checkout@v5
- name: setup python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: setup prerequisites
run: |
brew install boost
python -m pip install --upgrade pip
python -m pip install setuptools faber
- name: build
run: |
python --version
${{ matrix.cxx }} --version
brew info boost
faber -v
sed -e "s/\$PYTHON/python/g" .ci/faber > ~/.faber
faber \
--with-boost-include=$(brew --prefix boost)/include \
--builddir=build \
cxx.name=${{ matrix.cxx }} \
cxxflags=-std=${{ matrix.std }} \
cppflags=-std=${{ matrix.std }} \
-j`sysctl -n hw.ncpu`
- name: test
run: |
faber \
--with-boost-include=$(brew --prefix boost)/include \
--builddir=build\
cxx.name=${{ matrix.cxx }} \
cxxflags=-std=${{ matrix.std }} \
cppflags=-std=${{ matrix.std }} \
-j`sysctl -n hw.ncpu` \
test.report

57
.github/workflows/test-ubuntu.yml vendored Normal file
View File

@@ -0,0 +1,57 @@
name: Test Ubuntu
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: [python, python3]
cxx: [g++, clang++]
std: [c++11, c++14, c++17]
include:
# Add the appropriate docker image for each compiler.
# The images from teeks99/boost-python-test already have boost::python
# pre-reqs installed, see:
# https://github.com/teeks99/boost-python-test-docker
- cxx: clang++
docker-img: teeks99/boost-python-test:clang-21_1.89.0
- cxx: g++
docker-img: teeks99/boost-python-test:gcc-15_1.89.0
container:
image: ${{ matrix.docker-img }}
steps:
- uses: actions/checkout@v5
- name: setup prerequisites
run: |
# Warning: this is not necessarily the same Python version as the one configured above !
python3 -m pip install -U faber --break-system-packages
- name: build
run: |
${{ matrix.python }} --version
${{ matrix.cxx }} --version
faber -v
sed -e "s/\$PYTHON/${{ matrix.python }}/g" .ci/faber > ~/.faber
faber \
--with-boost-include=${BOOST_PY_DEPS} \
--builddir=build \
cxx.name=${{ matrix.cxx }} \
cxxflags=-std=${{ matrix.std }} \
cppflags=-std=${{ matrix.std }} \
-j`nproc`
- name: test
run: |
faber \
--with-boost-include=${BOOST_PY_DEPS} \
--builddir=build \
cxx.name=${{ matrix.cxx }} \
cxxflags=-std=${{ matrix.std }} \
cppflags=-std=${{ matrix.std }} \
-j`nproc` \
test.report

49
.github/workflows/test-windows.yml vendored Normal file
View File

@@ -0,0 +1,49 @@
name: Test Windows
on: [push, pull_request]
jobs:
build:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: [3.7]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- uses: microsoft/setup-msbuild@v2
- name: setup boost prerequisites
uses: lukka/run-vcpkg@v6
with:
vcpkgGitCommitId: '88b1071e39f13b632644d9d953738d345a4ac055'
vcpkgDirectory: '${{ runner.workspace }}/vcpkg'
vcpkgTriplet: x64-windows
vcpkgArguments: >
boost-config
boost-core
boost-function
boost-graph
boost-iterator
boost-lexical-cast
boost-mpl
boost-preprocessor
boost-smart-ptr
boost-static-assert
boost-align
- name: setup faber
run: |
python -m pip install --upgrade pip
python -m pip install setuptools faber numpy
faber --info=tools cxx
- name: build
shell: cmd
run: |
faber --builddir=build cxx.name=msvc --log=commands --log=output --with-boost-include=${{ runner.workspace }}\vcpkg\installed\x64-windows\include -j4
- name: test
shell: cmd
run: |
faber --builddir=build cxx.name=msvc --with-boost-include=${{ runner.workspace }}\vcpkg\installed\x64-windows\include -j4 test.report

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
bin.SCons
*.pyc
*~
\#*\#

View File

176
CMakeLists.txt Normal file
View File

@@ -0,0 +1,176 @@
# Copyright 2020, 2021 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.14...3.20)
project(boost_python VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
find_package(Python REQUIRED COMPONENTS Development OPTIONAL_COMPONENTS NumPy)
if(Python_NumPy_FOUND)
message(STATUS "Boost.Python: using Python ${Python_VERSION} with NumPy at ${Python_NumPy_INCLUDE_DIRS}")
else()
message(STATUS "Boost.Python: using Python ${Python_VERSION} without NumPy")
endif()
# boost_pythonXY
set(_pyver ${Python_VERSION_MAJOR}${Python_VERSION_MINOR})
set(_boost_python boost_python${_pyver})
add_library(${_boost_python}
src/dict.cpp
src/errors.cpp
src/exec.cpp
src/import.cpp
src/list.cpp
src/long.cpp
src/module.cpp
src/object_operators.cpp
src/object_protocol.cpp
src/slice.cpp
src/str.cpp
src/tuple.cpp
src/wrapper.cpp
src/converter/from_python.cpp
src/converter/registry.cpp
src/converter/type_id.cpp
src/converter/builtin_converters.cpp
src/converter/arg_to_python_base.cpp
src/object/enum.cpp
src/object/class.cpp
src/object/function.cpp
src/object/inheritance.cpp
src/object/life_support.cpp
src/object/pickle_support.cpp
src/object/iterator.cpp
src/object/stl_iterator.cpp
src/object_protocol.cpp
src/object_operators.cpp
src/object/function_doc_signature.cpp
)
add_library(Boost::python${_pyver} ALIAS ${_boost_python})
target_include_directories(${_boost_python} PUBLIC include)
target_link_libraries(${_boost_python}
PUBLIC
Boost::align
Boost::bind
Boost::config
Boost::conversion
Boost::core
Boost::detail
Boost::foreach
Boost::function
Boost::iterator
Boost::lexical_cast
Boost::mpl
Boost::numeric_conversion
Boost::preprocessor
Boost::smart_ptr
Boost::static_assert
Boost::tuple
Boost::type_traits
Boost::utility
Python::Module
PRIVATE
Boost::graph
Boost::integer
Boost::property_map
)
target_compile_definitions(${_boost_python}
PUBLIC BOOST_PYTHON_NO_LIB
PRIVATE BOOST_PYTHON_SOURCE
)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${_boost_python} PUBLIC BOOST_PYTHON_DYN_LINK)
else()
target_compile_definitions(${_boost_python} PUBLIC BOOST_PYTHON_STATIC_LINK BOOST_PYTHON_STATIC_LIB)
endif()
# Boost::python alias
add_library(boost_python INTERFACE)
add_library(Boost::python ALIAS boost_python)
target_link_libraries(boost_python INTERFACE Boost::python${_pyver})
# Installation
if(BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13)
boost_install(TARGETS ${_boost_python} boost_python VERSION ${BOOST_SUPERPROJECT_VERSION} HEADER_DIRECTORY include)
endif()
if(Python_NumPy_FOUND)
# boost_numpyXY
set(_boost_numpy boost_numpy${_pyver})
add_library(${_boost_numpy}
src/numpy/dtype.cpp
src/numpy/matrix.cpp
src/numpy/ndarray.cpp
src/numpy/numpy.cpp
src/numpy/scalars.cpp
src/numpy/ufunc.cpp
)
add_library(Boost::numpy${_pyver} ALIAS ${_boost_numpy})
target_include_directories(${_boost_numpy} PUBLIC include)
target_link_libraries(${_boost_numpy}
PUBLIC
Boost::config
Boost::core
Boost::detail
Boost::mpl
Boost::python
Boost::smart_ptr
Python::NumPy
)
target_compile_definitions(${_boost_numpy}
PUBLIC BOOST_NUMPY_NO_LIB
PRIVATE BOOST_NUMPY_SOURCE
)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${_boost_numpy} PUBLIC BOOST_NUMPY_DYN_LINK)
else()
target_compile_definitions(${_boost_numpy} PUBLIC BOOST_NUMPY_STATIC_LINK BOOST_NUMPY_STATIC_LIB)
endif()
# Boost::numpy alias
add_library(boost_numpy INTERFACE)
add_library(Boost::numpy ALIAS boost_numpy)
target_link_libraries(boost_numpy INTERFACE Boost::numpy${_pyver})
# Installation
if(BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13)
boost_install(TARGETS ${_boost_numpy} boost_numpy VERSION ${BOOST_SUPERPROJECT_VERSION})
endif()
endif()
unset(_pyver)
unset(_boost_python)
unset(_boost_numpy)
# Testing
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()

23
LICENSE_1_0.txt Normal file
View File

@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

59
README.md Normal file
View File

@@ -0,0 +1,59 @@
![logo](https://raw.githubusercontent.com/boostorg/python/develop/doc/images/bpl.png)
# Synopsis
[![Join the chat at https://gitter.im/boostorg/python](https://badges.gitter.im/boostorg/python.svg)](https://gitter.im/boostorg/python?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Welcome to Boost.Python, a C++ library which enables seamless interoperability between C++ and the Python programming language. The library includes support for:
* References and Pointers
* Globally Registered Type Coercions
* Automatic Cross-Module Type Conversions
* Efficient Function Overloading
* C++ to Python Exception Translation
* Default Arguments
* Keyword Arguments
* Manipulating Python objects in C++
* Exporting C++ Iterators as Python Iterators
* Documentation Strings
See the [Boost.Python](http://boostorg.github.io/python) documentation for details.
**Hint :** Check out the [development version](http://boostorg.github.io/python/develop) of the documentation to see work in progress.
# Building ![Test Ubuntu](https://github.com/boostorg/python/workflows/Test%20Ubuntu/badge.svg) ![Test OSX](https://github.com/boostorg/python/workflows/Test%20OSX/badge.svg) ![Test Windows](https://github.com/boostorg/python/workflows/Test%20Windows/badge.svg)
While Boost.Python is part of the Boost C++ Libraries super-project, and thus can be compiled as part of Boost, it can also be compiled and installed stand-alone, i.e. against a pre-installed Boost package.
## Prerequisites
* [Python](http://www.python.org)
* [Boost](http://www.boost.org)
* [Faber](https://stefanseefeld.github.io/faber)
## Build
Run
```
faber
```
to build the library.
## Test
Run
```
faber test.report
```
to run the tests.
## Build docs
Run
```
faber doc.html
```
to build the documentation.

41
build.jam Normal file
View File

@@ -0,0 +1,41 @@
# Copyright René Ferdinand Rivera Morell 2024
# 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)
require-b2 5.2 ;
constant boost_dependencies :
/boost/align//boost_align
/boost/bind//boost_bind
/boost/config//boost_config
/boost/conversion//boost_conversion
/boost/core//boost_core
/boost/detail//boost_detail
/boost/foreach//boost_foreach
/boost/function//boost_function
/boost/iterator//boost_iterator
/boost/lexical_cast//boost_lexical_cast
/boost/mpl//boost_mpl
/boost/numeric_conversion//boost_numeric_conversion
/boost/preprocessor//boost_preprocessor
/boost/static_assert//boost_static_assert
/boost/tuple//boost_tuple
/boost/type_traits//boost_type_traits
/boost/utility//boost_utility ;
project /boost/python
: common-requirements
<include>include
;
explicit
[ alias boost_python : build//boost_python ]
[ alias boost_numpy : build//boost_numpy ]
[ alias all : boost_python boost_numpy test ]
;
call-if : boost-library python
: install boost_python boost_numpy
;

175
build/Jamfile Normal file
View File

@@ -0,0 +1,175 @@
# Copyright David Abrahams 2001-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 os ;
import indirect ;
import modules ;
import feature ;
import property ;
import python ;
if ! [ python.configured ] && ! ( --without-python in [ modules.peek : ARGV ] )
{
# Attempt default configuration of python
import toolset : using ;
using python ;
}
if [ python.configured ] || ( --without-python in [ modules.peek : ARGV ] )
{
alias config-warning ;
}
else
{
message config-warning
: "warning: No python installation configured and autoconfiguration"
: "note: failed. See http://www.boost.org/libs/python/doc/building.html"
: "note: for configuration instructions or pass --without-python to"
: "note: suppress this message and silently skip all Boost.Python targets"
;
}
constant boost_dependencies_private :
/boost/graph//boost_graph
/boost/integer//boost_integer
/boost/property_map//boost_property_map
/boost/smart_ptr//boost_smart_ptr
;
project
: source-location ../src
: common-requirements <library>$(boost_dependencies)
: requirements <library>$(boost_dependencies_private)
;
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 tag ( name : type ? : property-set )
{
if python-tag in [ RULENAMES $(__name__) ]
{
return [ $(__name__).python-tag $(name) : $(type) : $(property-set) ] ;
}
}
if [ python.configured ]
{
lib boost_python
: # sources
list.cpp
long.cpp
dict.cpp
tuple.cpp
str.cpp
slice.cpp
converter/from_python.cpp
converter/registry.cpp
converter/type_id.cpp
object/enum.cpp
object/class.cpp
object/function.cpp
object/inheritance.cpp
object/life_support.cpp
object/pickle_support.cpp
errors.cpp
module.cpp
converter/builtin_converters.cpp
converter/arg_to_python_base.cpp
object/iterator.cpp
object/stl_iterator.cpp
object_protocol.cpp
object_operators.cpp
wrapper.cpp
import.cpp
exec.cpp
object/function_doc_signature.cpp
: # requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<define>BOOST_PYTHON_SOURCE
# On Windows, all code using Python has to link to the Python
# import library.
#
# On *nix we never link libboost_python to libpython. When
# extending Python, all Python symbols are provided by the
# Python interpreter executable. When embedding Python, the
# client executable is expected to explicitly link to
# /python//python (the target representing libpython) itself.
#
# python_for_extensions is a target defined by Boost.Build to
# provide the Python include paths, and on Windows, the Python
# import library, as usage requirements.
[ cond [ python.configured ] : <library>/python//python_for_extensions ]
# we prevent building when there is no python available
# as it's not possible anyway, and to cause dependents to
# fail to build
[ unless [ python.configured ] : <build>no ]
<dependency>config-warning
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
-<tag>@%boostcpp.tag
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
<tag>@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
<define>BOOST_PYTHON_NO_LIB
;
}
else
{
alias boost_python : config-warning ;
}
if [ python.configured ] && [ python.numpy ]
{
numpy-include = [ python.numpy-include ] ;
lib boost_numpy
: # 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 ]
<library>/python//numpy
<library>boost_python
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
-<tag>@%boostcpp.tag
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
<tag>@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
<define>BOOST_NUMPY_NO_LIB
;
}
else
{
alias boost_numpy : config-warning ;
}

View File

@@ -1,31 +0,0 @@
index.html
rn.html
building.html
building/background.html
building/no_install_quickstart.html
building/installing_boost_python_on_your_.html
building/configuring_boost_build.html
building/choosing_a_boost_python_library_.html
building/include_issues.html
building/python_debugging_builds.html
building/testing_boost_python.html
building/notes_for_mingw_and_cygwin_with_.html
configuration.html
support.html
faq.html
faq/i_m_getting_the_attempt_to_retur.html
faq/is_return_internal_reference_eff.html
faq/how_can_i_wrap_functions_which_t.html
faq/fatal_error_c1204_compiler_limit.html
faq/how_do_i_debug_my_python_extensi.html
faq/why_doesn_t_my_operator_work.html
faq/does_boost_python_work_with_mac_.html
faq/how_can_i_find_the_existing_pyob.html
faq/how_can_i_wrap_a_function_which0.html
faq/compilation_takes_too_much_time_.html
faq/how_do_i_create_sub_packages_usi.html
faq/error_c2064_term_does_not_evalua.html
faq/how_can_i_automatically_convert_.html
faq/why_is_my_automatic_to_python_co.html
faq/is_boost_python_thread_aware_com.html
glossary.html

File diff suppressed because it is too large Load Diff

View File

@@ -1,61 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;2.&#160;Building and Testing</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Boost.Python">
<link rel="up" href="index.html" title="Boost.Python">
<link rel="prev" href="rn.html" title="Chapter&#160;1.&#160;Release Notes">
<link rel="next" href="building/background.html" title="Background">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="rn.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="building/background.html"><img src="images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div>
<div><h1 class="title">
<a name="building"></a>Chapter&#160;2.&#160;Building and Testing</h1></div>
<div><div class="authorgroup"><div class="author"><h3 class="author">
<span class="firstname">David</span> <span class="surname">Abrahams</span>
</h3></div></div></div>
<div><p class="copyright">Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld</p></div>
</div></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.requirements"></a><a class="link" href="building.html#building.requirements" title="Requirements">Requirements</a>
</h3></div></div></div>
<p>
Boost.Python requires <a href="http://www.python.org/2.2" target="_top">Python 2.2</a>
<a href="#ftn.building.requirements.f0" class="footnote" name="building.requirements.f0"><sup class="footnote">[1]</sup></a> <span class="bold"><strong>or</strong></span> <a href="http://www.python.org" target="_top">newer</a>.
</p>
</div>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.building.requirements.f0" class="footnote"><p><a href="#building.requirements.f0" class="para"><sup class="para">[1] </sup></a>
Note that although we tested earlier versions of Boost.Python with Python
2.2, and we don't <span class="bold"><strong>think</strong></span> we've done anything
to break compatibility, this release of Boost.Python may not have been
tested with versions of Python earlier than 2.4, so we're not 100% sure
that python 2.2 and 2.3 are supported.
</p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="rn.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="building/background.html"><img src="images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,70 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Background</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="next" href="no_install_quickstart.html" title="No-Install Quickstart">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../building.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="no_install_quickstart.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.background"></a><a class="link" href="background.html" title="Background">Background</a>
</h3></div></div></div>
<p>
There are two basic models for combining C++ and Python:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://www.python.org/doc/current/ext/intro.html" target="_top">extending</a>,
in which the end-user launches the Python interpreter executable and
imports Python &#8220;extension modules&#8221; written in C++. Think of taking
a library written in C++ and giving it a Python interface so Python programmers
can use it. From Python, these modules look just like regular Python
modules.
</li>
<li class="listitem">
<a href="http://www.python.org/doc/current/ext/embedding.html" target="_top">embedding</a>,
in which the end-user launches a program written in C++ that in turn
invokes the Python interpreter as a library subroutine. Think of adding
scriptability to an existing application.
</li>
</ul></div>
<p>
The key distinction between extending and embedding is the location of the
C++ <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code>
function: in the Python interpreter executable, or in some other program,
respectively. Note that even when embedding Python in another program, <a href="http://www.python.org/doc/current/ext/extending-with-embedding.html" target="_top">extension
modules are often the best way to make C/C++ functionality accessible to
Python code</a>, so the use of extension modules is really at the heart
of both models.
</p>
<p>
Except in rare cases, extension modules are built as dynamically-loaded libraries
with a single entry point, which means you can change them without rebuilding
either the other extension modules or the executable containing <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code>.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../building.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="no_install_quickstart.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,128 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Choosing a Boost.Python Library Binary</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="configuring_boost_build.html" title="Configuring Boost.Build">
<link rel="next" href="include_issues.html" title="#include Issues">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="configuring_boost_build.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="include_issues.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.choosing_a_boost_python_library_"></a><a class="link" href="choosing_a_boost_python_library_.html" title="Choosing a Boost.Python Library Binary">Choosing a
Boost.Python Library Binary</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="choosing_a_boost_python_library_.html#building.choosing_a_boost_python_library_.the_dynamic_binary">The
Dynamic Binary</a></span></dt>
<dt><span class="section"><a href="choosing_a_boost_python_library_.html#building.choosing_a_boost_python_library_.the_static_binary">The
Static Binary</a></span></dt>
</dl></div>
<p>
If&#8212;instead of letting Boost.Build construct and link with the right libraries
automatically&#8212;you choose to use a pre-built Boost.Python library, you'll
need to think about which one to link with. The Boost.Python binary comes
in both static and dynamic flavors. Take care to choose the right flavor
for your application. <a href="#ftn.building.choosing_a_boost_python_library_.f0" class="footnote" name="building.choosing_a_boost_python_library_.f0"><sup class="footnote">[3]</sup></a>
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="building.choosing_a_boost_python_library_.the_dynamic_binary"></a><a class="link" href="choosing_a_boost_python_library_.html#building.choosing_a_boost_python_library_.the_dynamic_binary" title="The Dynamic Binary">The
Dynamic Binary</a>
</h4></div></div></div>
<p>
The dynamic library is the safest and most-versatile choice:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
A single copy of the library code is used by all extension modules
built with a given toolset. <a href="#ftn.building.choosing_a_boost_python_library_.the_dynamic_binary.f0" class="footnote" name="building.choosing_a_boost_python_library_.the_dynamic_binary.f0"><sup class="footnote">[4]</sup></a>
</li>
<li class="listitem">
The library contains a type conversion registry. Because one registry
is shared among all extension modules, instances of a class exposed
to Python in one dynamically-loaded extension module can be passed
to functions exposed in another such module.
</li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="building.choosing_a_boost_python_library_.the_static_binary"></a><a class="link" href="choosing_a_boost_python_library_.html#building.choosing_a_boost_python_library_.the_static_binary" title="The Static Binary">The
Static Binary</a>
</h4></div></div></div>
<p>
It might be appropriate to use the static Boost.Python library in any of
the following cases:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
You are <a href="https://docs.python.org/2/extending/extending.html" target="_top">extending</a>
python and the types exposed in your dynamically-loaded extension module
don't need to be used by any other Boost.Python extension modules,
and you don't care if the core library code is duplicated among them.
</li>
<li class="listitem">
You are <a href="https://docs.python.org/2/extending/embedding.html" target="_top">embedding</a>
python in your application and either:
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
You are targeting a Unix variant OS other than MacOS or AIX,
where the dynamically-loaded extension modules can &#8220;see&#8221;
the Boost.Python library symbols that are part of the executable.
</li>
<li class="listitem">
Or, you have statically linked some Boost.Python extension modules
into your application and you don't care if any dynamically-loaded
Boost.Python extension modules are able to use the types exposed
by your statically-linked extension modules (and vice-versa).
</li>
</ul></div>
</li>
</ul></div>
</div>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.building.choosing_a_boost_python_library_.f0" class="footnote"><p><a href="#building.choosing_a_boost_python_library_.f0" class="para"><sup class="para">[3] </sup></a>
Information about how to identify the static and dynamic builds of Boost.Python
on <a href="http://boost.org/more/getting_started/windows.html#library-naming" target="_top">Windows</a>
/ <a href="http://boost.org/more/getting_started/unix-variants.html#library-naming" target="_top">Unix
variants</a>
</p></div>
<div id="ftn.building.choosing_a_boost_python_library_.the_dynamic_binary.f0" class="footnote"><p><a href="#building.choosing_a_boost_python_library_.the_dynamic_binary.f0" class="para"><sup class="para">[4] </sup></a>
Because of the way most *nix platforms share symbols among dynamically-loaded
objects, I'm not certain that extension modules built with different
compiler toolsets will always use different copies of the Boost.Python
library when loaded into the same Python instance. Not using different
libraries could be a good thing if the compilers have compatible
ABIs, because extension modules built with the two libraries would
be interoperable. Otherwise, it could spell disaster, since an extension
module and the Boost.Python library would have different ideas of
such things as class layout. I would appreciate someone doing the
experiment to find out what happens.
</p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="configuring_boost_build.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="include_issues.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,252 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Configuring Boost.Build</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="installing_boost_python_on_your_.html" title="Installing Boost.Python on your System">
<link rel="next" href="choosing_a_boost_python_library_.html" title="Choosing a Boost.Python Library Binary">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="installing_boost_python_on_your_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="choosing_a_boost_python_library_.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.configuring_boost_build"></a><a class="link" href="configuring_boost_build.html" title="Configuring Boost.Build">Configuring Boost.Build</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="configuring_boost_build.html#building.configuring_boost_build.python_configuration_parameters">Python
Configuration Parameters</a></span></dt>
<dt><span class="section"><a href="configuring_boost_build.html#building.configuring_boost_build.examples">Examples</a></span></dt>
</dl></div>
<p>
As described in the <a href="http://www.boost.org/build/doc/html/bbv2/overview/configuration.html" target="_top">Boost.Build
Reference Manual</a>, a file called <code class="computeroutput"><span class="identifier">user</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code> in
your home directory is used to specify the tools and libraries available
to the build system. You may need to create or edit <code class="computeroutput"><span class="identifier">user</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code> to
tell Boost.Build how to invoke Python, <code class="computeroutput"><span class="preprocessor">#include</span></code>
its headers, and link with its libraries.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
If you are using a unix-variant OS and you ran Boost's <code class="computeroutput"><span class="identifier">configure</span></code>
script, it may have generated a <code class="computeroutput"><span class="identifier">user</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code>
for you. <a href="#ftn.building.configuring_boost_build.f0" class="footnote" name="building.configuring_boost_build.f0"><sup class="footnote">[2]</sup></a> If your <code class="computeroutput"><span class="identifier">configure</span></code>/<code class="computeroutput"><span class="identifier">make</span></code> sequence was successful and Boost.Python
binaries were built, your <code class="computeroutput"><span class="identifier">user</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code>
file is probably already correct.
</p></td></tr>
</table></div>
<p>
If you have one fairly &#8220;standard&#8221; python installation for your platform,
you might not need to do anything special to describe it. If you haven't
configured python in <code class="computeroutput"><span class="identifier">user</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code> (and
you don't specify <code class="computeroutput"><span class="special">--</span><span class="identifier">without</span><span class="special">-</span><span class="identifier">python</span></code>
on the Boost.Build command line), Boost.Build will automatically execute
the equivalent of
</p>
<pre class="programlisting"><span class="identifier">import</span> <span class="identifier">toolset</span> <span class="special">:</span> <span class="keyword">using</span> <span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">python</span> <span class="special">;</span>
</pre>
<p>
which automatically looks for Python in the most likely places. However,
that only happens when using the Boost.Python project file (e.g. when referred
to by another project as in the quickstart method). If instead you are linking
against separately-compiled Boost.Python binaries, you should set up a <code class="computeroutput"><span class="identifier">user</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code> file
with at least the minimal incantation above.
</p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="building.configuring_boost_build.python_configuration_parameters"></a><a class="link" href="configuring_boost_build.html#building.configuring_boost_build.python_configuration_parameters" title="Python Configuration Parameters">Python
Configuration Parameters</a>
</h4></div></div></div>
<p>
If you have several versions of Python installed, or Python is installed
in an unusual way, you may want to supply any or all of the following optional
parameters to <code class="computeroutput"><span class="keyword">using</span> <span class="identifier">python</span></code>.
</p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">version</span></dt>
<dd><p>
the version of Python to use. Should be in Major.Minor format, for
example, <code class="computeroutput"><span class="number">2.3</span></code>. Do not
include the subminor version (i.e. <span class="bold"><strong>not</strong></span>
<code class="computeroutput"><span class="number">2.5</span><span class="special">.</span><span class="number">1</span></code>). If you have multiple Python versions
installed, the version will usually be the only configuration argument
required.
</p></dd>
<dt><span class="term">cmd-or-prefix</span></dt>
<dd><p>
preferably, a command that invokes a Python interpreter. Alternatively,
the installation prefix for Python libraries and header files. Only
use the alternative formulation if there is no appropriate Python
executable available.
</p></dd>
<dt><span class="term"><span class="bold"><strong>includes</strong></span></span></dt>
<dd><p>
the <code class="computeroutput"><span class="preprocessor">#include</span></code> paths
for Python headers. Normally the correct path(s) will be automatically
deduced from <code class="computeroutput"><span class="identifier">version</span></code>
and/or <code class="computeroutput"><span class="identifier">cmd</span><span class="special">-</span><span class="keyword">or</span><span class="special">-</span><span class="identifier">prefix</span></code>.
</p></dd>
<dt><span class="term"><span class="bold"><strong>libraries</strong></span></span></dt>
<dd><p>
the path to Python library binaries. On MacOS/Darwin, you can also
pass the path of the Python framework. Normally the correct path(s)
will be automatically deduced from <code class="computeroutput"><span class="identifier">version</span></code>
and/or <code class="computeroutput"><span class="identifier">cmd</span><span class="special">-</span><span class="keyword">or</span><span class="special">-</span><span class="identifier">prefix</span></code>.
</p></dd>
<dt><span class="term"><span class="bold"><strong>condition</strong></span></span></dt>
<dd><p>
if specified, should be a set of Boost.Build properties that are
matched against the build configuration when Boost.Build selects
a Python configuration to use. See examples below for details.
</p></dd>
<dt><span class="term"><span class="bold"><strong>extension-suffix</strong></span></span></dt>
<dd><p>
A string to append to the name of extension modules before the true
filename extension. You almost certainly don't need to use this.
Usually this suffix is only used when targeting a Windows debug build
of Python, and will be set automatically for you based on the value
of the <a class="link" href="python_debugging_builds.html" title="Python Debugging Builds">&lt;python-debugging&gt;</a>
feature. However, at least one Linux distribution (Ubuntu Feisty
Fawn) has a specially configured <a href="https://wiki.ubuntu.com/PyDbgBuilds" target="_top">&lt;python-dbg&gt;</a>
package that claims to use such a suffix.
</p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="building.configuring_boost_build.examples"></a><a class="link" href="configuring_boost_build.html#building.configuring_boost_build.examples" title="Examples">Examples</a>
</h4></div></div></div>
<p>
Note that in the examples below, case and <span class="bold"><strong>especially
whitespace</strong></span> are significant.
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
If you have both python 2.5 and python 2.4 installed, <code class="computeroutput"><span class="identifier">user</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code> might contain
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">python</span> <span class="special">:</span> <span class="number">2.5</span> <span class="special">;</span> <span class="special">#</span> <span class="identifier">Make</span> <span class="identifier">both</span> <span class="identifier">versions</span> <span class="identifier">of</span> <span class="identifier">Python</span> <span class="identifier">available</span>
<span class="keyword">using</span> <span class="identifier">python</span> <span class="special">:</span> <span class="number">2.4</span> <span class="special">;</span> <span class="special">#</span> <span class="identifier">To</span> <span class="identifier">build</span> <span class="identifier">with</span> <span class="identifier">python</span> <span class="number">2.4</span><span class="special">,</span> <span class="identifier">add</span> <span class="identifier">python</span><span class="special">=</span><span class="number">2.4</span>
<span class="preprocessor"># to</span> <span class="identifier">your</span> <span class="identifier">command</span> <span class="identifier">line</span><span class="special">.</span>
</pre>
<p>
The first version configured (2.5) becomes the default. To build
against python 2.4, add <code class="computeroutput"><span class="identifier">python</span><span class="special">=</span><span class="number">2.4</span></code>
to the <code class="computeroutput"><span class="identifier">bjam</span></code> command
line.
</p>
</li>
<li class="listitem">
If you have python installed in an unusual location, you might supply
the path to the interpreter in the <code class="computeroutput"><span class="identifier">cmd</span><span class="special">-</span><span class="keyword">or</span><span class="special">-</span><span class="identifier">prefix</span></code>
parameter:
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">python</span> <span class="special">:</span> <span class="special">:</span> <span class="special">/</span><span class="identifier">usr</span><span class="special">/</span><span class="identifier">local</span><span class="special">/</span><span class="identifier">python</span><span class="special">-</span><span class="number">2.6</span><span class="special">-</span><span class="identifier">beta</span><span class="special">/</span><span class="identifier">bin</span><span class="special">/</span><span class="identifier">python</span> <span class="special">;</span>
</pre>
</li>
<li class="listitem">
If you have a separate build of Python for use with a particular toolset,
you might supply that toolset in the <code class="computeroutput"><span class="identifier">condition</span></code>
parameter:
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">python</span> <span class="special">;</span> <span class="special">#</span> <span class="identifier">use</span> <span class="keyword">for</span> <span class="identifier">most</span> <span class="identifier">toolsets</span>
<span class="preprocessor"># Use</span> <span class="identifier">with</span> <span class="identifier">Intel</span> <span class="identifier">C</span><span class="special">++</span> <span class="identifier">toolset</span>
<span class="keyword">using</span> <span class="identifier">python</span>
<span class="special">:</span> <span class="special">#</span> <span class="identifier">version</span>
<span class="special">:</span> <span class="identifier">c</span><span class="special">:\\</span><span class="identifier">Devel</span><span class="special">\\</span><span class="identifier">Python</span><span class="special">-</span><span class="number">2.5</span><span class="special">-</span><span class="identifier">IntelBuild</span><span class="special">\\</span><span class="identifier">PCBuild</span><span class="special">\\</span><span class="identifier">python</span> <span class="special">#</span> <span class="identifier">cmd</span><span class="special">-</span><span class="keyword">or</span><span class="special">-</span><span class="identifier">prefix</span>
<span class="special">:</span> <span class="special">#</span> <span class="identifier">includes</span>
<span class="special">:</span> <span class="special">#</span> <span class="identifier">libraries</span>
<span class="special">:</span> <span class="special">&lt;</span><span class="identifier">toolset</span><span class="special">&gt;</span><span class="identifier">intel</span> <span class="special">#</span> <span class="identifier">condition</span>
<span class="special">;</span>
</pre>
</li>
<li class="listitem">
If you have downloaded the Python sources and built both the normal
and the <a class="link" href="python_debugging_builds.html" title="Python Debugging Builds">"python
debugging"</a> builds from source on Windows, you might see:
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">python</span> <span class="special">:</span> <span class="number">2.5</span> <span class="special">:</span> <span class="identifier">C</span><span class="special">:\\</span><span class="identifier">src</span><span class="special">\\</span><span class="identifier">Python</span><span class="special">-</span><span class="number">2.5</span><span class="special">\\</span><span class="identifier">PCBuild</span><span class="special">\\</span><span class="identifier">python</span> <span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">python</span> <span class="special">:</span> <span class="number">2.5</span> <span class="special">:</span> <span class="identifier">C</span><span class="special">:\\</span><span class="identifier">src</span><span class="special">\\</span><span class="identifier">Python</span><span class="special">-</span><span class="number">2.5</span><span class="special">\\</span><span class="identifier">PCBuild</span><span class="special">\\</span><span class="identifier">python_d</span>
<span class="special">:</span> <span class="special">#</span> <span class="identifier">includes</span>
<span class="special">:</span> <span class="special">#</span> <span class="identifier">libs</span>
<span class="special">:</span> <span class="special">&lt;</span><span class="identifier">python</span><span class="special">-</span><span class="identifier">debugging</span><span class="special">&gt;</span><span class="identifier">on</span> <span class="special">;</span>
</pre>
</li>
<li class="listitem">
You can set up your user-config.jam so a bjam built under Windows can
build/test both Windows and Cygwin_ python extensions. Just pass <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">target</span><span class="special">-</span><span class="identifier">os</span><span class="special">&gt;</span><span class="identifier">cygwin</span></code>
in the <code class="computeroutput"><span class="identifier">condition</span></code> parameter
for the cygwin python installation:
<pre class="programlisting"><span class="preprocessor"># windows</span> <span class="identifier">installation</span>
<span class="keyword">using</span> <span class="identifier">python</span> <span class="special">;</span>
<span class="preprocessor"># cygwin</span> <span class="identifier">installation</span>
<span class="keyword">using</span> <span class="identifier">python</span> <span class="special">:</span> <span class="special">:</span> <span class="identifier">c</span><span class="special">:\\</span><span class="identifier">cygwin</span><span class="special">\\</span><span class="identifier">bin</span><span class="special">\\</span><span class="identifier">python2</span><span class="special">.</span><span class="number">5</span> <span class="special">:</span> <span class="special">:</span> <span class="special">:</span> <span class="special">&lt;</span><span class="identifier">target</span><span class="special">-</span><span class="identifier">os</span><span class="special">&gt;</span><span class="identifier">cygwin</span> <span class="special">;</span>
</pre>
<p>
when you put target-os=cygwin in your build request, it should build
with the cygwin version of python: <a name="flavor"></a>_
</p>
<pre class="programlisting"><span class="identifier">bjam</span> <span class="identifier">target</span><span class="special">-</span><span class="identifier">os</span><span class="special">=</span><span class="identifier">cygwin</span> <span class="identifier">toolset</span><span class="special">=</span><span class="identifier">gcc</span>
</pre>
<p>
This is supposed to work the other way, too (targeting windows python
with a <a href="http://cygwin.com" target="_top">Cygwin</a> bjam) but it
seems as though the support in Boost.Build's toolsets for building
that way is broken at the time of this writing.
</p>
</li>
<li class="listitem">
Note that because of <a href="http://zigzag.cs.msu.su/boost.build/wiki/AlternativeSelection" target="_top">the
way Boost.Build currently selects target alternatives</a>, you
might have be very explicit in your build requests. For example, given:
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">python</span> <span class="special">:</span> <span class="number">2.5</span> <span class="special">;</span> <span class="special">#</span> <span class="identifier">a</span> <span class="identifier">regular</span> <span class="identifier">windows</span> <span class="identifier">build</span>
<span class="keyword">using</span> <span class="identifier">python</span> <span class="special">:</span> <span class="number">2.4</span> <span class="special">:</span> <span class="special">:</span> <span class="special">:</span> <span class="special">:</span> <span class="special">&lt;</span><span class="identifier">target</span><span class="special">-</span><span class="identifier">os</span><span class="special">&gt;</span><span class="identifier">cygwin</span> <span class="special">;</span>
</pre>
<p>
building with
</p>
<pre class="programlisting"><span class="identifier">bjam</span> <span class="identifier">target</span><span class="special">-</span><span class="identifier">os</span><span class="special">=</span><span class="identifier">cygwin</span>
</pre>
<p>
will yield an error. Instead, you'll need to write
</p>
<pre class="programlisting"><span class="identifier">bjam</span> <span class="identifier">target</span><span class="special">-</span><span class="identifier">os</span><span class="special">=</span><span class="identifier">cygwin</span><span class="special">/</span><span class="identifier">python</span><span class="special">=</span><span class="number">2.4</span>
</pre>
</li>
</ul></div>
</div>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.building.configuring_boost_build.f0" class="footnote"><p><a href="#building.configuring_boost_build.f0" class="para"><sup class="para">[2] </sup></a>
<code class="computeroutput"><span class="identifier">configure</span></code> overwrites
the existing <code class="computeroutput"><span class="identifier">user</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code> in your home directory (if any)
after making a backup of the old version.
</p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="installing_boost_python_on_your_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="choosing_a_boost_python_library_.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,53 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>#include Issues</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="choosing_a_boost_python_library_.html" title="Choosing a Boost.Python Library Binary">
<link rel="next" href="python_debugging_builds.html" title="Python Debugging Builds">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="choosing_a_boost_python_library_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="python_debugging_builds.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.include_issues"></a><a class="link" href="include_issues.html" title="#include Issues"><code class="computeroutput"><span class="preprocessor">#include</span></code>
Issues</a>
</h3></div></div></div>
<p>
1. If you should ever have occasion to <code class="computeroutput"><span class="preprocessor">#include</span>
<span class="string">"python.h"</span></code> directly in a
translation unit of a program using Boost.Python, use <code class="computeroutput"><span class="preprocessor">#include</span>
<span class="string">"boost/python/detail/wrap_python.hpp"</span></code>
instead. It handles several issues necessary for use with Boost.Python, one
of which is mentioned in the next section.
</p>
<p>
2. Be sure not to <code class="computeroutput"><span class="preprocessor">#include</span></code>
any system headers before <code class="computeroutput"><span class="identifier">wrap_python</span><span class="special">.</span><span class="identifier">hpp</span></code>. This
restriction is actually imposed by Python, or more properly, by Python's
interaction with your operating system. See <a href="http://docs.python.org/ext/simpleExample.html" target="_top">http://docs.python.org/ext/simpleExample.html</a>
for details.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="choosing_a_boost_python_library_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="python_debugging_builds.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,52 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Installing Boost.Python on your System</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="no_install_quickstart.html" title="No-Install Quickstart">
<link rel="next" href="configuring_boost_build.html" title="Configuring Boost.Build">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="no_install_quickstart.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="configuring_boost_build.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.installing_boost_python_on_your_"></a><a class="link" href="installing_boost_python_on_your_.html" title="Installing Boost.Python on your System">Installing
Boost.Python on your System</a>
</h3></div></div></div>
<p>
Since Boost.Python is a separately-compiled (as opposed to <code class="computeroutput"><span class="identifier">header</span><span class="special">-</span><span class="identifier">only</span></code>) library, its user relies on the services
of a Boost.Python library binary.
</p>
<p>
If you need a regular installation of the Boost.Python library binaries on
your system, the Boost <a href="http://www.boost.org/more/getting_started/" target="_top">Getting
Started Guide</a> will walk you through the steps of creating one. If
building binaries from source, you might want to supply the <code class="computeroutput"><span class="special">--</span><span class="identifier">with</span><span class="special">-</span><span class="identifier">python</span></code>
argument to <code class="computeroutput"><span class="identifier">bjam</span></code> (or the
<code class="computeroutput"><span class="special">--</span><span class="identifier">with</span><span class="special">-</span><span class="identifier">libraries</span><span class="special">=</span><span class="identifier">python</span></code>
argument to <code class="computeroutput"><span class="identifier">configure</span></code>), so
only the Boost.Python binary will be built, rather than all the Boost binaries.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="no_install_quickstart.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="configuring_boost_build.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,318 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>No-Install Quickstart</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="background.html" title="Background">
<link rel="next" href="installing_boost_python_on_your_.html" title="Installing Boost.Python on your System">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="background.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="installing_boost_python_on_your_.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.no_install_quickstart"></a><a class="link" href="no_install_quickstart.html" title="No-Install Quickstart">No-Install Quickstart</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="no_install_quickstart.html#building.no_install_quickstart.basic_procedure">Basic
Procedure</a></span></dt>
<dt><span class="section"><a href="no_install_quickstart.html#building.no_install_quickstart.in_case_of_trouble">In
Case of Trouble</a></span></dt>
<dt><span class="section"><a href="no_install_quickstart.html#building.no_install_quickstart.in_case_everything_seemed_to_wor">In
Case Everything Seemed to Work</a></span></dt>
<dt><span class="section"><a href="no_install_quickstart.html#building.no_install_quickstart.modifying_the_example_project">Modifying
the Example Project</a></span></dt>
</dl></div>
<p>
There is no need to &#8220;install Boost&#8221; in order to get started using Boost.Python.
These instructions use <a href="http://www.boost.org/build" target="_top">Boost.Build</a>
projects, which will build those binaries as soon as they're needed. Your
first tests may take a little longer while you wait for Boost.Python to build,
but doing things this way will save you from worrying about build intricacies
like which library binaries to use for a specific compiler configuration
and figuring out the right compiler options to use yourself.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
<p>
Of course it's possible to use other build systems to build Boost.Python
and its extensions, but they are not officially supported by Boost. Moreover
<span class="bold"><strong>99% of all &#8220;I can't build Boost.Python&#8221; problems
come from trying to use another build system</strong></span> without first following
these instructions.
</p>
<p>
If you want to use another system anyway, we suggest that you follow these
instructions, and then invoke <code class="computeroutput"><span class="identifier">bjam</span></code>
with the
</p>
<p>
<code class="computeroutput"><span class="special">-</span><span class="identifier">a</span>
<span class="special">-</span><span class="identifier">o</span></code><span class="emphasis"><em>filename</em></span>
</p>
<p>
options to dump the build commands it executes to a file, so you can see
what your alternate build system needs to do.
</p>
</td></tr>
</table></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="building.no_install_quickstart.basic_procedure"></a><a class="link" href="no_install_quickstart.html#building.no_install_quickstart.basic_procedure" title="Basic Procedure">Basic
Procedure</a>
</h4></div></div></div>
<p>
1. Get Boost; see sections 1 and 2 of the Boost <a href="http://www.boost.org/more/getting_started/" target="_top">Getting
Started Guide</a>.
</p>
<p>
2. Get the <code class="computeroutput"><span class="identifier">bjam</span></code> build driver.
See section 5 of the Boost <a href="http://www.boost.org/more/getting_started/" target="_top">Getting
Started Guide</a>.
</p>
<p>
3. cd into the <code class="computeroutput"><span class="identifier">example</span><span class="special">/</span><span class="identifier">quickstart</span><span class="special">/</span></code> directory of your Boost.Python installation,
which contains a small example project.
</p>
<p>
4. Invoke <code class="computeroutput"><span class="identifier">bjam</span></code>. Replace
the &#8220;<code class="computeroutput"><span class="identifier">stage</span></code>&#8220; argument
from the example invocation from section 5 of the Boost <a href="http://www.boost.org/more/getting_started/" target="_top">Getting
Started Guide</a> with &#8220;<code class="computeroutput"><span class="identifier">test</span></code>,&#8220;
to build all the test targets. Also add the argument &#8220;<code class="computeroutput"><span class="special">--</span><span class="identifier">verbose</span><span class="special">-</span><span class="identifier">test</span></code>&#8221; to see the output generated by
the tests when they are run. On Windows, your <code class="computeroutput"><span class="identifier">bjam</span></code>
invocation might look something like:
</p>
<pre class="programlisting"><span class="identifier">C</span><span class="special">:\\...\\</span><span class="identifier">quickstart</span><span class="special">&gt;</span> <span class="identifier">bjam</span> <span class="identifier">toolset</span><span class="special">=</span><span class="identifier">msvc</span> <span class="special">--</span><span class="identifier">verbose</span><span class="special">-</span><span class="identifier">test</span> <span class="identifier">test</span>
</pre>
<p>
and on Unix variants, perhaps,
</p>
<pre class="programlisting"><span class="special">.../</span><span class="identifier">quickstart</span><span class="error">$</span> <span class="identifier">bjam</span> <span class="identifier">toolset</span><span class="special">=</span><span class="identifier">gcc</span> <span class="special">--</span><span class="identifier">verbose</span><span class="special">-</span><span class="identifier">test</span> <span class="identifier">test</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
For the sake of concision, the rest of this guide will use unix-style
forward slashes in pathnames instead of the backslashes with which Windows
users may be more familiar. The forward slashes should work everywhere
except in <a href="http://www.boost.org/more/getting_started/windows.html#command-prompt" target="_top">Command
Prompt</a> windows, where you should use backslashes.
</p></td></tr>
</table></div>
<p>
If you followed this procedure successfully, you will have built an extension
module called <code class="computeroutput"><span class="identifier">extending</span></code>
and tested it by running a Python script called <code class="computeroutput"><span class="identifier">test_extending</span><span class="special">.</span><span class="identifier">py</span></code>.
You will also have built and run a simple application called <code class="computeroutput"><span class="identifier">embedding</span></code> that embeds python.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="building.no_install_quickstart.in_case_of_trouble"></a><a class="link" href="no_install_quickstart.html#building.no_install_quickstart.in_case_of_trouble" title="In Case of Trouble">In
Case of Trouble</a>
</h4></div></div></div>
<p>
If you're seeing lots of compiler and/or linker error messages, it's probably
because Boost.Build is having trouble finding your Python installation.
You might want to pass the <code class="computeroutput"><span class="special">--</span><span class="identifier">debug</span><span class="special">-</span><span class="identifier">configuration</span></code> option to <code class="computeroutput"><span class="identifier">bjam</span></code> the first few times you invoke it,
to make sure that Boost.Build is correctly locating all the parts of your
Python installation. If it isn't, consider <a class="link" href="configuring_boost_build.html" title="Configuring Boost.Build">Configuring
Boost.Build</a> as detailed below.
</p>
<p>
If you're still having trouble, Someone on one of the following mailing
lists may be able to help:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
The <a href="http://www.boost.org/more/mailing_lists.htm#jamboost" target="_top">Boost.Build
mailing list</a> for issues related to Boost.Build
</li>
<li class="listitem">
The <a href="http://www.boost.org/more/mailing_lists.htm#cplussig" target="_top">Boost.Python
mailing list</a> for issues specifically related to Boost.Python
</li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="building.no_install_quickstart.in_case_everything_seemed_to_wor"></a><a class="link" href="no_install_quickstart.html#building.no_install_quickstart.in_case_everything_seemed_to_wor" title="In Case Everything Seemed to Work">In
Case Everything Seemed to Work</a>
</h4></div></div></div>
<p>
Rejoice! If you're new to Boost.Python, at this point it might be a good
idea to ignore build issues for a while and concentrate on learning the
library by going through the <a href="../tutorial/index.html" target="_top">Tutorial</a>
and perhaps some of the <a href="../reference/index.html" target="_top">Reference Manual</a>,
trying out what you've learned about the API by modifying the quickstart
project.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="building.no_install_quickstart.modifying_the_example_project"></a><a class="link" href="no_install_quickstart.html#building.no_install_quickstart.modifying_the_example_project" title="Modifying the Example Project">Modifying
the Example Project</a>
</h4></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="no_install_quickstart.html#building.no_install_quickstart.modifying_the_example_project.relocate_the_project">Relocate
the Project</a></span></dt>
<dt><span class="section"><a href="no_install_quickstart.html#building.no_install_quickstart.modifying_the_example_project.add_new_or_change_names_of_exist">Add
New or Change Names of Existing Source Files</a></span></dt>
<dt><span class="section"><a href="no_install_quickstart.html#building.no_install_quickstart.modifying_the_example_project.change_the_name_of_your_extensio">Change
the Name of your Extension Module</a></span></dt>
</dl></div>
<p>
If you're content to keep your extension module forever in one source file
called <code class="computeroutput"><span class="identifier">extending</span><span class="special">.</span><span class="identifier">cpp</span></code>, inside your Boost.Python distribution,
and import it forever as <code class="computeroutput"><span class="identifier">extending</span></code>,
then you can stop here. However, it's likely that you will want to make
a few changes. There are a few things you can do without having to learn
<a href="http://www.boost.org/build" target="_top">Boost.Build</a> in depth.
</p>
<p>
The project you just built is specified in two files in the current directory:
<code class="computeroutput"><span class="identifier">boost</span><span class="special">-</span><span class="identifier">build</span><span class="special">.</span><span class="identifier">jam</span></code>, which tells <code class="computeroutput"><span class="identifier">bjam</span></code>
where it can find the interpreted code of the Boost build system, and
<code class="computeroutput"><span class="identifier">Jamroot</span></code>, which describes
the targets you just built. These files are heavily commented, so they
should be easy to modify. Take care, however, to preserve whitespace. Punctuation
such as <code class="computeroutput"><span class="special">;</span></code> will not be recognized
as intended by <code class="computeroutput"><span class="identifier">bjam</span></code> if
it is not surrounded by whitespace.
</p>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="building.no_install_quickstart.modifying_the_example_project.relocate_the_project"></a><a class="link" href="no_install_quickstart.html#building.no_install_quickstart.modifying_the_example_project.relocate_the_project" title="Relocate the Project">Relocate
the Project</a>
</h5></div></div></div>
<p>
You'll probably want to copy this project elsewhere so you can change
it without modifying your Boost distribution. To do that, simply
</p>
<p>
a. copy the entire <code class="computeroutput"><span class="identifier">example</span><span class="special">/</span><span class="identifier">quickstart</span><span class="special">/</span></code> directory into a new directory.
</p>
<p>
b. In the new copies of <code class="computeroutput"><span class="identifier">boost</span><span class="special">-</span><span class="identifier">build</span><span class="special">.</span><span class="identifier">jam</span></code>
and <code class="computeroutput"><span class="identifier">Jamroot</span></code>, locate the
relative path near the top of the file that is clearly marked by a comment,
and edit that path so that it refers to the same directory your Boost
distribution as it referred to when the file was in its original location
in the <code class="computeroutput"><span class="identifier">example</span><span class="special">/</span><span class="identifier">quickstart</span><span class="special">/</span></code>
directory.
</p>
<p>
For example, if you moved the project from <code class="computeroutput"><span class="special">/</span><span class="identifier">home</span><span class="special">/</span><span class="identifier">dave</span><span class="special">/</span><span class="identifier">boost_1_34_0</span><span class="special">/</span><span class="identifier">libs</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">example</span><span class="special">/</span><span class="identifier">quickstart</span></code> to <code class="computeroutput"><span class="special">/</span><span class="identifier">home</span><span class="special">/</span><span class="identifier">dave</span><span class="special">/</span><span class="identifier">my</span><span class="special">-</span><span class="identifier">project</span></code>, you could change the first
path in <code class="computeroutput"><span class="identifier">boost</span><span class="special">-</span><span class="identifier">build</span><span class="special">.</span><span class="identifier">jam</span></code> from
</p>
<pre class="programlisting"><span class="special">../../../../</span><span class="identifier">tools</span><span class="special">/</span><span class="identifier">build</span><span class="special">/</span><span class="identifier">src</span>
</pre>
<p>
to
</p>
<pre class="programlisting"><span class="special">/</span><span class="identifier">home</span><span class="special">/</span><span class="identifier">dave</span><span class="special">/</span><span class="identifier">boost_1_34_0</span><span class="special">/</span><span class="identifier">tools</span><span class="special">/</span><span class="identifier">build</span><span class="special">/</span><span class="identifier">src</span>
</pre>
<p>
and change the first path in <code class="computeroutput"><span class="identifier">Jamroot</span></code>
from
</p>
<pre class="programlisting"><span class="special">../../../..</span>
</pre>
<p>
to
</p>
<pre class="programlisting"><span class="special">/</span><span class="identifier">home</span><span class="special">/</span><span class="identifier">dave</span><span class="special">/</span><span class="identifier">boost_1_34_0</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="building.no_install_quickstart.modifying_the_example_project.add_new_or_change_names_of_exist"></a><a class="link" href="no_install_quickstart.html#building.no_install_quickstart.modifying_the_example_project.add_new_or_change_names_of_exist" title="Add New or Change Names of Existing Source Files">Add
New or Change Names of Existing Source Files</a>
</h5></div></div></div>
<p>
The names of additional source files involved in building your extension
module or embedding application can be listed in <code class="computeroutput"><span class="identifier">Jamroot</span></code>
right alongside <code class="computeroutput"><span class="identifier">extending</span><span class="special">.</span><span class="identifier">cpp</span></code>
or <code class="computeroutput"><span class="identifier">embedding</span><span class="special">.</span><span class="identifier">cpp</span></code> respectively. Just be sure to leave
whitespace around each filename:
</p>
<pre class="programlisting"><span class="error">&#8230;</span> <span class="identifier">file1</span><span class="special">.</span><span class="identifier">cpp</span> <span class="identifier">file2</span><span class="special">.</span><span class="identifier">cpp</span> <span class="identifier">file3</span><span class="special">.</span><span class="identifier">cpp</span> <span class="error">&#8230;</span>
</pre>
<p>
Naturally, if you want to change the name of a source file you can tell
Boost.Build about it by editing the name in <code class="computeroutput"><span class="identifier">Jamroot</span></code>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="building.no_install_quickstart.modifying_the_example_project.change_the_name_of_your_extensio"></a><a class="link" href="no_install_quickstart.html#building.no_install_quickstart.modifying_the_example_project.change_the_name_of_your_extensio" title="Change the Name of your Extension Module">Change
the Name of your Extension Module</a>
</h5></div></div></div>
<p>
The name of the extension module is determined by two things:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
the name in <code class="computeroutput"><span class="identifier">Jamroot</span></code>
immediately following <code class="computeroutput"><span class="identifier">python</span><span class="special">-</span><span class="identifier">extension</span></code>,
and
</li>
<li class="listitem">
the name passed to <code class="computeroutput"><span class="identifier">BOOST_PYTHON_MODULE</span></code>
in <code class="computeroutput"><span class="identifier">extending</span><span class="special">.</span><span class="identifier">cpp</span></code>.
</li>
</ol></div>
<p>
To change the name of the extension module from <code class="computeroutput"><span class="identifier">extending</span></code>
to <code class="computeroutput"><span class="identifier">hello</span></code>, you'd edit
<code class="computeroutput"><span class="identifier">Jamroot</span></code>, changing
</p>
<pre class="programlisting"><span class="identifier">python</span><span class="special">-</span><span class="identifier">extension</span> <span class="identifier">extending</span> <span class="special">:</span> <span class="identifier">extending</span><span class="special">.</span><span class="identifier">cpp</span> <span class="special">;</span>
</pre>
<p>
to
</p>
<pre class="programlisting"><span class="identifier">python</span><span class="special">-</span><span class="identifier">extension</span> <span class="identifier">hello</span> <span class="special">:</span> <span class="identifier">extending</span><span class="special">.</span><span class="identifier">cpp</span> <span class="special">;</span>
</pre>
<p>
and you'd edit extending.cpp, changing
</p>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">extending</span><span class="special">)</span>
</pre>
<p>
to
</p>
<pre class="programlisting"><span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="background.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="installing_boost_python_on_your_.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,47 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Notes for MinGW (and Cygwin with -mno-cygwin) GCC Users</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="testing_boost_python.html" title="Testing Boost.Python">
<link rel="next" href="../configuration.html" title="Chapter&#160;3.&#160;Configuration">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="testing_boost_python.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../configuration.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.notes_for_mingw_and_cygwin_with_"></a><a class="link" href="notes_for_mingw_and_cygwin_with_.html" title="Notes for MinGW (and Cygwin with -mno-cygwin) GCC Users">Notes for
MinGW (and Cygwin with -mno-cygwin) GCC Users</a>
</h3></div></div></div>
<p>
If you are using a version of Python prior to 2.4.1 with a MinGW prior to
3.0.0 (with binutils-2.13.90-20030111-1), you will need to create a MinGW-compatible
version of the Python library; the one shipped with Python will only work
with a Microsoft-compatible linker. Follow the instructions in the &#8220;Non-Microsoft&#8221;
section of the &#8220;Building Extensions: Tips And Tricks&#8221; chapter in <a href="https://docs.python.org/2/install/index.html" target="_top">Installing Python Modules</a>
to create <code class="computeroutput"><span class="identifier">libpythonXX</span><span class="special">.</span><span class="identifier">a</span></code>, where <code class="computeroutput"><span class="identifier">XX</span></code>
corresponds to the major and minor version numbers of your Python installation.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="testing_boost_python.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../configuration.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,78 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Python Debugging Builds</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="include_issues.html" title="#include Issues">
<link rel="next" href="testing_boost_python.html" title="Testing Boost.Python">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="include_issues.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="testing_boost_python.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.python_debugging_builds"></a><a class="link" href="python_debugging_builds.html" title="Python Debugging Builds">Python Debugging Builds</a>
</h3></div></div></div>
<p>
Python can be built in a special &#8220;python debugging&#8221; configuration that
adds extra checks and instrumentation that can be very useful for developers
of extension modules. The data structures used by the debugging configuration
contain additional members, so <span class="bold"><strong>a Python executable
built with python debugging enabled cannot be used with an extension module
or library compiled without it, and vice-versa.</strong></span>
</p>
<p>
Since pre-built &#8220;python debugging&#8221; versions of the Python executable
and libraries are not supplied with most distributions of Python, <a href="#ftn.building.python_debugging_builds.f0" class="footnote" name="building.python_debugging_builds.f0"><sup class="footnote">[5]</sup></a> and we didn't want to force our users to build them, Boost.Build
does not automatically enable python debugging in its <code class="computeroutput"><span class="identifier">debug</span></code>
build variant (which is the default). Instead there is a special build property
called <code class="computeroutput"><span class="identifier">python</span><span class="special">-</span><span class="identifier">debugging</span></code> that, when used as a build property,
will define the right preprocessor symbols and select the right libraries
to link with.
</p>
<p>
On unix-variant platforms, the debugging versions of Python's data structures
will only be used if the symbol <code class="computeroutput"><span class="identifier">Py_DEBUG</span></code>
is defined. On many windows compilers, when extension modules are built with
the preprocessor symbol <code class="computeroutput"><span class="identifier">_DEBUG</span></code>,
Python defaults to force linking with a special debugging version of the
Python DLL. Since that symbol is very commonly used even when Python is not
present, Boost.Python temporarily undefines <code class="computeroutput"><span class="identifier">_DEBUG</span></code>
when <code class="computeroutput"><span class="identifier">Python</span><span class="special">.</span><span class="identifier">h</span></code> is #included from <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">wrap_python</span><span class="special">.</span><span class="identifier">hpp</span></code> -
unless <code class="computeroutput"><span class="identifier">BOOST_DEBUG_PYTHON</span></code>
is defined. The upshot is that if you want &#8220;python debugging&#8221;and you
aren't using Boost.Build, you should make sure <code class="computeroutput"><span class="identifier">BOOST_DEBUG_PYTHON</span></code>
is defined, or python debugging will be suppressed.
</p>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.building.python_debugging_builds.f0" class="footnote"><p><a href="#building.python_debugging_builds.f0" class="para"><sup class="para">[5] </sup></a>
On Unix and similar platforms, a debugging python and associated libraries
are built by adding --with-pydebug when configuring the Python build. On
Windows, the debugging version of Python is generated by the "Win32
Debug" target of the Visual Studio project in the PCBuild subdirectory
of a full Python source code distribution.
</p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="include_issues.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="testing_boost_python.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,42 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Testing Boost.Python</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../building.html" title="Chapter&#160;2.&#160;Building and Testing">
<link rel="prev" href="python_debugging_builds.html" title="Python Debugging Builds">
<link rel="next" href="notes_for_mingw_and_cygwin_with_.html" title="Notes for MinGW (and Cygwin with -mno-cygwin) GCC Users">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="python_debugging_builds.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="notes_for_mingw_and_cygwin_with_.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="building.testing_boost_python"></a><a class="link" href="testing_boost_python.html" title="Testing Boost.Python">Testing Boost.Python</a>
</h3></div></div></div>
<p>
To run the full test suite for Boost.Python, invoke <code class="computeroutput"><span class="identifier">bjam</span></code>
in the <code class="computeroutput"><span class="identifier">test</span></code> subdirectory
of your Boost.Python distribution.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<br>Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="python_debugging_builds.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="notes_for_mingw_and_cygwin_with_.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,340 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;3.&#160;Configuration</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Boost.Python">
<link rel="up" href="index.html" title="Boost.Python">
<link rel="prev" href="building/notes_for_mingw_and_cygwin_with_.html" title="Notes for MinGW (and Cygwin with -mno-cygwin) GCC Users">
<link rel="next" href="support.html" title="Chapter&#160;4.&#160;Support Resources">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="building/notes_for_mingw_and_cygwin_with_.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="support.html"><img src="images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div>
<div><h1 class="title">
<a name="configuration"></a>Chapter&#160;3.&#160;Configuration</h1></div>
<div><div class="authorgroup"><div class="author"><h3 class="author">
<span class="firstname">David</span> <span class="surname">Abrahams</span>
</h3></div></div></div>
<div><p class="copyright">Copyright &#169; 2002-2015 David Abrahams, Stefan Seefeld</p></div>
</div></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="configuration.configuration"></a><a class="link" href="configuration.html#configuration.configuration" title="Configuration">Configuration</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="configuration.html#configuration.configuration.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="configuration.html#configuration.configuration.application_defined_macros">Application
Defined Macros</a></span></dt>
<dt><span class="section"><a href="configuration.html#configuration.configuration.library_defined_defined_macros">Library
Defined Defined Macros</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="configuration.configuration.introduction"></a><a class="link" href="configuration.html#configuration.configuration.introduction" title="Introduction">Introduction</a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Boost.Python</strong></span> uses several configuration
macros in <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>, as well as configuration macros meant
to be supplied by the application. These macros are documented here.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="configuration.configuration.application_defined_macros"></a><a class="link" href="configuration.html#configuration.configuration.application_defined_macros" title="Application Defined Macros">Application
Defined Macros</a>
</h4></div></div></div>
<p>
These are the macros that may be defined by an application using Boost.Python.
Note that if you extend a strict interpretation of the C++ standard to
cover dynamic libraries, using different values of these macros when compiling
different libraries (including extension modules and the Boost.Python library
itself) is a violation of the <a class="link" href="glossary.html#odr">ODR</a>. However,
we know of no C++ implementations on which this particular violation is
detectable or causes any problems.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Macro
</p>
</th>
<th>
<p>
Default
</p>
</th>
<th>
<p>
Meaning
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
BOOST_PYTHON_MAX_ARITY
</p>
</td>
<td>
<p>
15
</p>
</td>
<td>
<p>
The maximum arity of any function, member function, or constructor
to be wrapped, invocation of a Boost.Python function wich is
specified as taking arguments x1, x2,...Xn. This includes, in
particular, callback mechanisms such as object::operator()(...)
or call_method&lt;R&gt;(... ).
</p>
</td>
</tr>
<tr>
<td>
<p>
BOOST_PYTHON_MAX_BASES
</p>
</td>
<td>
<p>
10
</p>
</td>
<td>
<p>
The maximum number of template arguments to the <code class="computeroutput"><span class="identifier">bases</span><span class="special">&lt;...&gt;</span></code>
class template, which is used to specify the bases of a wrapped
C++ class..
</p>
</td>
</tr>
<tr>
<td>
<p>
BOOST_PYTHON_STATIC_MODULE
</p>
</td>
<td>
<p>
<span class="emphasis"><em>not defined</em></span>
</p>
</td>
<td>
<p>
If defined, prevents your module initialization function from
being treated as an exported symbol on platforms which support
that distinction in-code
</p>
</td>
</tr>
<tr>
<td>
<p>
BOOST_PYTHON_ENABLE_CDECL
</p>
</td>
<td>
<p>
<span class="emphasis"><em>not defined</em></span>
</p>
</td>
<td>
<p>
If defined, allows functions using the <code class="computeroutput"><span class="identifier">__cdecl</span></code>
calling convention to be wrapped.
</p>
</td>
</tr>
<tr>
<td>
<p>
BOOST_PYTHON_ENABLE_STDCALL
</p>
</td>
<td>
<p>
<span class="emphasis"><em>not defined</em></span>
</p>
</td>
<td>
<p>
If defined, allows functions using the <code class="computeroutput"><span class="identifier">__stdcall</span></code>
calling convention to be wrapped.
</p>
</td>
</tr>
<tr>
<td>
<p>
BOOST_PYTHON_ENABLE_FASTCALL
</p>
</td>
<td>
<p>
<span class="emphasis"><em>not defined</em></span>
</p>
</td>
<td>
<p>
If defined, allows functions using the <code class="computeroutput"><span class="identifier">__fastcall</span></code>
calling convention to be wrapped.
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="configuration.configuration.library_defined_defined_macros"></a><a class="link" href="configuration.html#configuration.configuration.library_defined_defined_macros" title="Library Defined Defined Macros">Library
Defined Defined Macros</a>
</h4></div></div></div>
<p>
These macros are defined by <span class="bold"><strong>Boost.Python</strong></span>
and are implementation details of interest only to implementors and those
porting to new platforms.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Macro
</p>
</th>
<th>
<p>
Default
</p>
</th>
<th>
<p>
Meaning
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
BOOST_PYTHON_TYPE_ID_NAME
</p>
</td>
<td>
<p>
<span class="emphasis"><em>not defined</em></span>
</p>
</td>
<td>
<p>
If defined, this indicates that the type_info comparison across
shared library boundaries does not work on this platform. In
other words, if shared-lib-1 passes <code class="computeroutput"><span class="keyword">typeid</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span></code> to a function in shared-lib-2
which compares it to <code class="computeroutput"><span class="keyword">typeid</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span></code>, that comparison may return
<code class="computeroutput"><span class="keyword">false</span></code>. If this macro
is #defined, Boost.Python uses and compares <code class="computeroutput"><span class="keyword">typeid</span><span class="special">(</span><span class="identifier">T</span><span class="special">).</span><span class="identifier">name</span><span class="special">()</span></code> instead of using and comparing
the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span></code> objects directly.
</p>
</td>
</tr>
<tr>
<td>
<p>
BOOST_PYTHON_NO_PY_SIGNATURES
</p>
</td>
<td>
<p>
<span class="emphasis"><em>not defined</em></span>
</p>
</td>
<td>
<p>
If defined for a module no pythonic signatures are generated
for the docstrings of the module functions, and no python type
is associated with any of the converters registered by the module.
This also reduces the binary size of the module by about 14%
(gcc compiled). If defined for the boost_python runtime library,
the default for the <code class="computeroutput"><span class="identifier">docstring_options</span><span class="special">.</span><span class="identifier">enable_py_signatures</span><span class="special">()</span></code> is set to <code class="computeroutput"><span class="keyword">false</span></code>.
</p>
</td>
</tr>
<tr>
<td>
<p>
BOOST_PYTHON_SUPPORTS_PY_SIGNATURES
</p>
</td>
<td>
<p>
<span class="emphasis"><em>defined</em></span> if <code class="computeroutput"><span class="identifier">BOOST_PYTHON_NO_PY_SIGNATURES</span></code>
is <span class="emphasis"><em>undefined</em></span>
</p>
</td>
<td>
<p>
This macro is defined to enable a smooth transition from older
Boost.Python versions which do not support pythonic signatures.
For example usage see here.
</p>
</td>
</tr>
<tr>
<td>
<p>
BOOST_PYTHON_PY_SIGNATURES_PROPER_INIT_SELF_TYPE
</p>
</td>
<td>
<p>
<span class="emphasis"><em>not defined</em></span>
</p>
</td>
<td>
<p>
If defined the python type of <code class="computeroutput"><span class="identifier">__init__</span></code>
method "self" parameters is properly generated, otherwise
object is used. It is undefined by default because it increases
the binary size of the module by about 14% (gcc compiled).
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="building/notes_for_mingw_and_cygwin_with_.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="support.html"><img src="images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,84 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Boost.Python">
<link rel="up" href="index.html" title="Boost.Python">
<link rel="prev" href="support.html" title="Chapter&#160;4.&#160;Support Resources">
<link rel="next" href="faq/i_m_getting_the_attempt_to_retur.html" title="I'm getting the &quot;attempt to return dangling reference&quot; error. What am I doing wrong?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="support.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="faq/i_m_getting_the_attempt_to_retur.html"><img src="images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="faq"></a>Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)</h1></div></div></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.how_can_i_wrap_a_function_which_"></a><a class="link" href="faq.html#faq.how_can_i_wrap_a_function_which_" title="How can I wrap a function which takes a function pointer as an argument?">How can I wrap
a function which takes a function pointer as an argument?</a>
</h3></div></div></div>
<p>
If what you're trying to do is something like this:
</p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">void</span> <span class="special">(</span><span class="identifier">string</span> <span class="identifier">s</span><span class="special">)</span> <span class="special">&gt;</span> <span class="identifier">funcptr</span><span class="special">;</span>
<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">funcptr</span> <span class="identifier">fp</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">fp</span><span class="special">(</span><span class="string">"hello,world!"</span><span class="special">);</span>
<span class="special">}</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">test</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span><span class="identifier">foo</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
And then:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">def</span> <span class="identifier">hello</span><span class="special">(</span><span class="identifier">s</span><span class="special">):</span>
<span class="special">...</span> <span class="identifier">print</span> <span class="identifier">s</span>
<span class="special">...</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span>
<span class="identifier">hello</span><span class="special">,</span> <span class="identifier">world</span><span class="special">!</span>
</pre>
<p>
The short answer is: "you can't". This is not a Boost.Python limitation
so much as a limitation of C++. The problem is that a Python function is
actually data, and the only way of associating data with a C++ function pointer
is to store it in a static variable of the function. The problem with that
is that you can only associate one piece of data with every C++ function,
and we have no way of compiling a new C++ function on-the-fly for every Python
function you decide to pass to <code class="computeroutput"><span class="identifier">foo</span></code>.
In other words, this could work if the C++ function is always going to invoke
the <span class="emphasis"><em>same</em></span> Python function, but you probably don't want
that.
</p>
<p>
If you have the luxury of changing the C++ code you're wrapping, pass it
an <code class="computeroutput"><span class="identifier">object</span></code> instead and call
that; the overloaded function call operator will invoke the Python function
you pass it behind the <code class="computeroutput"><span class="identifier">object</span></code>.
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="support.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="faq/i_m_getting_the_attempt_to_retur.html"><img src="images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,42 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Compilation takes too much time and eats too much memory! What can I do to make it faster?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="how_can_i_wrap_a_function_which0.html" title="How can I wrap a function which needs to take ownership of a raw pointer?">
<link rel="next" href="how_do_i_create_sub_packages_usi.html" title="How do I create sub-packages using Boost.Python?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_can_i_wrap_a_function_which0.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_do_i_create_sub_packages_usi.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.compilation_takes_too_much_time_"></a><a class="link" href="compilation_takes_too_much_time_.html" title="Compilation takes too much time and eats too much memory! What can I do to make it faster?">Compilation takes
too much time and eats too much memory! What can I do to make it faster?</a>
</h3></div></div></div>
<p>
Please refer to the <code class="computeroutput"><span class="identifier">Reducing</span> <span class="identifier">Compiling</span> <span class="identifier">Time</span></code>
section in the <a href="../tutorial/index.html" target="_top">Tutorial</a>.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_can_i_wrap_a_function_which0.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_do_i_create_sub_packages_usi.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,93 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Does Boost.Python work with Mac OS X?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="why_doesn_t_my_operator_work.html" title="Why doesn't my *= operator work?">
<link rel="next" href="how_can_i_find_the_existing_pyob.html" title="How can I find the existing PyObject that holds a C++ object?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_doesn_t_my_operator_work.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_can_i_find_the_existing_pyob.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.does_boost_python_work_with_mac_"></a><a class="link" href="does_boost_python_work_with_mac_.html" title="Does Boost.Python work with Mac OS X?">Does Boost.Python
work with Mac OS X?</a>
</h3></div></div></div>
<p>
It is known to work under 10.2.8 and 10.3 using Apple's gcc 3.3 compiler:
</p>
<pre class="programlisting"><span class="identifier">gcc</span> <span class="special">(</span><span class="identifier">GCC</span><span class="special">)</span> <span class="number">3.3</span> <span class="number">20030304</span> <span class="special">(</span><span class="identifier">Apple</span> <span class="identifier">Computer</span><span class="special">,</span> <span class="identifier">Inc</span><span class="special">.</span> <span class="identifier">build</span> <span class="number">1493</span><span class="special">)</span></pre>
<p>
Under 10.2.8 get the August 2003 gcc update (free at <a href="http://connect.apple.com" target="_top">http://connect.apple.com</a>).
Under 10.3 get the Xcode Tools v1.0 (also free).
</p>
<p>
Python 2.3 is required. The Python that ships with 10.3 is fine. Under 10.2.8
use these commands to install Python as a framework:
</p>
<pre class="programlisting"><span class="special">./</span><span class="identifier">configure</span> <span class="special">--</span><span class="identifier">enable</span><span class="special">-</span><span class="identifier">framework</span>
<span class="identifier">make</span>
<span class="identifier">make</span> <span class="identifier">frameworkinstall</span></pre>
<p>
The last command requires root privileges because the target directory is
<code class="computeroutput"><span class="special">/</span><span class="identifier">Library</span><span class="special">/</span><span class="identifier">Frameworks</span><span class="special">/</span><span class="identifier">Python</span><span class="special">.</span><span class="identifier">framework</span><span class="special">/</span><span class="identifier">Versions</span><span class="special">/</span><span class="number">2.3</span></code>. However,
the installation does not interfere with the Python version that ships with
10.2.8.
</p>
<p>
It is also crucial to increase the <code class="computeroutput"><span class="identifier">stacksize</span></code>
before starting compilations, e.g.:
</p>
<pre class="programlisting"><span class="identifier">limit</span> <span class="identifier">stacksize</span> <span class="number">8192</span><span class="identifier">k</span></pre>
<p>
If the <code class="computeroutput"><span class="identifier">stacksize</span></code> is too small
the build might crash with internal compiler errors.
</p>
<p>
Sometimes Apple's compiler exhibits a bug by printing an error like the following
while compiling a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">your_type</span><span class="special">&gt;</span></code>
template instantiation:
</p>
<pre class="programlisting"><span class="special">.../</span><span class="identifier">inheritance</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">:</span><span class="number">44</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">cannot</span>
<span class="keyword">dynamic_cast</span> <span class="error">`</span><span class="identifier">p</span><span class="char">' (of type `struct cctbx::boost_python::&lt;unnamed&gt;::add_pair*
'</span><span class="special">)</span> <span class="identifier">to</span> <span class="identifier">type</span> <span class="error">`</span><span class="keyword">void</span><span class="special">*</span><span class="error">'</span> <span class="special">(</span><span class="identifier">source</span> <span class="identifier">type</span> <span class="identifier">is</span> <span class="keyword">not</span> <span class="identifier">polymorphic</span><span class="special">)</span>
</pre>
<p>
We do not know a general workaround, but if the definition of <code class="computeroutput"><span class="identifier">your_type</span></code> can be modified the following
was found to work in all cases encountered so far:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">your_type</span>
<span class="special">{</span>
<span class="comment">// before defining any member data</span>
<span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">__MACH__</span><span class="special">)</span> <span class="special">&amp;</span><span class="identifier">amp</span><span class="special">;&amp;</span><span class="identifier">amp</span><span class="special">;</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">__APPLE_CC__</span><span class="special">)</span> <span class="special">&amp;</span><span class="identifier">amp</span><span class="special">;&amp;</span><span class="identifier">amp</span><span class="special">;</span> <span class="identifier">__APPLE_CC__</span> <span class="special">==</span> <span class="number">1493</span>
<span class="keyword">bool</span> <span class="identifier">dummy_</span><span class="special">;</span>
<span class="preprocessor">#endif</span>
<span class="comment">// now your member data, e.g.</span>
<span class="keyword">double</span> <span class="identifier">x</span><span class="special">;</span>
<span class="keyword">int</span> <span class="identifier">j</span><span class="special">;</span>
<span class="comment">// etc.</span>
<span class="special">};</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_doesn_t_my_operator_work.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_can_i_find_the_existing_pyob.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,77 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>error C2064: term does not evaluate to a function taking 2 arguments</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="how_do_i_create_sub_packages_usi.html" title="How do I create sub-packages using Boost.Python?">
<link rel="next" href="how_can_i_automatically_convert_.html" title="How can I automatically convert my custom string type to and from a Python string?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_do_i_create_sub_packages_usi.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_can_i_automatically_convert_.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.error_c2064_term_does_not_evalua"></a><a class="link" href="error_c2064_term_does_not_evalua.html" title="error C2064: term does not evaluate to a function taking 2 arguments">error C2064: term
does not evaluate to a function taking 2 arguments</a>
</h3></div></div></div>
<p>
<span class="emphasis"><em>Niall Douglas provides these notes:</em></span>
</p>
<p>
If you see Microsoft Visual C++ 7.1 (MS Visual Studio .NET 2003) issue an
error message like the following it is most likely due to a bug in the compiler:
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">\</span><span class="identifier">boost</span><span class="special">\</span><span class="identifier">python</span><span class="special">\</span><span class="identifier">detail</span><span class="special">\</span><span class="identifier">invoke</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">(</span><span class="number">76</span><span class="special">):</span>
<span class="identifier">error</span> <span class="identifier">C2064</span><span class="special">:</span> <span class="identifier">term</span> <span class="identifier">does</span> <span class="keyword">not</span> <span class="identifier">evaluate</span> <span class="identifier">to</span> <span class="identifier">a</span> <span class="identifier">function</span> <span class="identifier">taking</span> <span class="number">2</span> <span class="identifier">arguments</span><span class="error">"</span>
</pre>
<p>
This message is triggered by code like the following:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="keyword">class</span> <span class="identifier">FXThread</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">bool</span> <span class="identifier">setAutoDelete</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">doso</span><span class="special">)</span> <span class="keyword">throw</span><span class="special">();</span>
<span class="special">};</span>
<span class="keyword">void</span> <span class="identifier">Export_FXThread</span><span class="special">()</span>
<span class="special">{</span>
<span class="identifier">class_</span><span class="special">&lt;</span> <span class="identifier">FXThread</span> <span class="special">&gt;(</span><span class="string">"FXThread"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"setAutoDelete"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">amp</span><span class="special">;</span><span class="identifier">FXThread</span><span class="special">::</span><span class="identifier">setAutoDelete</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
The bug is related to the <code class="computeroutput"><span class="keyword">throw</span><span class="special">()</span></code> modifier. As a workaround cast off the
modifier. E.g.:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"setAutoDelete"</span><span class="special">,</span> <span class="special">(</span><span class="keyword">bool</span> <span class="special">(</span><span class="identifier">FXThread</span><span class="special">::*)(</span><span class="keyword">bool</span><span class="special">))</span> <span class="special">&amp;</span><span class="identifier">FXThread</span><span class="special">::</span><span class="identifier">setAutoDelete</span><span class="special">)</span>
</pre>
<p>
(The bug has been reported to Microsoft.)
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_do_i_create_sub_packages_usi.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_can_i_automatically_convert_.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,94 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>fatal error C1204:Compiler limit:internal structure overflow</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="how_can_i_wrap_functions_which_t.html" title="How can I wrap functions which take C++ containers as arguments?">
<link rel="next" href="how_do_i_debug_my_python_extensi.html" title="How do I debug my Python extensions?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_can_i_wrap_functions_which_t.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_do_i_debug_my_python_extensi.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.fatal_error_c1204_compiler_limit"></a><a class="link" href="fatal_error_c1204_compiler_limit.html" title="fatal error C1204:Compiler limit:internal structure overflow">fatal error C1204:Compiler
limit:internal structure overflow</a>
</h3></div></div></div>
<p>
<span class="bold"><strong>Q:</strong></span> <span class="emphasis"><em>I get this error message when
compiling a large source file. What can I do?</em></span>
</p>
<p>
<span class="bold"><strong>A:</strong></span> You have two choices:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
Upgrade your compiler (preferred)
</li>
<li class="listitem">
Break your source file up into multiple translation units.
<p>
<code class="computeroutput"><span class="identifier">my_module</span><span class="special">.</span><span class="identifier">cpp</span></code>:
</p>
<pre class="programlisting"><span class="special">...</span>
<span class="keyword">void</span> <span class="identifier">more_of_my_module</span><span class="special">();</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">my_module</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"bar"</span><span class="special">,</span> <span class="identifier">bar</span><span class="special">);</span>
<span class="special">...</span>
<span class="identifier">more_of_my_module</span><span class="special">();</span>
<span class="special">}</span>
</pre>
<p>
<code class="computeroutput"><span class="identifier">more_of_my_module</span><span class="special">.</span><span class="identifier">cpp</span></code>:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">more_of_my_module</span><span class="special">()</span>
<span class="special">{</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"baz"</span><span class="special">,</span> <span class="identifier">baz</span><span class="special">);</span>
<span class="special">...</span>
<span class="special">}</span>
</pre>
<p>
If you find that a <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;...&gt;</span></code> declaration can't fit in
a single source file without triggering the error, you can always pass
a reference to the <code class="computeroutput"><span class="identifier">class_</span></code>
object to a function in another source file, and call some of its member
functions (e.g. <code class="computeroutput"><span class="special">.</span><span class="identifier">def</span><span class="special">(...)</span></code>) in the auxilliary source file:
</p>
<p>
<code class="computeroutput"><span class="identifier">more_of_my_class</span><span class="special">.</span><span class="identifier">cpp</span></code>:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">more_of_my_class</span><span class="special">(</span><span class="keyword">class</span><span class="special">&amp;</span><span class="identifier">lt</span><span class="special">;</span><span class="identifier">my_class</span><span class="special">&amp;</span><span class="identifier">gt</span><span class="special">;&amp;</span><span class="identifier">amp</span><span class="special">;</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">x</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"baz"</span><span class="special">,</span> <span class="identifier">baz</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"xx"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">my_class</span><span class="special">::</span><span class="identifier">get_xx</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">my_class</span><span class="special">::</span><span class="identifier">set_xx</span><span class="special">)</span>
<span class="special">;</span>
<span class="special">...</span>
<span class="special">}</span>
</pre>
</li>
</ol></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_can_i_wrap_functions_which_t.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_do_i_debug_my_python_extensi.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,146 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>How can I automatically convert my custom string type to and from a Python string?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="error_c2064_term_does_not_evalua.html" title="error C2064: term does not evaluate to a function taking 2 arguments">
<link rel="next" href="why_is_my_automatic_to_python_co.html" title="Why is my automatic to-python conversion not being found?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="error_c2064_term_does_not_evalua.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="why_is_my_automatic_to_python_co.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.how_can_i_automatically_convert_"></a><a class="link" href="how_can_i_automatically_convert_.html" title="How can I automatically convert my custom string type to and from a Python string?">How can I automatically
convert my custom string type to and from a Python string?</a>
</h3></div></div></div>
<p>
<span class="emphasis"><em>Ralf W. Grosse-Kunstleve provides these notes:</em></span>
</p>
<p>
Below is a small, self-contained demo extension module that shows how to
do this. Here is the corresponding trivial test:
</p>
<pre class="programlisting"><span class="identifier">import</span> <span class="identifier">custom_string</span>
<span class="identifier">assert</span> <span class="identifier">custom_string</span><span class="special">.</span><span class="identifier">hello</span><span class="special">()</span> <span class="special">==</span> <span class="string">"Hello world."</span>
<span class="identifier">assert</span> <span class="identifier">custom_string</span><span class="special">.</span><span class="identifier">size</span><span class="special">(</span><span class="string">"california"</span><span class="special">)</span> <span class="special">==</span> <span class="number">10</span>
</pre>
<p>
If you look at the code you will find:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
A custom <code class="computeroutput"><span class="identifier">to_python</span></code> converter
(easy): <code class="computeroutput"><span class="identifier">custom_string_to_python_str</span></code>
</li>
<li class="listitem">
A custom lvalue converter (needs more code): <code class="computeroutput"><span class="identifier">custom_string_from_python_str</span></code>
</li>
</ul></div>
<p>
The custom converters are registered in the global Boost.Python registry
near the top of the module initialization function. Once flow control has
passed through the registration code the automatic conversions from and to
Python strings will work in any module imported in the same process.
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">to_python_converter</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">namespace</span> <span class="identifier">sandbox</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="special">{</span>
<span class="keyword">class</span> <span class="identifier">custom_string</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="identifier">custom_string</span><span class="special">()</span> <span class="special">{}</span>
<span class="identifier">custom_string</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">value</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">value_</span><span class="special">(</span><span class="identifier">value</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">value</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">value_</span><span class="special">;</span> <span class="special">}</span>
<span class="keyword">private</span><span class="special">:</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">value_</span><span class="special">;</span>
<span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">custom_string_to_python_str</span>
<span class="special">{</span>
<span class="keyword">static</span> <span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">custom_string</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">s</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">incref</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">value</span><span class="special">()).</span><span class="identifier">ptr</span><span class="special">());</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">custom_string_from_python_str</span>
<span class="special">{</span>
<span class="identifier">custom_string_from_python_str</span><span class="special">()</span>
<span class="special">{</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">converter</span><span class="special">::</span><span class="identifier">registry</span><span class="special">::</span><span class="identifier">push_back</span><span class="special">(</span>
<span class="special">&amp;</span><span class="identifier">convertible</span><span class="special">,</span>
<span class="special">&amp;</span><span class="identifier">construct</span><span class="special">,</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">type_id</span><span class="special">&lt;</span><span class="identifier">custom_string</span><span class="special">&gt;());</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="keyword">void</span><span class="special">*</span> <span class="identifier">convertible</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">obj_ptr</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">if</span> <span class="special">(!</span><span class="identifier">PyString_Check</span><span class="special">(</span><span class="identifier">obj_ptr</span><span class="special">))</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="keyword">return</span> <span class="identifier">obj_ptr</span><span class="special">;</span>
<span class="special">}</span>
<span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">construct</span><span class="special">(</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">obj_ptr</span><span class="special">,</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">converter</span><span class="special">::</span><span class="identifier">rvalue_from_python_stage1_data</span><span class="special">*</span> <span class="identifier">data</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">PyString_AsString</span><span class="special">(</span><span class="identifier">obj_ptr</span><span class="special">);</span>
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">value</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">throw_error_already_set</span><span class="special">();</span>
<span class="keyword">void</span><span class="special">*</span> <span class="identifier">storage</span> <span class="special">=</span> <span class="special">(</span>
<span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">converter</span><span class="special">::</span><span class="identifier">rvalue_from_python_storage</span><span class="special">&lt;</span><span class="identifier">custom_string</span><span class="special">&gt;*)</span>
<span class="identifier">data</span><span class="special">)-&gt;</span><span class="identifier">storage</span><span class="special">.</span><span class="identifier">bytes</span><span class="special">;</span>
<span class="keyword">new</span> <span class="special">(</span><span class="identifier">storage</span><span class="special">)</span> <span class="identifier">custom_string</span><span class="special">(</span><span class="identifier">value</span><span class="special">);</span>
<span class="identifier">data</span><span class="special">-&gt;</span><span class="identifier">convertible</span> <span class="special">=</span> <span class="identifier">storage</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">};</span>
<span class="identifier">custom_string</span> <span class="identifier">hello</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">custom_string</span><span class="special">(</span><span class="string">"Hello world."</span><span class="special">);</span> <span class="special">}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">(</span><span class="identifier">custom_string</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">s</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">value</span><span class="special">().</span><span class="identifier">size</span><span class="special">();</span> <span class="special">}</span>
<span class="keyword">void</span> <span class="identifier">init_module</span><span class="special">()</span>
<span class="special">{</span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">to_python_converter</span><span class="special">&lt;</span>
<span class="identifier">custom_string</span><span class="special">,</span>
<span class="identifier">custom_string_to_python_str</span><span class="special">&gt;();</span>
<span class="identifier">custom_string_from_python_str</span><span class="special">();</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"hello"</span><span class="special">,</span> <span class="identifier">hello</span><span class="special">);</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"size"</span><span class="special">,</span> <span class="identifier">size</span><span class="special">);</span>
<span class="special">}</span>
<span class="special">}}</span> <span class="comment">// namespace sandbox::&lt;anonymous&gt;</span>
<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">custom_string</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">sandbox</span><span class="special">::</span><span class="identifier">init_module</span><span class="special">();</span>
<span class="special">}</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="error_c2064_term_does_not_evalua.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="why_is_my_automatic_to_python_co.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,103 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>How can I find the existing PyObject that holds a C++ object?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="does_boost_python_work_with_mac_.html" title="Does Boost.Python work with Mac OS X?">
<link rel="next" href="how_can_i_wrap_a_function_which0.html" title="How can I wrap a function which needs to take ownership of a raw pointer?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="does_boost_python_work_with_mac_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_can_i_wrap_a_function_which0.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.how_can_i_find_the_existing_pyob"></a><a class="link" href="how_can_i_find_the_existing_pyob.html" title="How can I find the existing PyObject that holds a C++ object?">How can I find
the existing PyObject that holds a C++ object?</a>
</h3></div></div></div>
<div class="blockquote"><blockquote class="blockquote"><p>
"I am wrapping a function that always returns a pointer to an already-held
C++ object."
</p></blockquote></div>
<p>
One way to do that is to hijack the mechanisms used for wrapping a class
with virtual functions. If you make a wrapper class with an initial PyObject*
constructor argument and store that PyObject* as "self", you can
get back to it by casting down to that wrapper type in a thin wrapper function.
For example:
</p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">X</span> <span class="special">{</span> <span class="identifier">X</span><span class="special">(</span><span class="keyword">int</span><span class="special">);</span> <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">X</span><span class="special">();</span> <span class="special">...</span> <span class="special">};</span>
<span class="identifier">X</span><span class="special">*</span> <span class="identifier">f</span><span class="special">();</span> <span class="comment">// known to return Xs that are managed by Python objects</span>
<span class="comment">// wrapping code</span>
<span class="keyword">struct</span> <span class="identifier">X_wrap</span> <span class="special">:</span> <span class="identifier">X</span>
<span class="special">{</span>
<span class="identifier">X_wrap</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">v</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">self</span><span class="special">(</span><span class="identifier">self</span><span class="special">),</span> <span class="identifier">X</span><span class="special">(</span><span class="identifier">v</span><span class="special">)</span> <span class="special">{}</span>
<span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">self</span><span class="special">;</span>
<span class="special">};</span>
<span class="identifier">handle</span><span class="special">&lt;&gt;</span> <span class="identifier">f_wrap</span><span class="special">()</span>
<span class="special">{</span>
<span class="identifier">X_wrap</span><span class="special">*</span> <span class="identifier">xw</span> <span class="special">=</span> <span class="keyword">dynamic_cast</span><span class="special">&lt;</span><span class="identifier">X_wrap</span><span class="special">*&gt;(</span><span class="identifier">f</span><span class="special">());</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">xw</span> <span class="special">!=</span> <span class="number">0</span><span class="special">);</span>
<span class="keyword">return</span> <span class="identifier">handle</span><span class="special">&lt;&gt;(</span><span class="identifier">borrowed</span><span class="special">(</span><span class="identifier">xw</span><span class="special">-&gt;</span><span class="identifier">self</span><span class="special">));</span>
<span class="special">}</span>
<span class="special">...</span>
<span class="identifier">def</span><span class="special">(</span><span class="string">"f"</span><span class="special">,</span> <span class="identifier">f_wrap</span><span class="special">());</span>
<span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">,</span><span class="identifier">X_wrap</span><span class="special">,</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">noncopyable</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">,</span> <span class="identifier">init</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;())</span>
<span class="special">...</span>
<span class="special">;</span>
</pre>
<p>
Of course, if X has no virtual functions you'll have to use <code class="computeroutput"><span class="keyword">static_cast</span></code> instead of <code class="computeroutput"><span class="keyword">dynamic_cast</span></code>
with no runtime check that it's valid. This approach also only works if the
<code class="computeroutput"><span class="identifier">X</span></code> object was constructed
from Python, because <code class="computeroutput"><span class="identifier">X</span></code>s constructed
from C++ are of course never <code class="computeroutput"><span class="identifier">X_wrap</span></code>
objects.
</p>
<p>
Another approach to this requires you to change your C++ code a bit; if that's
an option for you it might be a better way to go. work we've been meaning
to get to anyway. When a <code class="computeroutput"><span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span></code>
is converted from Python, the shared_ptr actually manages a reference to
the containing Python object. When a shared_ptr&lt;X&gt; is converted back
to Python, the library checks to see if it's one of those "Python object
managers" and if so just returns the original Python object. So you
could just write <code class="computeroutput"><span class="identifier">object</span><span class="special">(</span><span class="identifier">p</span><span class="special">)</span></code> to get
the Python object back. To exploit this you'd have to be able to change the
C++ code you're wrapping so that it deals with shared_ptr instead of raw
pointers.
</p>
<p>
There are other approaches too. The functions that receive the Python object
that you eventually want to return could be wrapped with a thin wrapper that
records the correspondence between the object address and its containing
Python object, and you could have your f_wrap function look in that mapping
to get the Python object out.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="does_boost_python_work_with_mac_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_can_i_wrap_a_function_which0.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,86 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>How can I wrap a function which needs to take ownership of a raw pointer?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="how_can_i_find_the_existing_pyob.html" title="How can I find the existing PyObject that holds a C++ object?">
<link rel="next" href="compilation_takes_too_much_time_.html" title="Compilation takes too much time and eats too much memory! What can I do to make it faster?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_can_i_find_the_existing_pyob.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="compilation_takes_too_much_time_.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.how_can_i_wrap_a_function_which0"></a><a class="link" href="how_can_i_wrap_a_function_which0.html" title="How can I wrap a function which needs to take ownership of a raw pointer?">How can I wrap
a function which needs to take ownership of a raw pointer?</a>
</h3></div></div></div>
<p>
<span class="bold"><strong>Q:</strong></span> Part of an API that I'm wrapping goes
something like this:
</p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">A</span> <span class="special">{};</span> <span class="keyword">struct</span> <span class="identifier">B</span> <span class="special">{</span> <span class="keyword">void</span> <span class="identifier">add</span><span class="special">(</span> <span class="identifier">A</span><span class="special">*</span> <span class="special">);</span> <span class="special">}</span>
<span class="identifier">where</span> <span class="identifier">B</span><span class="special">::</span><span class="identifier">add</span><span class="special">()</span> <span class="identifier">takes</span> <span class="identifier">ownership</span> <span class="identifier">of</span> <span class="identifier">the</span> <span class="identifier">pointer</span> <span class="identifier">passed</span> <span class="identifier">to</span> <span class="identifier">it</span><span class="special">.</span>
</pre>
<p>
However:
</p>
<pre class="programlisting"><span class="identifier">a</span> <span class="special">=</span> <span class="identifier">mod</span><span class="special">.</span><span class="identifier">A</span><span class="special">()</span>
<span class="identifier">b</span> <span class="special">=</span> <span class="identifier">mod</span><span class="special">.</span><span class="identifier">B</span><span class="special">()</span>
<span class="identifier">b</span><span class="special">.</span><span class="identifier">add</span><span class="special">(</span> <span class="identifier">a</span> <span class="special">)</span>
<span class="identifier">del</span> <span class="identifier">a</span>
<span class="identifier">del</span> <span class="identifier">b</span>
<span class="preprocessor"># python</span> <span class="identifier">interpreter</span> <span class="identifier">crashes</span>
<span class="preprocessor"># later</span> <span class="identifier">due</span> <span class="identifier">to</span> <span class="identifier">memory</span> <span class="identifier">corruption</span><span class="special">.</span>
</pre>
<p>
Even binding the lifetime of a to b via <code class="computeroutput"><span class="identifier">with_custodian_and_ward</span></code>
doesn't prevent the python object a from ultimately trying to delete the
object it's pointing to. Is there a way to accomplish a 'transfer-of-ownership'
of a wrapped C++ object?
</p>
<p>
--Bruce Lowery
</p>
<p>
Yes: Make sure the C++ object is held by auto_ptr:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">auto_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"A"</span><span class="special">)</span>
<span class="special">...</span>
<span class="special">;</span>
</pre>
<p>
Then make a thin wrapper function which takes an auto_ptr parameter:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">b_insert</span><span class="special">(</span><span class="identifier">B</span> <span class="special">&amp;</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">auto_ptr</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span> <span class="identifier">a</span><span class="special">)</span>
<span class="special">{</span>
<span class="identifier">b</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">a</span><span class="special">.</span><span class="identifier">get</span><span class="special">());</span>
<span class="identifier">a</span><span class="special">.</span><span class="identifier">release</span><span class="special">();</span>
<span class="special">}</span>
</pre>
<p>
Wrap that as B.add. Note that pointers returned via <code class="computeroutput"><span class="identifier">manage_new_object</span></code>
will also be held by <code class="computeroutput"><span class="identifier">auto_ptr</span></code>,
so this transfer-of-ownership will also work correctly.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_can_i_find_the_existing_pyob.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="compilation_takes_too_much_time_.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,120 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>How can I wrap functions which take C++ containers as arguments?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="is_return_internal_reference_eff.html" title="Is return_internal_reference efficient?">
<link rel="next" href="fatal_error_c1204_compiler_limit.html" title="fatal error C1204:Compiler limit:internal structure overflow">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="is_return_internal_reference_eff.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="fatal_error_c1204_compiler_limit.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.how_can_i_wrap_functions_which_t"></a><a class="link" href="how_can_i_wrap_functions_which_t.html" title="How can I wrap functions which take C++ containers as arguments?">How can I wrap
functions which take C++ containers as arguments?</a>
</h3></div></div></div>
<p>
Ralf W. Grosse-Kunstleve provides these notes:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<p>
Using the regular <code class="computeroutput"><span class="identifier">class_</span><span class="special">&lt;&gt;</span></code> wrapper:
</p>
<pre class="programlisting"><span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="special">&gt;(</span><span class="string">"std_vector_double"</span><span class="special">)</span>
<span class="special">.</span><span class="identifier">def</span><span class="special">(...)</span>
<span class="special">...</span>
<span class="special">;</span>
</pre>
This can be moved to a template so that several types (<code class="computeroutput"><span class="keyword">double</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>,
<code class="computeroutput"><span class="keyword">long</span></code>, etc.) can be wrapped
with the same code. This technique is used in the file <code class="computeroutput"><span class="identifier">scitbx</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">scitbx</span><span class="special">/</span><span class="identifier">array_family</span><span class="special">/</span><span class="identifier">boost_python</span><span class="special">/</span><span class="identifier">flex_wrapper</span><span class="special">.</span><span class="identifier">h</span></code> in the "scitbx" package.
The file could easily be modified for wrapping <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;&gt;</span></code> instantiations. This type of
C++/Python binding is most suitable for containers that may contain a
large number of elements (&gt;10000).
</li>
<li class="listitem">
<p>
Using custom rvalue converters. Boost.Python "rvalue converters"
match function signatures such as:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">array</span><span class="special">);</span> <span class="comment">// pass by const-reference</span>
<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">array</span><span class="special">);</span> <span class="comment">// pass by value</span>
</pre>
Some custom rvalue converters are implemented in the file <code class="computeroutput"><span class="identifier">scitbx</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">scitbx</span><span class="special">/</span><span class="identifier">boost_python</span><span class="special">/</span><span class="identifier">container_conversions</span><span class="special">.</span><span class="identifier">h</span></code> This code can be used to convert
from C++ container types such as <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;&gt;</span></code> or <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;&gt;</span></code> to Python tuples and vice versa.
A few simple examples can be found in the file <code class="computeroutput"><span class="identifier">scitbx</span><span class="special">/</span><span class="identifier">array_family</span><span class="special">/</span><span class="identifier">boost_python</span><span class="special">/</span><span class="identifier">regression_test_module</span><span class="special">.</span><span class="identifier">cpp</span></code>
Automatic C++ container &lt;-&gt; Python tuple conversions are most suitable
for containers of moderate size. These converters generate significantly
less object code compared to alternative 1 above.
</li>
</ol></div>
<p>
A disadvantage of using alternative 2 is that operators such as arithmetic
+,-,*,/,% are not available. It would be useful to have custom rvalue converters
that convert to a "math_array" type instead of tuples. This is
currently not implemented but is possible within the framework of Boost.Python
V2 as it will be released in the next couple of weeks. [ed.: this was posted
on 2002/03/10]
</p>
<p>
It would also be useful to also have "custom lvalue converters"
such as <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;&gt;</span></code>
&lt;-&gt; Python list. These converters would support the modification of
the Python list from C++. For example:
</p>
<p>
C++:
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="special">&amp;</span><span class="identifier">array</span><span class="special">)</span>
<span class="special">{</span>
<span class="keyword">for</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">i</span><span class="special">=</span><span class="number">0</span><span class="special">;</span><span class="identifier">i</span><span class="special">&amp;</span><span class="identifier">lt</span><span class="special">;</span><span class="identifier">array</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span><span class="identifier">i</span><span class="special">++)</span> <span class="special">{</span>
<span class="identifier">array</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">*=</span> <span class="number">2</span><span class="special">;</span>
<span class="special">}</span>
<span class="special">}</span>
</pre>
<p>
Python:
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">l</span> <span class="special">=</span> <span class="special">[</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">]</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">l</span><span class="special">)</span>
<span class="special">&gt;&gt;&gt;</span> <span class="keyword">print</span> <span class="identifier">l</span>
<span class="special">[</span><span class="number">2</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">6</span><span class="special">]</span>
</pre>
<p>
Custom lvalue converters require changes to the Boost.Python core library
and are currently not available.
</p>
<p>
P.S.:
</p>
<p>
The "scitbx" files referenced above are available via anonymous
CVS:
</p>
<pre class="programlisting"><span class="identifier">cvs</span> <span class="special">-</span><span class="identifier">d</span><span class="special">:</span><span class="identifier">pserver</span><span class="special">:</span><span class="identifier">anonymous</span><span class="error">@</span><span class="identifier">cvs</span><span class="special">.</span><span class="identifier">cctbx</span><span class="special">.</span><span class="identifier">sourceforge</span><span class="special">.</span><span class="identifier">net</span><span class="special">:/</span><span class="identifier">cvsroot</span><span class="special">/</span><span class="identifier">cctbx</span> <span class="identifier">login</span>
<span class="identifier">cvs</span> <span class="special">-</span><span class="identifier">d</span><span class="special">:</span><span class="identifier">pserver</span><span class="special">:</span><span class="identifier">anonymous</span><span class="error">@</span><span class="identifier">cvs</span><span class="special">.</span><span class="identifier">cctbx</span><span class="special">.</span><span class="identifier">sourceforge</span><span class="special">.</span><span class="identifier">net</span><span class="special">:/</span><span class="identifier">cvsroot</span><span class="special">/</span><span class="identifier">cctbx</span> <span class="identifier">co</span> <span class="identifier">scitbx</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="is_return_internal_reference_eff.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="fatal_error_c1204_compiler_limit.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,41 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>How do I create sub-packages using Boost.Python?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="compilation_takes_too_much_time_.html" title="Compilation takes too much time and eats too much memory! What can I do to make it faster?">
<link rel="next" href="error_c2064_term_does_not_evalua.html" title="error C2064: term does not evaluate to a function taking 2 arguments">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="compilation_takes_too_much_time_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="error_c2064_term_does_not_evalua.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.how_do_i_create_sub_packages_usi"></a><a class="link" href="how_do_i_create_sub_packages_usi.html" title="How do I create sub-packages using Boost.Python?">How do I create
sub-packages using Boost.Python?</a>
</h3></div></div></div>
<p>
Please refer to the <code class="computeroutput"><span class="identifier">Creating</span> <span class="identifier">Packages</span></code> section in the <a href="../tutorial/index.html" target="_top">Tutorial</a>.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="compilation_takes_too_much_time_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="error_c2064_term_does_not_evalua.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,151 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>How do I debug my Python extensions?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="fatal_error_c1204_compiler_limit.html" title="fatal error C1204:Compiler limit:internal structure overflow">
<link rel="next" href="why_doesn_t_my_operator_work.html" title="Why doesn't my *= operator work?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="fatal_error_c1204_compiler_limit.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="why_doesn_t_my_operator_work.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.how_do_i_debug_my_python_extensi"></a><a class="link" href="how_do_i_debug_my_python_extensi.html" title="How do I debug my Python extensions?">How do I debug
my Python extensions?</a>
</h3></div></div></div>
<p>
Greg Burley gives the following answer for Unix GCC users:
</p>
<div class="blockquote"><blockquote class="blockquote">
<p>
Once you have created a boost python extension for your c++ library or
class, you may need to debug the code. Afterall this is one of the reasons
for wrapping the library in python. An expected side-effect or benefit
of using BPL is that debugging should be isolated to the c++ library that
is under test, given that python code is minimal and boost::python either
works or it doesn't. (ie. While errors can occur when the wrapping method
is invalid, most errors are caught by the compiler ;-).
</p>
<p>
The basic steps required to initiate a gdb session to debug a c++ library
via python are shown here. Note, however that you should start the gdb
session in the directory that contains your BPL my_ext.so module.
</p>
<pre class="programlisting"><span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="identifier">target</span> <span class="identifier">exec</span> <span class="identifier">python</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="identifier">run</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">my_ext</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="special">&gt;&gt;&gt;</span> <span class="special">[</span><span class="identifier">C</span><span class="special">-</span><span class="identifier">c</span><span class="special">]</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="keyword">break</span> <span class="identifier">MyClass</span><span class="special">::</span><span class="identifier">MyBuggyFunction</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="identifier">cont</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">pyobj</span> <span class="special">=</span> <span class="identifier">MyClass</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">pyobj</span><span class="special">.</span><span class="identifier">MyBuggyFunction</span><span class="special">()</span>
<span class="identifier">Breakpoint</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">MyClass</span><span class="special">::</span><span class="identifier">MyBuggyFunction</span> <span class="special">...</span>
<span class="identifier">Current</span> <span class="identifier">language</span><span class="special">:</span> <span class="keyword">auto</span><span class="special">;</span> <span class="identifier">currently</span> <span class="identifier">c</span><span class="special">++</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="keyword">do</span> <span class="identifier">debugging</span> <span class="identifier">stuff</span>
</pre>
</blockquote></div>
<p>
Greg's approach works even better using Emacs' "gdb" command, since
it will show you each line of source as you step through it.
</p>
<p>
On <span class="bold"><strong>Windows</strong></span>, my favorite debugging solution
is the debugger that comes with Microsoft Visual C++ 7. This debugger seems
to work with code generated by all versions of Microsoft and Metrowerks toolsets;
it's rock solid and "just works" without requiring any special
tricks from the user.
</p>
<p>
Raoul Gough has provided the following for gdb on Windows:
</p>
<div class="blockquote"><blockquote class="blockquote">
<p>
gdb support for Windows DLLs has improved lately, so it is now possible
to debug Python extensions using a few tricks. Firstly, you will need an
up-to-date gdb with support for minimal symbol extraction from a DLL. Any
gdb from version 6 onwards, or Cygwin gdb-20030214-1 and onwards should
do. A suitable release will have a section in the gdb.info file under Configuration
- Native - Cygwin Native - Non-debug DLL symbols. Refer to that info section
for more details of the procedures outlined here.
</p>
<p>
Secondly, it seems necessary to set a breakpoint in the Python interpreter,
rather than using ^C to break execution. A good place to set this breakpoint
is PyOS_Readline, which will stop execution immediately before reading
each interactive Python command. You have to let Python start once under
the debugger, so that it loads its own DLL, before you can set the breakpoint:
</p>
<pre class="programlisting"><span class="error">$</span> <span class="identifier">gdb</span> <span class="identifier">python</span>
<span class="identifier">GNU</span> <span class="identifier">gdb</span> <span class="number">2003</span><span class="special">-</span><span class="number">09</span><span class="special">-</span><span class="number">02</span><span class="special">-</span><span class="identifier">cvs</span> <span class="special">(</span><span class="identifier">cygwin</span><span class="special">-</span><span class="identifier">special</span><span class="special">)</span>
<span class="special">[...]</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="identifier">run</span>
<span class="identifier">Starting</span> <span class="identifier">program</span><span class="special">:</span> <span class="special">/</span><span class="identifier">cygdrive</span><span class="special">/</span><span class="identifier">c</span><span class="special">/</span><span class="identifier">Python22</span><span class="special">/</span><span class="identifier">python</span><span class="special">.</span><span class="identifier">exe</span>
<span class="identifier">Python</span> <span class="number">2.2</span><span class="special">.</span><span class="number">2</span> <span class="special">(#</span><span class="number">37</span><span class="special">,</span> <span class="identifier">Oct</span> <span class="number">14</span> <span class="number">2002</span><span class="special">,</span> <span class="number">17</span><span class="special">:</span><span class="number">02</span><span class="special">:</span><span class="number">34</span><span class="special">)</span> <span class="special">[</span><span class="identifier">MSC</span> <span class="number">32</span> <span class="identifier">bit</span> <span class="special">(</span><span class="identifier">Intel</span><span class="special">)]</span> <span class="identifier">on</span> <span class="identifier">win32</span>
<span class="identifier">Type</span> <span class="string">"help"</span><span class="special">,</span> <span class="string">"copyright"</span><span class="special">,</span> <span class="string">"credits"</span> <span class="keyword">or</span> <span class="string">"license"</span> <span class="keyword">for</span> <span class="identifier">more</span> <span class="identifier">information</span><span class="special">.</span>
<span class="special">&gt;&gt;&gt;</span> <span class="special">^</span><span class="identifier">Z</span>
<span class="identifier">Program</span> <span class="identifier">exited</span> <span class="identifier">normally</span><span class="special">.</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="keyword">break</span> <span class="special">*&amp;</span><span class="identifier">PyOS_Readline</span>
<span class="identifier">Breakpoint</span> <span class="number">1</span> <span class="identifier">at</span> <span class="number">0x1e04eff0</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="identifier">run</span>
<span class="identifier">Starting</span> <span class="identifier">program</span><span class="special">:</span> <span class="special">/</span><span class="identifier">cygdrive</span><span class="special">/</span><span class="identifier">c</span><span class="special">/</span><span class="identifier">Python22</span><span class="special">/</span><span class="identifier">python</span><span class="special">.</span><span class="identifier">exe</span>
<span class="identifier">Python</span> <span class="number">2.2</span><span class="special">.</span><span class="number">2</span> <span class="special">(#</span><span class="number">37</span><span class="special">,</span> <span class="identifier">Oct</span> <span class="number">14</span> <span class="number">2002</span><span class="special">,</span> <span class="number">17</span><span class="special">:</span><span class="number">02</span><span class="special">:</span><span class="number">34</span><span class="special">)</span> <span class="special">[</span><span class="identifier">MSC</span> <span class="number">32</span> <span class="identifier">bit</span> <span class="special">(</span><span class="identifier">Intel</span><span class="special">)]</span> <span class="identifier">on</span> <span class="identifier">win32</span>
<span class="identifier">Type</span> <span class="string">"help"</span><span class="special">,</span> <span class="string">"copyright"</span><span class="special">,</span> <span class="string">"credits"</span> <span class="keyword">or</span> <span class="string">"license"</span> <span class="keyword">for</span> <span class="identifier">more</span> <span class="identifier">information</span><span class="special">.</span>
<span class="identifier">Breakpoint</span> <span class="number">1</span><span class="special">,</span> <span class="number">0x1e04eff0</span> <span class="identifier">in</span> <span class="identifier">python22</span><span class="special">!</span><span class="identifier">PyOS_Readline</span> <span class="special">()</span>
<span class="identifier">from</span> <span class="special">/</span><span class="identifier">cygdrive</span><span class="special">/</span><span class="identifier">c</span><span class="special">/</span><span class="identifier">WINNT</span><span class="special">/</span><span class="identifier">system32</span><span class="special">/</span><span class="identifier">python22</span><span class="special">.</span><span class="identifier">dll</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="identifier">cont</span>
<span class="identifier">Continuing</span><span class="special">.</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">my_ext</span> <span class="identifier">import</span> <span class="special">*</span>
<span class="identifier">Breakpoint</span> <span class="number">1</span><span class="special">,</span> <span class="number">0x1e04eff0</span> <span class="identifier">in</span> <span class="identifier">python22</span><span class="special">!</span><span class="identifier">PyOS_Readline</span> <span class="special">()</span>
<span class="identifier">from</span> <span class="special">/</span><span class="identifier">cygdrive</span><span class="special">/</span><span class="identifier">c</span><span class="special">/</span><span class="identifier">WINNT</span><span class="special">/</span><span class="identifier">system32</span><span class="special">/</span><span class="identifier">python22</span><span class="special">.</span><span class="identifier">dll</span>
<span class="special">(</span><span class="identifier">gdb</span><span class="special">)</span> <span class="special">#</span> <span class="identifier">my_ext</span> <span class="identifier">now</span> <span class="identifier">loaded</span> <span class="special">(</span><span class="identifier">with</span> <span class="identifier">any</span> <span class="identifier">debugging</span> <span class="identifier">symbols</span> <span class="identifier">it</span> <span class="identifier">contains</span><span class="special">)</span>
</pre>
</blockquote></div>
<h3>
<a name="faq.how_do_i_debug_my_python_extensi.h0"></a>
<span class="phrase"><a name="faq.how_do_i_debug_my_python_extensi.debugging_extensions_through_boo"></a></span><a class="link" href="how_do_i_debug_my_python_extensi.html#faq.how_do_i_debug_my_python_extensi.debugging_extensions_through_boo">Debugging
extensions through Boost.Build</a>
</h3>
<p>
If you are launching your extension module tests with <a href="http://www.boost.org/build" target="_top">Boost.Build</a>
using the <code class="computeroutput"><span class="identifier">boost</span><span class="special">-</span><span class="identifier">python</span><span class="special">-</span><span class="identifier">runtest</span></code> rule, you can ask it to launch
your debugger for you by adding "--debugger=<span class="emphasis"><em>debugger</em></span>"
to your bjam command-line:
</p>
<pre class="programlisting"><span class="identifier">bjam</span> <span class="special">-</span><span class="identifier">sTOOLS</span><span class="special">=</span><span class="identifier">vc7</span><span class="special">.</span><span class="number">1</span> <span class="string">"--debugger=devenv /debugexe"</span> <span class="identifier">test</span>
<span class="identifier">bjam</span> <span class="special">-</span><span class="identifier">sTOOLS</span><span class="special">=</span><span class="identifier">gcc</span> <span class="special">-</span><span class="identifier">sPYTHON_LAUNCH</span><span class="special">=</span><span class="identifier">gdb</span> <span class="identifier">test</span>
</pre>
<p>
It can also be extremely useful to add the <code class="computeroutput"><span class="special">-</span><span class="identifier">d</span><span class="special">+</span><span class="number">2</span></code>
option when you run your test, because Boost.Build will then show you the
exact commands it uses to invoke it. This will invariably involve setting
up PYTHONPATH and other important environment variables such as LD_LIBRARY_PATH
which may be needed by your debugger in order to get things to work right.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="fatal_error_c1204_compiler_limit.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="why_doesn_t_my_operator_work.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,67 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>I'm getting the "attempt to return dangling reference" error. What am I doing wrong?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="next" href="is_return_internal_reference_eff.html" title="Is return_internal_reference efficient?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../faq.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="is_return_internal_reference_eff.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.i_m_getting_the_attempt_to_retur"></a><a class="link" href="i_m_getting_the_attempt_to_retur.html" title="I'm getting the &quot;attempt to return dangling reference&quot; error. What am I doing wrong?">I'm getting the
"attempt to return dangling reference" error. What am I doing wrong?</a>
</h3></div></div></div>
<p>
That exception is protecting you from causing a nasty crash. It usually happens
in response to some code like this:
</p>
<pre class="programlisting"><span class="identifier">period</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">get_floating_frequency</span><span class="special">()</span> <span class="keyword">const</span>
<span class="special">{</span>
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">call_method</span><span class="special">&lt;</span><span class="identifier">period</span> <span class="keyword">const</span> <span class="special">&amp;&gt;(</span>
<span class="identifier">m_self</span><span class="special">,</span><span class="string">"get_floating_frequency"</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
And you get:
</p>
<pre class="programlisting"><span class="identifier">ReferenceError</span><span class="special">:</span> <span class="identifier">Attempt</span> <span class="identifier">to</span> <span class="keyword">return</span> <span class="identifier">dangling</span> <span class="identifier">reference</span> <span class="identifier">to</span> <span class="identifier">object</span> <span class="identifier">of</span> <span class="identifier">type</span><span class="special">:</span>
<span class="keyword">class</span> <span class="identifier">period</span>
</pre>
<p>
In this case, the Python method invoked by <code class="computeroutput"><span class="identifier">call_method</span></code>
constructs a new Python object. You're trying to return a reference to a
C++ object (an instance of <code class="computeroutput"><span class="keyword">class</span> <span class="identifier">period</span></code>) contained within and owned by that
Python object. Because the called method handed back a brand new object,
the only reference to it is held for the duration of <code class="computeroutput"><span class="identifier">get_floating_frequency</span><span class="special">()</span></code> above. When the function returns, the Python
object will be destroyed, destroying the instance of <code class="computeroutput"><span class="keyword">class</span>
<span class="identifier">period</span></code>, and leaving the returned
reference dangling. That's already undefined behavior, and if you try to
do anything with that reference you're likely to cause a crash. Boost.Python
detects this situation at runtime and helpfully throws an exception instead
of letting you do that.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../faq.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="is_return_internal_reference_eff.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,60 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Is Boost.Python thread-aware/compatible with multiple interpreters?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="why_is_my_automatic_to_python_co.html" title="Why is my automatic to-python conversion not being found?">
<link rel="next" href="../glossary.html" title="Chapter&#160;6.&#160;Glossary">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_is_my_automatic_to_python_co.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../glossary.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.is_boost_python_thread_aware_com"></a><a class="link" href="is_boost_python_thread_aware_com.html" title="Is Boost.Python thread-aware/compatible with multiple interpreters?">Is Boost.Python
thread-aware/compatible with multiple interpreters?</a>
</h3></div></div></div>
<p>
<span class="emphasis"><em>Niall Douglas provides these notes:</em></span>
</p>
<p>
The quick answer to this is: no.
</p>
<p>
The longer answer is that it can be patched to be so, but it's complex. You
will need to add custom lock/unlock wrapping of every time your code enters
Boost.Python (particularly every virtual function override) plus heavily
modify <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">invoke</span><span class="special">.</span><span class="identifier">hpp</span></code> with custom unlock/lock wrapping of
every time Boost.Python enters your code. You must furthermore take care
to <span class="emphasis"><em>not</em></span> unlock/lock when Boost.Python is invoking iterator
changes via <code class="computeroutput"><span class="identifier">invoke</span><span class="special">.</span><span class="identifier">hpp</span></code>.
</p>
<p>
There is a patched <code class="computeroutput"><span class="identifier">invoke</span><span class="special">.</span><span class="identifier">hpp</span></code> posted
on the C++-SIG mailing list archives and you can find a real implementation
of all the machinery necessary to fully implement this in the TnFOX project
at <a href="http://sourceforge.net/projects/tnfox/" target="_top">this</a> SourceForge
project location.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_is_my_automatic_to_python_co.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../glossary.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,62 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Is return_internal_reference efficient?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="i_m_getting_the_attempt_to_retur.html" title="I'm getting the &quot;attempt to return dangling reference&quot; error. What am I doing wrong?">
<link rel="next" href="how_can_i_wrap_functions_which_t.html" title="How can I wrap functions which take C++ containers as arguments?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="i_m_getting_the_attempt_to_retur.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_can_i_wrap_functions_which_t.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.is_return_internal_reference_eff"></a><a class="link" href="is_return_internal_reference_eff.html" title="Is return_internal_reference efficient?">Is <code class="computeroutput"><span class="identifier">return_internal_reference</span></code> efficient?</a>
</h3></div></div></div>
<p>
<span class="bold"><strong>Q:</strong></span> /I have an object composed of 12 doubles.
A <code class="computeroutput"><span class="keyword">const</span><span class="special">&amp;</span></code>
to this object is returned by a member function of another class. From the
viewpoint of using the returned object in Python I do not care if I get a
copy or a reference to the returned object. In Boost.Python I have the choice
of using <code class="computeroutput"><span class="identifier">copy_const_reference</span></code>
or <code class="computeroutput"><span class="identifier">return_internal_reference</span></code>.
Are there considerations that would lead me to prefer one over the other,
such as size of generated code or memory overhead?/
</p>
<p>
<span class="bold"><strong>A:</strong></span> <code class="computeroutput"><span class="identifier">copy_const_reference</span></code>
will make an instance with storage for one of your objects, <code class="computeroutput"><span class="identifier">size</span> <span class="special">=</span> <span class="identifier">base_size</span> <span class="special">+</span> <span class="number">12</span> <span class="special">*</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="keyword">double</span><span class="special">)</span></code>.
<code class="computeroutput"><span class="identifier">return_internal_reference</span></code>
will make an instance with storage for a pointer to one of your objects,
<code class="computeroutput"><span class="identifier">size</span> <span class="special">=</span>
<span class="identifier">base_size</span> <span class="special">+</span>
<span class="keyword">sizeof</span><span class="special">(</span><span class="keyword">void</span><span class="special">*)</span></code>. However,
it will also create a weak reference object which goes in the source object's
weakreflist and a special callback object to manage the lifetime of the internally-referenced
object. My guess? <code class="computeroutput"><span class="identifier">copy_const_reference</span></code>
is your friend here, resulting in less overall memory use and less fragmentation,
also probably fewer total cycles.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="i_m_getting_the_attempt_to_retur.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="how_can_i_wrap_functions_which_t.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,63 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Why doesn't my *= operator work?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="how_do_i_debug_my_python_extensi.html" title="How do I debug my Python extensions?">
<link rel="next" href="does_boost_python_work_with_mac_.html" title="Does Boost.Python work with Mac OS X?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_do_i_debug_my_python_extensi.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="does_boost_python_work_with_mac_.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.why_doesn_t_my_operator_work"></a><a class="link" href="why_doesn_t_my_operator_work.html" title="Why doesn't my *= operator work?">Why doesn't my <code class="computeroutput"><span class="special">*=</span></code> operator work?</a>
</h3></div></div></div>
<p>
<span class="bold"><strong>Q:</strong></span> <span class="emphasis"><em>I have exported my class to
python, with many overloaded operators. it works fine for me except the
<code class="computeroutput"><span class="special">*=</span></code> operator. It always tells
me "can't multiply sequence with non int type". If I use <code class="computeroutput"><span class="identifier">p1</span><span class="special">.</span><span class="identifier">__imul__</span><span class="special">(</span><span class="identifier">p2</span><span class="special">)</span></code>
instead of <code class="computeroutput"><span class="identifier">p1</span> <span class="special">*=</span>
<span class="identifier">p2</span></code>, it successfully executes my
code. What's wrong with me?</em></span>
</p>
<p>
<span class="bold"><strong>A:</strong></span> There's nothing wrong with you. This
is a bug in Python 2.2. You can see the same effect in Pure Python (you can
learn a lot about what's happening in Boost.Python by playing with new-style
classes in Pure Python).
</p>
<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="keyword">class</span> <span class="identifier">X</span><span class="special">(</span><span class="identifier">object</span><span class="special">):</span>
<span class="special">...</span> <span class="identifier">def</span> <span class="identifier">__imul__</span><span class="special">(</span><span class="identifier">self</span><span class="special">,</span> <span class="identifier">x</span><span class="special">):</span>
<span class="special">...</span> <span class="identifier">print</span> <span class="char">'imul'</span>
<span class="special">...</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">=</span> <span class="identifier">X</span><span class="special">()</span>
<span class="special">&gt;&gt;&gt;</span> <span class="identifier">x</span> <span class="special">*=</span> <span class="number">1</span>
</pre>
<p>
To cure this problem, all you need to do is upgrade your Python to version
2.2.1 or later.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_do_i_debug_my_python_extensi.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="does_boost_python_work_with_mac_.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,67 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Why is my automatic to-python conversion not being found?</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python">
<link rel="up" href="../faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">
<link rel="prev" href="how_can_i_automatically_convert_.html" title="How can I automatically convert my custom string type to and from a Python string?">
<link rel="next" href="is_boost_python_thread_aware_com.html" title="Is Boost.Python thread-aware/compatible with multiple interpreters?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_can_i_automatically_convert_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="is_boost_python_thread_aware_com.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="faq.why_is_my_automatic_to_python_co"></a><a class="link" href="why_is_my_automatic_to_python_co.html" title="Why is my automatic to-python conversion not being found?">Why is my automatic
to-python conversion not being found?</a>
</h3></div></div></div>
<p>
<span class="emphasis"><em>Niall Douglas provides these notes:</em></span>
</p>
<p>
If you define custom converters similar to the ones shown above the <code class="computeroutput"><span class="identifier">def_readonly</span><span class="special">()</span></code>
and <code class="computeroutput"><span class="identifier">def_readwrite</span><span class="special">()</span></code>
member functions provided by <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">class_</span></code>
for direct access to your member data will not work as expected. This is
because <code class="computeroutput"><span class="identifier">def_readonly</span><span class="special">(</span><span class="string">"bar"</span><span class="special">,&amp;</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">bar</span><span class="special">)</span></code> is equivalent to:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"bar"</span><span class="special">,</span> <span class="identifier">make_getter</span><span class="special">(&amp;</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">bar</span><span class="special">,</span> <span class="identifier">return_internal_reference</span><span class="special">()))</span>
</pre>
<p>
Similarly, <code class="computeroutput"><span class="identifier">def_readwrite</span><span class="special">(</span><span class="string">"bar"</span><span class="special">,&amp;</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">bar</span><span class="special">)</span></code>
is equivalent to:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"bar"</span><span class="special">,</span> <span class="identifier">make_getter</span><span class="special">(&amp;</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">bar</span><span class="special">,</span> <span class="identifier">return_internal_reference</span><span class="special">()),</span>
<span class="identifier">make_setter</span><span class="special">(&amp;</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">bar</span><span class="special">,</span> <span class="identifier">return_internal_reference</span><span class="special">())</span>
</pre>
<p>
In order to define return value policies compatible with the custom conversions
replace <code class="computeroutput"><span class="identifier">def_readonly</span><span class="special">()</span></code>
and <code class="computeroutput"><span class="identifier">def_readwrite</span><span class="special">()</span></code>
by <code class="computeroutput"><span class="identifier">add_property</span><span class="special">()</span></code>.
E.g.:
</p>
<pre class="programlisting"><span class="special">.</span><span class="identifier">add_property</span><span class="special">(</span><span class="string">"bar"</span><span class="special">,</span> <span class="identifier">make_getter</span><span class="special">(&amp;</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">bar</span><span class="special">,</span> <span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">return_by_value</span><span class="special">&gt;()),</span>
<span class="identifier">make_setter</span><span class="special">(&amp;</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">bar</span><span class="special">,</span> <span class="identifier">return_value_policy</span><span class="special">&lt;</span><span class="identifier">return_by_value</span><span class="special">&gt;()))</span>
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="how_can_i_automatically_convert_.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../faq.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="is_boost_python_thread_aware_com.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,81 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;6.&#160;Glossary</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Boost.Python">
<link rel="up" href="index.html" title="Boost.Python">
<link rel="prev" href="faq/is_boost_python_thread_aware_com.html" title="Is Boost.Python thread-aware/compatible with multiple interpreters?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="faq/is_boost_python_thread_aware_com.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="glossary"></a>Chapter&#160;6.&#160;Glossary</h1></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">arity <a name="arity"></a></span></dt>
<dd><p>
The number of argumnts accepted by a function or member function. Unless
otherwise specified, the hidden <code class="computeroutput"><span class="keyword">this</span></code>
argument to member functions is not counted when specifying arity.
</p></dd>
<dt><span class="term">ntbs <a name="ntbs"></a></span></dt>
<dd><p>
Null-Terminated Byte String, or 'C'-string. C++ string literals are
<span class="bold"><strong>ntbs</strong></span>es. An <span class="bold"><strong>ntbs</strong></span>
must never be null.
</p></dd>
<dt><span class="term">raise <a name="raise"></a></span></dt>
<dd><p>
Exceptions in Python are "raised", not "thrown",
as they are in C++. When this documentation says that some Python exception
is "raised" in the context of C++ code, it means that the corresponding
Python exception is set via the <a href="http://www.python.org/doc/current/api/exceptionHandling.html" target="_top">Python/'C'
API</a>, and <code class="computeroutput"><span class="identifier">throw_error_already_set</span><span class="special">()</span></code> is called.
</p></dd>
<dt><span class="term">POD <a name="pod"></a></span></dt>
<dd><p>
A technical term from the C++ standard. Short for "Plain Ol'Data":
A POD-struct is an aggregate class that has no non-static data members
of type pointer to member, non-POD-struct, non-POD-union (or array of
such types) or reference, and has no user-defined copy assign- ment operator
and no user-defined destructor. Similarly, a POD-union is an aggregate
union that has no non-static data members of type pointer to member,
non-POD-struct, non-POD-union (or array of such types) or reference,
and has no user-defined copy assignment operator and no user-defined
destructor. A POD class is a class that is either a POD-struct or a POD-union.
An aggregate is an array or a class (clause 9) with no user-declared
constructors (12.1), no private or protected non-static data members
(clause 11), no base classes (clause 10), and no virtual functions (10.3).
</p></dd>
<dt><span class="term">ODR <a name="odr"></a></span></dt>
<dd><p>
The "One Definition Rule", which says that any entity in a
C++ program must have the same definition in all translation units (object
files) which make up a program.
</p></dd>
</dl>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="faq/is_boost_python_thread_aware_com.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a>
</div>
</body>
</html>

View File

@@ -1,135 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Boost.Python</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Boost.Python">
<link rel="next" href="rn.html" title="Chapter&#160;1.&#160;Release Notes">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav"><a accesskey="n" href="rn.html"><img src="images/next.png" alt="Next"></a></div>
<div class="book">
<div class="titlepage">
<div>
<div><h1 class="title">
<a name="python"></a>Boost.Python</h1></div>
<div><div class="authorgroup">
<div class="author"><h3 class="author">
<span class="firstname">David</span> <span class="surname">Abrahams</span>
</h3></div>
<div class="author"><h3 class="author">
<span class="firstname">Stefan</span> <span class="surname">Seefeld</span>
</h3></div>
</div></div>
<div><p class="copyright">Copyright &#169; 2002-2015 David
Abrahams, Stefan Seefeld</p></div>
<div><div class="legalnotice">
<a name="python.legal"></a><p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></div>
</div>
<hr>
</div>
<h3>
<a name="python.h0"></a>
<span class="phrase"><a name="python.synopsis"></a></span><a class="link" href="index.html#python.synopsis">Synopsis</a>
</h3>
<p>
Welcome to Boost.Python, a C++ library which enables seamless interoperability
between C++ and the Python programming language. The library includes support
for:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
References and Pointers
</li>
<li class="listitem">
Globally Registered Type Coercions
</li>
<li class="listitem">
Automatic Cross-Module Type Conversions
</li>
<li class="listitem">
Efficient Function Overloading
</li>
<li class="listitem">
C++ to Python Exception Translation
</li>
<li class="listitem">
Default Arguments
</li>
<li class="listitem">
Keyword Arguments
</li>
<li class="listitem">
Manipulating Python objects in C++
</li>
<li class="listitem">
Exporting C++ Iterators as Python Iterators
</li>
<li class="listitem">
Documentation Strings
</li>
</ul></div>
<p>
The development of these features was funded in part by grants to <code class="computeroutput"><span class="identifier">Boost</span> <span class="identifier">Consulting</span></code>
from the <a href="http://www.llnl.gov" target="_top">Lawrence Livermore National Laboratories</a>
and by the <a href="http://cci.lbl.gov" target="_top">Computational Crystallography Initiative</a>
at Lawrence Berkeley National Laboratories.
</p>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="python.contents"></a><a class="link" href="index.html#python.contents" title="Contents">Contents</a>
</h2></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a class="link" href="rn.html" title="Chapter&#160;1.&#160;Release Notes">Release Notes</a>
</li>
<li class="listitem">
<a href="tutorial/index.html" target="_top">Tutorial</a>
</li>
<li class="listitem">
<a class="link" href="building.html" title="Chapter&#160;2.&#160;Building and Testing">Building and Testing</a>
</li>
<li class="listitem">
<a href="reference/index.html" target="_top">Reference Manual</a>
</li>
<li class="listitem">
<a class="link" href="configuration.html" title="Chapter&#160;3.&#160;Configuration">Configuration Information</a>
</li>
<li class="listitem">
<a class="link" href="glossary.html" title="Chapter&#160;6.&#160;Glossary">Glossary</a>
</li>
<li class="listitem">
<a class="link" href="support.html" title="Chapter&#160;4.&#160;Support Resources">Support Resources</a>
</li>
<li class="listitem">
<a class="link" href="faq.html" title="Chapter&#160;5.&#160;Frequently Asked Questions (FAQs)">Frequently Asked Questions (FAQs)</a>
</li>
<li class="listitem">
<a href="numpy/index.html" target="_top">NumPy Extension Documentation</a>
</li>
</ul></div>
</div>
<h3>
<a name="python.h1"></a>
<span class="phrase"><a name="python.articles"></a></span><a class="link" href="index.html#python.articles">Articles</a>
</h3>
<p>
<a href="article.html" target="_top">Building Hybrid Systems With Boost Python</a>,
by Dave Abrahams and Ralf W. Grosse-Kunstleve
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: June 01, 2019 at 23:25:23 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
<div class="spirit-nav"><a accesskey="n" href="rn.html"><img src="images/next.png" alt="Next"></a></div>
</body>
</html>

View File

@@ -1,4 +0,0 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: c2f89bf9615bf36af14ecba75ba30ca4
tags: 645f666f9bcd5a90fca523b33c5a78b7

View File

@@ -1,54 +0,0 @@
How to use dtypes
=================
Here is a brief tutorial to show how to create ndarrays with built-in python data types, and extract the types and values of member variables
Like before, first get the necessary headers, setup the namespaces and initialize the Python runtime and numpy module::
#include <boost/python/numpy.hpp>
#include <iostream>
namespace p = boost::python;
namespace np = boost::python::numpy;
int main(int argc, char **argv)
{
Py_Initialize();
np::initialize();
Next, we create the shape and dtype. We use the get_builtin method to get the numpy dtype corresponding to the builtin C++ dtype
Here, we will create a 3x3 array passing a tuple with (3,3) for the size, and double as the data type ::
p::tuple shape = p::make_tuple(3, 3);
np::dtype dtype = np::dtype::get_builtin<double>();
np::ndarray a = np::zeros(shape, dtype);
Finally, we can print the array using the extract method in the python namespace.
Here, we first convert the variable into a string, and then extract it as a C++ character array from the python string using the <char const \* > template ::
std::cout << "Original array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
We can also print the dtypes of the data members of the ndarray by using the get_dtype method for the ndarray ::
std::cout << "Datatype is:\n" << p::extract<char const *>(p::str(a.get_dtype())) << std::endl ;
We can also create custom dtypes and build ndarrays with the custom dtypes
We use the dtype constructor to create a custom dtype. This constructor takes a list as an argument.
The list should contain one or more tuples of the format (variable name, variable type)
So first create a tuple with a variable name and its dtype, double, to create a custom dtype ::
p::tuple for_custom_dtype = p::make_tuple("ha",dtype) ;
Next, create a list, and add this tuple to the list. Then use the list to create the custom dtype ::
p::list list_for_dtype ;
list_for_dtype.append(for_custom_dtype) ;
np::dtype custom_dtype = np::dtype(list_for_dtype) ;
We are now ready to create an ndarray with dimensions specified by \*shape\* and of custom dtpye ::
np::ndarray new_array = np::zeros(shape,custom_dtype);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 673 B

View File

@@ -1,537 +0,0 @@
/*
* basic.css
* ~~~~~~~~~
*
* Sphinx stylesheet -- basic theme.
*
* :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
/* -- main layout ----------------------------------------------------------- */
div.clearer {
clear: both;
}
/* -- relbar ---------------------------------------------------------------- */
div.related {
width: 100%;
font-size: 90%;
}
div.related h3 {
display: none;
}
div.related ul {
margin: 0;
padding: 0 0 0 10px;
list-style: none;
}
div.related li {
display: inline;
}
div.related li.right {
float: right;
margin-right: 5px;
}
/* -- sidebar --------------------------------------------------------------- */
div.sphinxsidebarwrapper {
padding: 10px 5px 0 10px;
}
div.sphinxsidebar {
float: left;
width: 230px;
margin-left: -100%;
font-size: 90%;
}
div.sphinxsidebar ul {
list-style: none;
}
div.sphinxsidebar ul ul,
div.sphinxsidebar ul.want-points {
margin-left: 20px;
list-style: square;
}
div.sphinxsidebar ul ul {
margin-top: 0;
margin-bottom: 0;
}
div.sphinxsidebar form {
margin-top: 10px;
}
div.sphinxsidebar input {
border: 1px solid #98dbcc;
font-family: sans-serif;
font-size: 1em;
}
div.sphinxsidebar #searchbox input[type="text"] {
width: 170px;
}
div.sphinxsidebar #searchbox input[type="submit"] {
width: 30px;
}
img {
border: 0;
max-width: 100%;
}
/* -- search page ----------------------------------------------------------- */
ul.search {
margin: 10px 0 0 20px;
padding: 0;
}
ul.search li {
padding: 5px 0 5px 20px;
background-image: url(file.png);
background-repeat: no-repeat;
background-position: 0 7px;
}
ul.search li a {
font-weight: bold;
}
ul.search li div.context {
color: #888;
margin: 2px 0 0 30px;
text-align: left;
}
ul.keywordmatches li.goodmatch a {
font-weight: bold;
}
/* -- index page ------------------------------------------------------------ */
table.contentstable {
width: 90%;
}
table.contentstable p.biglink {
line-height: 150%;
}
a.biglink {
font-size: 1.3em;
}
span.linkdescr {
font-style: italic;
padding-top: 5px;
font-size: 90%;
}
/* -- general index --------------------------------------------------------- */
table.indextable {
width: 100%;
}
table.indextable td {
text-align: left;
vertical-align: top;
}
table.indextable dl, table.indextable dd {
margin-top: 0;
margin-bottom: 0;
}
table.indextable tr.pcap {
height: 10px;
}
table.indextable tr.cap {
margin-top: 10px;
background-color: #f2f2f2;
}
img.toggler {
margin-right: 3px;
margin-top: 3px;
cursor: pointer;
}
div.modindex-jumpbox {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
margin: 1em 0 1em 0;
padding: 0.4em;
}
div.genindex-jumpbox {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
margin: 1em 0 1em 0;
padding: 0.4em;
}
/* -- general body styles --------------------------------------------------- */
a.headerlink {
visibility: hidden;
}
h1:hover > a.headerlink,
h2:hover > a.headerlink,
h3:hover > a.headerlink,
h4:hover > a.headerlink,
h5:hover > a.headerlink,
h6:hover > a.headerlink,
dt:hover > a.headerlink {
visibility: visible;
}
div.body p.caption {
text-align: inherit;
}
div.body td {
text-align: left;
}
.field-list ul {
padding-left: 1em;
}
.first {
margin-top: 0 !important;
}
p.rubric {
margin-top: 30px;
font-weight: bold;
}
img.align-left, .figure.align-left, object.align-left {
clear: left;
float: left;
margin-right: 1em;
}
img.align-right, .figure.align-right, object.align-right {
clear: right;
float: right;
margin-left: 1em;
}
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left;
}
.align-center {
text-align: center;
}
.align-right {
text-align: right;
}
/* -- sidebars -------------------------------------------------------------- */
div.sidebar {
margin: 0 0 0.5em 1em;
border: 1px solid #ddb;
padding: 7px 7px 0 7px;
background-color: #ffe;
width: 40%;
float: right;
}
p.sidebar-title {
font-weight: bold;
}
/* -- topics ---------------------------------------------------------------- */
div.topic {
border: 1px solid #ccc;
padding: 7px 7px 0 7px;
margin: 10px 0 10px 0;
}
p.topic-title {
font-size: 1.1em;
font-weight: bold;
margin-top: 10px;
}
/* -- admonitions ----------------------------------------------------------- */
div.admonition {
margin-top: 10px;
margin-bottom: 10px;
padding: 7px;
}
div.admonition dt {
font-weight: bold;
}
div.admonition dl {
margin-bottom: 0;
}
p.admonition-title {
margin: 0px 10px 5px 0px;
font-weight: bold;
}
div.body p.centered {
text-align: center;
margin-top: 25px;
}
/* -- tables ---------------------------------------------------------------- */
table.docutils {
border: 0;
border-collapse: collapse;
}
table.docutils td, table.docutils th {
padding: 1px 8px 1px 5px;
border-top: 0;
border-left: 0;
border-right: 0;
border-bottom: 1px solid #aaa;
}
table.field-list td, table.field-list th {
border: 0 !important;
}
table.footnote td, table.footnote th {
border: 0 !important;
}
th {
text-align: left;
padding-right: 5px;
}
table.citation {
border-left: solid 1px gray;
margin-left: 1px;
}
table.citation td {
border-bottom: none;
}
/* -- other body styles ----------------------------------------------------- */
ol.arabic {
list-style: decimal;
}
ol.loweralpha {
list-style: lower-alpha;
}
ol.upperalpha {
list-style: upper-alpha;
}
ol.lowerroman {
list-style: lower-roman;
}
ol.upperroman {
list-style: upper-roman;
}
dl {
margin-bottom: 15px;
}
dd p {
margin-top: 0px;
}
dd ul, dd table {
margin-bottom: 10px;
}
dd {
margin-top: 3px;
margin-bottom: 10px;
margin-left: 30px;
}
dt:target, .highlighted {
background-color: #fbe54e;
}
dl.glossary dt {
font-weight: bold;
font-size: 1.1em;
}
.field-list ul {
margin: 0;
padding-left: 1em;
}
.field-list p {
margin: 0;
}
.optional {
font-size: 1.3em;
}
.versionmodified {
font-style: italic;
}
.system-message {
background-color: #fda;
padding: 5px;
border: 3px solid red;
}
.footnote:target {
background-color: #ffa;
}
.line-block {
display: block;
margin-top: 1em;
margin-bottom: 1em;
}
.line-block .line-block {
margin-top: 0;
margin-bottom: 0;
margin-left: 1.5em;
}
.guilabel, .menuselection {
font-family: sans-serif;
}
.accelerator {
text-decoration: underline;
}
.classifier {
font-style: oblique;
}
abbr, acronym {
border-bottom: dotted 1px;
cursor: help;
}
/* -- code displays --------------------------------------------------------- */
pre {
overflow: auto;
overflow-y: hidden; /* fixes display issues on Chrome browsers */
}
td.linenos pre {
padding: 5px 0px;
border: 0;
background-color: transparent;
color: #aaa;
}
table.highlighttable {
margin-left: 0.5em;
}
table.highlighttable td {
padding: 0 0.5em 0 0.5em;
}
tt.descname {
background-color: transparent;
font-weight: bold;
font-size: 1.2em;
}
tt.descclassname {
background-color: transparent;
}
tt.xref, a tt {
background-color: transparent;
font-weight: bold;
}
h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt {
background-color: transparent;
}
.viewcode-link {
float: right;
}
.viewcode-back {
float: right;
font-family: sans-serif;
}
div.viewcode-block:target {
margin: -1px -10px;
padding: 0 10px;
}
/* -- math display ---------------------------------------------------------- */
img.math {
vertical-align: middle;
}
div.body div.math p {
text-align: center;
}
span.eqno {
float: right;
}
/* -- printout stylesheet --------------------------------------------------- */
@media print {
div.document,
div.documentwrapper,
div.bodywrapper {
margin: 0 !important;
width: 100%;
}
div.sphinxsidebar,
div.related,
div.footer,
#top-link {
display: none;
}
}

View File

@@ -1,716 +0,0 @@
/*=============================================================================
Copyright (c) 2004 Joel de Guzman
http://spirit.sourceforge.net/
Copyright 2013 Niall Douglas additions for colors and alignment.
Copyright 2013 Paul A. Bristow additions for more colors and alignments.
Distributed under the Boost Software License, Version 1.0. (See accompany-
ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
/*=============================================================================
Body defaults
=============================================================================*/
body
{
margin: 1em;
font-family: sans-serif;
}
/*=============================================================================
Paragraphs
=============================================================================*/
p
{
text-align: left;
font-size: 10pt;
line-height: 1.15;
}
/*=============================================================================
Program listings
=============================================================================*/
/* Code on paragraphs */
p tt.computeroutput
{
font-size: 9pt;
}
pre.synopsis
{
font-size: 9pt;
margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc;
}
.programlisting,
.screen
{
font-size: 9pt;
display: block;
margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc;
}
/* Program listings in tables don't get borders */
td .programlisting,
td .screen
{
margin: 0pc 0pc 0pc 0pc;
padding: 0pc 0pc 0pc 0pc;
}
/*=============================================================================
Headings
=============================================================================*/
h1, h2, h3, h4, h5, h6
{
text-align: left;
margin: 1em 0em 0.5em 0em;
font-weight: bold;
}
h1 { font-size: 140%; }
h2 { font-weight: bold; font-size: 140%; }
h3 { font-weight: bold; font-size: 130%; }
h4 { font-weight: bold; font-size: 120%; }
h5 { font-weight: normal; font-style: italic; font-size: 110%; }
h6 { font-weight: normal; font-style: italic; font-size: 100%; }
/* Top page titles */
title,
h1.title,
h2.title
h3.title,
h4.title,
h5.title,
h6.title,
.refentrytitle
{
font-weight: bold;
margin-bottom: 1pc;
}
h1.title { font-size: 140% }
h2.title { font-size: 140% }
h3.title { font-size: 130% }
h4.title { font-size: 120% }
h5.title { font-size: 110% }
h6.title { font-size: 100% }
.section h1
{
margin: 0em 0em 0.5em 0em;
font-size: 140%;
}
.section h2 { font-size: 140% }
.section h3 { font-size: 130% }
.section h4 { font-size: 120% }
.section h5 { font-size: 110% }
.section h6 { font-size: 100% }
/* Code on titles */
h1 tt.computeroutput { font-size: 140% }
h2 tt.computeroutput { font-size: 140% }
h3 tt.computeroutput { font-size: 130% }
h4 tt.computeroutput { font-size: 130% }
h5 tt.computeroutput { font-size: 130% }
h6 tt.computeroutput { font-size: 130% }
/*=============================================================================
Author
=============================================================================*/
h3.author
{
font-size: 100%
}
/*=============================================================================
Lists
=============================================================================*/
li
{
font-size: 10pt;
line-height: 1.3;
}
/* Unordered lists */
ul
{
text-align: left;
}
/* Ordered lists */
ol
{
text-align: left;
}
/*=============================================================================
Links
=============================================================================*/
a
{
text-decoration: none; /* no underline */
}
a:hover
{
text-decoration: underline;
}
/*=============================================================================
Spirit style navigation
=============================================================================*/
.spirit-nav
{
text-align: right;
}
.spirit-nav a
{
color: white;
padding-left: 0.5em;
}
.spirit-nav img
{
border-width: 0px;
}
/*=============================================================================
Copyright footer
=============================================================================*/
.copyright-footer
{
text-align: right;
font-size: 70%;
}
.copyright-footer p
{
text-align: right;
font-size: 80%;
}
/*=============================================================================
Table of contents
=============================================================================*/
div.toc
{
margin: 1pc 4% 0pc 4%;
padding: 0.1pc 1pc 0.1pc 1pc;
font-size: 80%;
line-height: 1.15;
}
.boost-toc
{
float: right;
padding: 0.5pc;
}
/* Code on toc */
.toc .computeroutput { font-size: 120% }
/* No margin on nested menus */
.toc dl dl { margin: 0; }
/*=============================================================================
Tables
=============================================================================*/
.table-title,
div.table p.title
{
margin-left: 4%;
padding-right: 0.5em;
padding-left: 0.5em;
}
.informaltable table,
.table table
{
width: 92%;
margin-left: 4%;
margin-right: 4%;
}
div.informaltable table,
div.table table
{
padding: 4px;
}
/* Table Cells */
div.informaltable table tr td,
div.table table tr td
{
padding: 0.5em;
text-align: left;
font-size: 9pt;
}
div.informaltable table tr th,
div.table table tr th
{
padding: 0.5em 0.5em 0.5em 0.5em;
border: 1pt solid white;
font-size: 80%;
}
table.simplelist
{
width: auto !important;
margin: 0em !important;
padding: 0em !important;
border: none !important;
}
table.simplelist td
{
margin: 0em !important;
padding: 0em !important;
text-align: left !important;
font-size: 9pt !important;
border: none !important;
}
/*=============================================================================
Suppress margins in tables
=============================================================================*/
table th > *:first-child,
table td > *:first-child
{
margin-top: 0;
}
table th > *:last-child,
table td > *:last-child
{
margin-bottom: 0;
}
/*=============================================================================
Blurbs
=============================================================================*/
div.note,
div.tip,
div.important,
div.caution,
div.warning,
p.blurb
{
font-size: 9pt; /* A little bit smaller than the main text */
line-height: 1.2;
display: block;
margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc;
}
p.blurb img
{
padding: 1pt;
}
/*=============================================================================
Variable Lists
=============================================================================*/
div.variablelist
{
margin: 1em 0;
}
/* Make the terms in definition lists bold */
div.variablelist dl dt,
span.term
{
font-weight: bold;
font-size: 10pt;
}
div.variablelist table tbody tr td
{
text-align: left;
vertical-align: top;
padding: 0em 2em 0em 0em;
font-size: 10pt;
margin: 0em 0em 0.5em 0em;
line-height: 1;
}
div.variablelist dl dt
{
margin-bottom: 0.2em;
}
div.variablelist dl dd
{
margin: 0em 0em 0.5em 2em;
font-size: 10pt;
}
div.variablelist table tbody tr td p,
div.variablelist dl dd p
{
margin: 0em 0em 0.5em 0em;
line-height: 1;
}
/*=============================================================================
Misc
=============================================================================*/
/* Title of books and articles in bibliographies */
span.title
{
font-style: italic;
}
span.underline
{
text-decoration: underline;
}
span.strikethrough
{
text-decoration: line-through;
}
/* Copyright, Legal Notice */
div div.legalnotice p
{
text-align: left
}
/*=============================================================================
Colors
=============================================================================*/
@media screen
{
body {
background-color: #FFFFFF;
color: #000000;
}
/* Syntax Highlighting */
.keyword { color: #0000AA; }
.identifier { color: #000000; }
.special { color: #707070; }
.preprocessor { color: #402080; }
.char { color: teal; }
.comment { color: #800000; }
.string { color: teal; }
.number { color: teal; }
.white_bkd { background-color: #FFFFFF; }
.dk_grey_bkd { background-color: #999999; }
/* Links */
a, a .keyword, a .identifier, a .special, a .preprocessor
a .char, a .comment, a .string, a .number
{
color: #005a9c;
}
a:visited, a:visited .keyword, a:visited .identifier,
a:visited .special, a:visited .preprocessor a:visited .char,
a:visited .comment, a:visited .string, a:visited .number
{
color: #9c5a9c;
}
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a,
h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover,
h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited
{
text-decoration: none; /* no underline */
color: #000000;
}
/* Copyright, Legal Notice */
.copyright
{
color: #666666;
font-size: small;
}
div div.legalnotice p
{
color: #666666;
}
/* Program listing */
pre.synopsis
{
border: 1px solid #DCDCDC;
}
.programlisting,
.screen
{
border: 1px solid #DCDCDC;
}
td .programlisting,
td .screen
{
border: 0px solid #DCDCDC;
}
/* Blurbs */
div.note,
div.tip,
div.important,
div.caution,
div.warning,
p.blurb
{
border: 1px solid #DCDCDC;
}
/* Table of contents */
div.toc
{
border: 1px solid #DCDCDC;
}
/* Tables */
div.informaltable table tr td,
div.table table tr td
{
border: 1px solid #DCDCDC;
}
div.informaltable table tr th,
div.table table tr th
{
background-color: #F0F0F0;
border: 1px solid #DCDCDC;
}
.copyright-footer
{
color: #8F8F8F;
}
/* Misc */
span.highlight
{
color: #00A000;
}
}
@media print
{
/* Links */
a
{
color: black;
}
a:visited
{
color: black;
}
.spirit-nav
{
display: none;
}
/* Program listing */
pre.synopsis
{
border: 1px solid gray;
}
.programlisting,
.screen
{
border: 1px solid gray;
}
td .programlisting,
td .screen
{
border: 0px solid #DCDCDC;
}
/* Table of contents */
div.toc
{
border: 1px solid gray;
}
.informaltable table,
.table table
{
border: 1px solid gray;
border-collapse: collapse;
}
/* Tables */
div.informaltable table tr td,
div.table table tr td
{
border: 1px solid gray;
}
div.informaltable table tr th,
div.table table tr th
{
border: 1px solid gray;
}
table.simplelist tr td
{
border: none !important;
}
/* Misc */
span.highlight
{
font-weight: bold;
}
}
/*=============================================================================
Images
=============================================================================*/
span.inlinemediaobject img
{
vertical-align: middle;
}
/*==============================================================================
Super and Subscript: style so that line spacing isn't effected, see
http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=1&postId=5341
==============================================================================*/
sup,
sub {
height: 0;
line-height: 1;
vertical-align: baseline;
position: relative;
}
/* For internet explorer: */
* html sup,
* html sub {
vertical-align: bottom;
}
sup {
bottom: 1ex;
}
sub {
top: .5ex;
}
/*==============================================================================
Indexes: pretty much the same as the TOC.
==============================================================================*/
.index
{
font-size: 80%;
padding-top: 0px;
padding-bottom: 0px;
margin-top: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
.index ul
{
padding-left: 3em;
}
.index p
{
padding: 2px;
margin: 2px;
}
.index-entry-level-0
{
font-weight: bold;
}
.index em
{
font-weight: bold;
}
/*==============================================================================
Alignment and coloring use 'role' feature, available from Quickbook 1.6 up.
Added from Niall Douglas for role color and alignment.
http://article.gmane.org/gmane.comp.lib.boost.devel/243318
*/
/* Add text alignment (see http://www.w3schools.com/cssref/pr_text_text-align.asp) */
span.aligncenter
{
display: inline-block; width: 100%; text-align: center;
}
span.alignright
{
display: inline-block; width: 100%; text-align: right;
}
/* alignleft is the default. */
span.alignleft
{
display: inline-block; width: 100%; text-align: left;
}
/* alignjustify stretches the word spacing so that each line has equal width
within a chosen fraction of page width (here arbitrarily 20%).
*Not* useful inside table items as the column width remains the total string width.
Nor very useful, except to temporarily restrict the width.
*/
span.alignjustify
{
display: inline-block; width: 20%; text-align: justify;
}
/* Text colors.
Names at http://www.w3.org/TR/2002/WD-css3-color-20020219/ 4.3. X11 color keywords.
Quickbook Usage: [role red Some red text]
*/
span.red { inline-block; color: red; }
span.green { color: green; }
span.lime { color: #00FF00; }
span.blue { color: blue; }
span.navy { color: navy; }
span.yellow { color: yellow; }
span.magenta { color: magenta; }
span.indigo { color: #4B0082; }
span.cyan { color: cyan; }
span.purple { color: purple; }
span.gold { color: gold; }
span.silver { color: silver; } /* lighter gray */
span.gray { color: #808080; } /* light gray */

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

View File

@@ -1,256 +0,0 @@
/*
* default.css_t
* ~~~~~~~~~~~~~
*
* Sphinx stylesheet -- default theme.
*
* :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
@import url("basic.css");
/* -- page layout ----------------------------------------------------------- */
body {
font-family: sans-serif;
font-size: 100%;
background-color: #11303d;
color: #000;
margin: 0;
padding: 0;
}
div.document {
background-color: #1c4e63;
}
div.documentwrapper {
float: left;
width: 100%;
}
div.bodywrapper {
margin: 0 0 0 230px;
}
div.body {
background-color: #ffffff;
color: #000000;
padding: 0 20px 30px 20px;
}
div.footer {
color: #ffffff;
width: 100%;
padding: 9px 0 9px 0;
text-align: center;
font-size: 75%;
}
div.footer a {
color: #ffffff;
text-decoration: underline;
}
div.related {
background-color: #133f52;
line-height: 30px;
color: #ffffff;
}
div.related a {
color: #ffffff;
}
div.sphinxsidebar {
}
div.sphinxsidebar h3 {
font-family: 'Trebuchet MS', sans-serif;
color: #ffffff;
font-size: 1.4em;
font-weight: normal;
margin: 0;
padding: 0;
}
div.sphinxsidebar h3 a {
color: #ffffff;
}
div.sphinxsidebar h4 {
font-family: 'Trebuchet MS', sans-serif;
color: #ffffff;
font-size: 1.3em;
font-weight: normal;
margin: 5px 0 0 0;
padding: 0;
}
div.sphinxsidebar p {
color: #ffffff;
}
div.sphinxsidebar p.topless {
margin: 5px 10px 10px 10px;
}
div.sphinxsidebar ul {
margin: 10px;
padding: 0;
color: #ffffff;
}
div.sphinxsidebar a {
color: #98dbcc;
}
div.sphinxsidebar input {
border: 1px solid #98dbcc;
font-family: sans-serif;
font-size: 1em;
}
/* -- hyperlink styles ------------------------------------------------------ */
a {
color: #355f7c;
text-decoration: none;
}
a:visited {
color: #355f7c;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* -- body styles ----------------------------------------------------------- */
div.body h1,
div.body h2,
div.body h3,
div.body h4,
div.body h5,
div.body h6 {
font-family: 'Trebuchet MS', sans-serif;
background-color: #f2f2f2;
font-weight: normal;
color: #20435c;
border-bottom: 1px solid #ccc;
margin: 20px -20px 10px -20px;
padding: 3px 0 3px 10px;
}
div.body h1 { margin-top: 0; font-size: 200%; }
div.body h2 { font-size: 160%; }
div.body h3 { font-size: 140%; }
div.body h4 { font-size: 120%; }
div.body h5 { font-size: 110%; }
div.body h6 { font-size: 100%; }
a.headerlink {
color: #c60f0f;
font-size: 0.8em;
padding: 0 4px 0 4px;
text-decoration: none;
}
a.headerlink:hover {
background-color: #c60f0f;
color: white;
}
div.body p, div.body dd, div.body li {
text-align: justify;
line-height: 130%;
}
div.admonition p.admonition-title + p {
display: inline;
}
div.admonition p {
margin-bottom: 5px;
}
div.admonition pre {
margin-bottom: 5px;
}
div.admonition ul, div.admonition ol {
margin-bottom: 5px;
}
div.note {
background-color: #eee;
border: 1px solid #ccc;
}
div.seealso {
background-color: #ffc;
border: 1px solid #ff6;
}
div.topic {
background-color: #eee;
}
div.warning {
background-color: #ffe4e4;
border: 1px solid #f66;
}
p.admonition-title {
display: inline;
}
p.admonition-title:after {
content: ":";
}
pre {
padding: 5px;
background-color: #eeffcc;
color: #333333;
line-height: 120%;
border: 1px solid #ac9;
border-left: none;
border-right: none;
}
tt {
background-color: #ecf0f3;
padding: 0 1px 0 1px;
font-size: 0.95em;
}
th {
background-color: #ede;
}
.warning tt {
background: #efc2c2;
}
.note tt {
background: #d6d6d6;
}
.viewcode-back {
font-family: sans-serif;
}
div.viewcode-block:target {
background-color: #f4debf;
border-top: 1px solid #ac9;
border-bottom: 1px solid #ac9;
}

View File

@@ -1,238 +0,0 @@
/*
* doctools.js
* ~~~~~~~~~~~
*
* Sphinx JavaScript utilities for all documentation.
*
* :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
/**
* select a different prefix for underscore
*/
$u = _.noConflict();
/**
* make the code below compatible with browsers without
* an installed firebug like debugger
if (!window.console || !console.firebug) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir",
"dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace",
"profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i)
window.console[names[i]] = function() {};
}
*/
/**
* small helper function to urldecode strings
*/
jQuery.urldecode = function(x) {
return decodeURIComponent(x).replace(/\+/g, ' ');
};
/**
* small helper function to urlencode strings
*/
jQuery.urlencode = encodeURIComponent;
/**
* This function returns the parsed url parameters of the
* current request. Multiple values per key are supported,
* it will always return arrays of strings for the value parts.
*/
jQuery.getQueryParameters = function(s) {
if (typeof s == 'undefined')
s = document.location.search;
var parts = s.substr(s.indexOf('?') + 1).split('&');
var result = {};
for (var i = 0; i < parts.length; i++) {
var tmp = parts[i].split('=', 2);
var key = jQuery.urldecode(tmp[0]);
var value = jQuery.urldecode(tmp[1]);
if (key in result)
result[key].push(value);
else
result[key] = [value];
}
return result;
};
/**
* highlight a given string on a jquery object by wrapping it in
* span elements with the given class name.
*/
jQuery.fn.highlightText = function(text, className) {
function highlight(node) {
if (node.nodeType == 3) {
var val = node.nodeValue;
var pos = val.toLowerCase().indexOf(text);
if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) {
var span = document.createElement("span");
span.className = className;
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
document.createTextNode(val.substr(pos + text.length)),
node.nextSibling));
node.nodeValue = val.substr(0, pos);
}
}
else if (!jQuery(node).is("button, select, textarea")) {
jQuery.each(node.childNodes, function() {
highlight(this);
});
}
}
return this.each(function() {
highlight(this);
});
};
/**
* Small JavaScript module for the documentation.
*/
var Documentation = {
init : function() {
this.fixFirefoxAnchorBug();
this.highlightSearchWords();
this.initIndexTable();
},
/**
* i18n support
*/
TRANSLATIONS : {},
PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; },
LOCALE : 'unknown',
// gettext and ngettext don't access this so that the functions
// can safely bound to a different name (_ = Documentation.gettext)
gettext : function(string) {
var translated = Documentation.TRANSLATIONS[string];
if (typeof translated == 'undefined')
return string;
return (typeof translated == 'string') ? translated : translated[0];
},
ngettext : function(singular, plural, n) {
var translated = Documentation.TRANSLATIONS[singular];
if (typeof translated == 'undefined')
return (n == 1) ? singular : plural;
return translated[Documentation.PLURALEXPR(n)];
},
addTranslations : function(catalog) {
for (var key in catalog.messages)
this.TRANSLATIONS[key] = catalog.messages[key];
this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')');
this.LOCALE = catalog.locale;
},
/**
* add context elements like header anchor links
*/
addContextElements : function() {
$('div[id] > :header:first').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this headline')).
appendTo(this);
});
$('dt[id]').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this definition')).
appendTo(this);
});
},
/**
* workaround a firefox stupidity
*/
fixFirefoxAnchorBug : function() {
if (document.location.hash && $.browser.mozilla)
window.setTimeout(function() {
document.location.href += '';
}, 10);
},
/**
* highlight the search words provided in the url in the text
*/
highlightSearchWords : function() {
var params = $.getQueryParameters();
var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
if (terms.length) {
var body = $('div.body');
if (!body.length) {
body = $('body');
}
window.setTimeout(function() {
$.each(terms, function() {
body.highlightText(this.toLowerCase(), 'highlighted');
});
}, 10);
$('<p class="highlight-link"><a href="javascript:Documentation.' +
'hideSearchWords()">' + _('Hide Search Matches') + '</a></p>')
.appendTo($('#searchbox'));
}
},
/**
* init the domain index toggle buttons
*/
initIndexTable : function() {
var togglers = $('img.toggler').click(function() {
var src = $(this).attr('src');
var idnum = $(this).attr('id').substr(7);
$('tr.cg-' + idnum).toggle();
if (src.substr(-9) == 'minus.png')
$(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
else
$(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
}).css('display', '');
if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
togglers.click();
}
},
/**
* helper function to hide the search marks again
*/
hideSearchWords : function() {
$('#searchbox .highlight-link').fadeOut(300);
$('span.highlighted').removeClass('highlighted');
},
/**
* make the url absolute
*/
makeURL : function(relativeURL) {
return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL;
},
/**
* get the current relative url
*/
getCurrentURL : function() {
var path = document.location.pathname;
var parts = path.split(/\//);
$.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
if (this == '..')
parts.pop();
});
var url = parts.join('/');
return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
}
};
// quick alias for translations
_ = Documentation.gettext;
$(document).ready(function() {
Documentation.init();
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

View File

@@ -1,62 +0,0 @@
.highlight .hll { background-color: #ffffcc }
.highlight { background: #f8f8f8; }
.highlight .c { color: #408080; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #008000; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0044DD } /* Generic.Traceback */
.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008000 } /* Keyword.Pseudo */
.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #B00040 } /* Keyword.Type */
.highlight .m { color: #666666 } /* Literal.Number */
.highlight .s { color: #BA2121 } /* Literal.String */
.highlight .na { color: #7D9029 } /* Name.Attribute */
.highlight .nb { color: #008000 } /* Name.Builtin */
.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.highlight .no { color: #880000 } /* Name.Constant */
.highlight .nd { color: #AA22FF } /* Name.Decorator */
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0000FF } /* Name.Function */
.highlight .nl { color: #A0A000 } /* Name.Label */
.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #19177C } /* Name.Variable */
.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #666666 } /* Literal.Number.Float */
.highlight .mh { color: #666666 } /* Literal.Number.Hex */
.highlight .mi { color: #666666 } /* Literal.Number.Integer */
.highlight .mo { color: #666666 } /* Literal.Number.Oct */
.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
.highlight .sc { color: #BA2121 } /* Literal.String.Char */
.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.highlight .sx { color: #008000 } /* Literal.String.Other */
.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
.highlight .ss { color: #19177C } /* Literal.String.Symbol */
.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #19177C } /* Name.Variable.Class */
.highlight .vg { color: #19177C } /* Name.Variable.Global */
.highlight .vi { color: #19177C } /* Name.Variable.Instance */
.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */

View File

@@ -1,622 +0,0 @@
/*
* searchtools.js_t
* ~~~~~~~~~~~~~~~~
*
* Sphinx JavaScript utilties for the full-text search.
*
* :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
/**
* Porter Stemmer
*/
var Stemmer = function() {
var step2list = {
ational: 'ate',
tional: 'tion',
enci: 'ence',
anci: 'ance',
izer: 'ize',
bli: 'ble',
alli: 'al',
entli: 'ent',
eli: 'e',
ousli: 'ous',
ization: 'ize',
ation: 'ate',
ator: 'ate',
alism: 'al',
iveness: 'ive',
fulness: 'ful',
ousness: 'ous',
aliti: 'al',
iviti: 'ive',
biliti: 'ble',
logi: 'log'
};
var step3list = {
icate: 'ic',
ative: '',
alize: 'al',
iciti: 'ic',
ical: 'ic',
ful: '',
ness: ''
};
var c = "[^aeiou]"; // consonant
var v = "[aeiouy]"; // vowel
var C = c + "[^aeiouy]*"; // consonant sequence
var V = v + "[aeiou]*"; // vowel sequence
var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0
var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1
var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1
var s_v = "^(" + C + ")?" + v; // vowel in stem
this.stemWord = function (w) {
var stem;
var suffix;
var firstch;
var origword = w;
if (w.length < 3)
return w;
var re;
var re2;
var re3;
var re4;
firstch = w.substr(0,1);
if (firstch == "y")
w = firstch.toUpperCase() + w.substr(1);
// Step 1a
re = /^(.+?)(ss|i)es$/;
re2 = /^(.+?)([^s])s$/;
if (re.test(w))
w = w.replace(re,"$1$2");
else if (re2.test(w))
w = w.replace(re2,"$1$2");
// Step 1b
re = /^(.+?)eed$/;
re2 = /^(.+?)(ed|ing)$/;
if (re.test(w)) {
var fp = re.exec(w);
re = new RegExp(mgr0);
if (re.test(fp[1])) {
re = /.$/;
w = w.replace(re,"");
}
}
else if (re2.test(w)) {
var fp = re2.exec(w);
stem = fp[1];
re2 = new RegExp(s_v);
if (re2.test(stem)) {
w = stem;
re2 = /(at|bl|iz)$/;
re3 = new RegExp("([^aeiouylsz])\\1$");
re4 = new RegExp("^" + C + v + "[^aeiouwxy]$");
if (re2.test(w))
w = w + "e";
else if (re3.test(w)) {
re = /.$/;
w = w.replace(re,"");
}
else if (re4.test(w))
w = w + "e";
}
}
// Step 1c
re = /^(.+?)y$/;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
re = new RegExp(s_v);
if (re.test(stem))
w = stem + "i";
}
// Step 2
re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
suffix = fp[2];
re = new RegExp(mgr0);
if (re.test(stem))
w = stem + step2list[suffix];
}
// Step 3
re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
suffix = fp[2];
re = new RegExp(mgr0);
if (re.test(stem))
w = stem + step3list[suffix];
}
// Step 4
re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
re2 = /^(.+?)(s|t)(ion)$/;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
re = new RegExp(mgr1);
if (re.test(stem))
w = stem;
}
else if (re2.test(w)) {
var fp = re2.exec(w);
stem = fp[1] + fp[2];
re2 = new RegExp(mgr1);
if (re2.test(stem))
w = stem;
}
// Step 5
re = /^(.+?)e$/;
if (re.test(w)) {
var fp = re.exec(w);
stem = fp[1];
re = new RegExp(mgr1);
re2 = new RegExp(meq1);
re3 = new RegExp("^" + C + v + "[^aeiouwxy]$");
if (re.test(stem) || (re2.test(stem) && !(re3.test(stem))))
w = stem;
}
re = /ll$/;
re2 = new RegExp(mgr1);
if (re.test(w) && re2.test(w)) {
re = /.$/;
w = w.replace(re,"");
}
// and turn initial Y back to y
if (firstch == "y")
w = firstch.toLowerCase() + w.substr(1);
return w;
}
}
/**
* Simple result scoring code.
*/
var Scorer = {
// Implement the following function to further tweak the score for each result
// The function takes a result array [filename, title, anchor, descr, score]
// and returns the new score.
/*
score: function(result) {
return result[4];
},
*/
// query matches the full name of an object
objNameMatch: 11,
// or matches in the last dotted part of the object name
objPartialMatch: 6,
// Additive scores depending on the priority of the object
objPrio: {0: 15, // used to be importantResults
1: 5, // used to be objectResults
2: -5}, // used to be unimportantResults
// Used when the priority is not in the mapping.
objPrioDefault: 0,
// query found in title
title: 15,
// query found in terms
term: 5
};
/**
* Search Module
*/
var Search = {
_index : null,
_queued_query : null,
_pulse_status : -1,
init : function() {
var params = $.getQueryParameters();
if (params.q) {
var query = params.q[0];
$('input[name="q"]')[0].value = query;
this.performSearch(query);
}
},
loadIndex : function(url) {
$.ajax({type: "GET", url: url, data: null,
dataType: "script", cache: true,
complete: function(jqxhr, textstatus) {
if (textstatus != "success") {
document.getElementById("searchindexloader").src = url;
}
}});
},
setIndex : function(index) {
var q;
this._index = index;
if ((q = this._queued_query) !== null) {
this._queued_query = null;
Search.query(q);
}
},
hasIndex : function() {
return this._index !== null;
},
deferQuery : function(query) {
this._queued_query = query;
},
stopPulse : function() {
this._pulse_status = 0;
},
startPulse : function() {
if (this._pulse_status >= 0)
return;
function pulse() {
var i;
Search._pulse_status = (Search._pulse_status + 1) % 4;
var dotString = '';
for (i = 0; i < Search._pulse_status; i++)
dotString += '.';
Search.dots.text(dotString);
if (Search._pulse_status > -1)
window.setTimeout(pulse, 500);
}
pulse();
},
/**
* perform a search for something (or wait until index is loaded)
*/
performSearch : function(query) {
// create the required interface elements
this.out = $('#search-results');
this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out);
this.dots = $('<span></span>').appendTo(this.title);
this.status = $('<p style="display: none"></p>').appendTo(this.out);
this.output = $('<ul class="search"/>').appendTo(this.out);
$('#search-progress').text(_('Preparing search...'));
this.startPulse();
// index already loaded, the browser was quick!
if (this.hasIndex())
this.query(query);
else
this.deferQuery(query);
},
/**
* execute search (requires search index to be loaded)
*/
query : function(query) {
var i;
var stopwords = ["a","and","are","as","at","be","but","by","for","if","in","into","is","it","near","no","not","of","on","or","such","that","the","their","then","there","these","they","this","to","was","will","with"];
// stem the searchterms and add them to the correct list
var stemmer = new Stemmer();
var searchterms = [];
var excluded = [];
var hlterms = [];
var tmp = query.split(/\s+/);
var objectterms = [];
for (i = 0; i < tmp.length; i++) {
if (tmp[i] !== "") {
objectterms.push(tmp[i].toLowerCase());
}
if ($u.indexOf(stopwords, tmp[i].toLowerCase()) != -1 || tmp[i].match(/^\d+$/) ||
tmp[i] === "") {
// skip this "word"
continue;
}
// stem the word
var word = stemmer.stemWord(tmp[i].toLowerCase());
var toAppend;
// select the correct list
if (word[0] == '-') {
toAppend = excluded;
word = word.substr(1);
}
else {
toAppend = searchterms;
hlterms.push(tmp[i].toLowerCase());
}
// only add if not already in the list
if (!$u.contains(toAppend, word))
toAppend.push(word);
}
var highlightstring = '?highlight=' + $.urlencode(hlterms.join(" "));
// console.debug('SEARCH: searching for:');
// console.info('required: ', searchterms);
// console.info('excluded: ', excluded);
// prepare search
var terms = this._index.terms;
var titleterms = this._index.titleterms;
// array of [filename, title, anchor, descr, score]
var results = [];
$('#search-progress').empty();
// lookup as object
for (i = 0; i < objectterms.length; i++) {
var others = [].concat(objectterms.slice(0, i),
objectterms.slice(i+1, objectterms.length));
results = results.concat(this.performObjectSearch(objectterms[i], others));
}
// lookup as search terms in fulltext
results = results.concat(this.performTermsSearch(searchterms, excluded, terms, Scorer.term))
.concat(this.performTermsSearch(searchterms, excluded, titleterms, Scorer.title));
// let the scorer override scores with a custom scoring function
if (Scorer.score) {
for (i = 0; i < results.length; i++)
results[i][4] = Scorer.score(results[i]);
}
// now sort the results by score (in opposite order of appearance, since the
// display function below uses pop() to retrieve items) and then
// alphabetically
results.sort(function(a, b) {
var left = a[4];
var right = b[4];
if (left > right) {
return 1;
} else if (left < right) {
return -1;
} else {
// same score: sort alphabetically
left = a[1].toLowerCase();
right = b[1].toLowerCase();
return (left > right) ? -1 : ((left < right) ? 1 : 0);
}
});
// for debugging
//Search.lastresults = results.slice(); // a copy
//console.info('search results:', Search.lastresults);
// print the results
var resultCount = results.length;
function displayNextItem() {
// results left, load the summary and display it
if (results.length) {
var item = results.pop();
var listItem = $('<li style="display:none"></li>');
if (DOCUMENTATION_OPTIONS.FILE_SUFFIX === '') {
// dirhtml builder
var dirname = item[0] + '/';
if (dirname.match(/\/index\/$/)) {
dirname = dirname.substring(0, dirname.length-6);
} else if (dirname == 'index/') {
dirname = '';
}
listItem.append($('<a/>').attr('href',
DOCUMENTATION_OPTIONS.URL_ROOT + dirname +
highlightstring + item[2]).html(item[1]));
} else {
// normal html builders
listItem.append($('<a/>').attr('href',
item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
highlightstring + item[2]).html(item[1]));
}
if (item[3]) {
listItem.append($('<span> (' + item[3] + ')</span>'));
Search.output.append(listItem);
listItem.slideDown(5, function() {
displayNextItem();
});
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
$.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[0] + '.txt',
dataType: "text",
complete: function(jqxhr, textstatus) {
var data = jqxhr.responseText;
if (data !== '') {
listItem.append(Search.makeSearchSummary(data, searchterms, hlterms));
}
Search.output.append(listItem);
listItem.slideDown(5, function() {
displayNextItem();
});
}});
} else {
// no source available, just display title
Search.output.append(listItem);
listItem.slideDown(5, function() {
displayNextItem();
});
}
}
// search finished, update title and status message
else {
Search.stopPulse();
Search.title.text(_('Search Results'));
if (!resultCount)
Search.status.text(_('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
else
Search.status.text(_('Search finished, found %s page(s) matching the search query.').replace('%s', resultCount));
Search.status.fadeIn(500);
}
}
displayNextItem();
},
/**
* search for object names
*/
performObjectSearch : function(object, otherterms) {
var filenames = this._index.filenames;
var objects = this._index.objects;
var objnames = this._index.objnames;
var titles = this._index.titles;
var i;
var results = [];
for (var prefix in objects) {
for (var name in objects[prefix]) {
var fullname = (prefix ? prefix + '.' : '') + name;
if (fullname.toLowerCase().indexOf(object) > -1) {
var score = 0;
var parts = fullname.split('.');
// check for different match types: exact matches of full name or
// "last name" (i.e. last dotted part)
if (fullname == object || parts[parts.length - 1] == object) {
score += Scorer.objNameMatch;
// matches in last name
} else if (parts[parts.length - 1].indexOf(object) > -1) {
score += Scorer.objPartialMatch;
}
var match = objects[prefix][name];
var objname = objnames[match[1]][2];
var title = titles[match[0]];
// If more than one term searched for, we require other words to be
// found in the name/title/description
if (otherterms.length > 0) {
var haystack = (prefix + ' ' + name + ' ' +
objname + ' ' + title).toLowerCase();
var allfound = true;
for (i = 0; i < otherterms.length; i++) {
if (haystack.indexOf(otherterms[i]) == -1) {
allfound = false;
break;
}
}
if (!allfound) {
continue;
}
}
var descr = objname + _(', in ') + title;
var anchor = match[3];
if (anchor === '')
anchor = fullname;
else if (anchor == '-')
anchor = objnames[match[1]][1] + '-' + fullname;
// add custom score for some objects according to scorer
if (Scorer.objPrio.hasOwnProperty(match[2])) {
score += Scorer.objPrio[match[2]];
} else {
score += Scorer.objPrioDefault;
}
results.push([filenames[match[0]], fullname, '#'+anchor, descr, score]);
}
}
}
return results;
},
/**
* search for full-text terms in the index
*/
performTermsSearch : function(searchterms, excluded, terms, score) {
var filenames = this._index.filenames;
var titles = this._index.titles;
var i, j, file, files;
var fileMap = {};
var results = [];
// perform the search on the required terms
for (i = 0; i < searchterms.length; i++) {
var word = searchterms[i];
// no match but word was a required one
if ((files = terms[word]) === undefined)
break;
if (files.length === undefined) {
files = [files];
}
// create the mapping
for (j = 0; j < files.length; j++) {
file = files[j];
if (file in fileMap)
fileMap[file].push(word);
else
fileMap[file] = [word];
}
}
// now check if the files don't contain excluded terms
for (file in fileMap) {
var valid = true;
// check if all requirements are matched
if (fileMap[file].length != searchterms.length)
continue;
// ensure that none of the excluded terms is in the search result
for (i = 0; i < excluded.length; i++) {
if (terms[excluded[i]] == file ||
$u.contains(terms[excluded[i]] || [], file)) {
valid = false;
break;
}
}
// if we have still a valid result we can add it to the result list
if (valid) {
results.push([filenames[file], titles[file], '', null, score]);
}
}
return results;
},
/**
* helper function to return a node containing the
* search summary for a given text. keywords is a list
* of stemmed words, hlwords is the list of normal, unstemmed
* words. the first one is used to find the occurance, the
* latter for highlighting it.
*/
makeSearchSummary : function(text, keywords, hlwords) {
var textLower = text.toLowerCase();
var start = 0;
$.each(keywords, function() {
var i = textLower.indexOf(this.toLowerCase());
if (i > -1)
start = i;
});
start = Math.max(start - 120, 0);
var excerpt = ((start > 0) ? '...' : '') +
$.trim(text.substr(start, 240)) +
((start + 240 - text.length) ? '...' : '');
var rv = $('<div class="context"></div>').text(excerpt);
$.each(hlwords, function() {
rv = rv.highlightText(this, 'highlighted');
});
return rv;
}
};
$(document).ready(function() {
Search.init();
});

View File

@@ -1,159 +0,0 @@
/*
* sidebar.js
* ~~~~~~~~~~
*
* This script makes the Sphinx sidebar collapsible.
*
* .sphinxsidebar contains .sphinxsidebarwrapper. This script adds
* in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton
* used to collapse and expand the sidebar.
*
* When the sidebar is collapsed the .sphinxsidebarwrapper is hidden
* and the width of the sidebar and the margin-left of the document
* are decreased. When the sidebar is expanded the opposite happens.
* This script saves a per-browser/per-session cookie used to
* remember the position of the sidebar among the pages.
* Once the browser is closed the cookie is deleted and the position
* reset to the default (expanded).
*
* :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
$(function() {
// global elements used by the functions.
// the 'sidebarbutton' element is defined as global after its
// creation, in the add_sidebar_button function
var bodywrapper = $('.bodywrapper');
var sidebar = $('.sphinxsidebar');
var sidebarwrapper = $('.sphinxsidebarwrapper');
// for some reason, the document has no sidebar; do not run into errors
if (!sidebar.length) return;
// original margin-left of the bodywrapper and width of the sidebar
// with the sidebar expanded
var bw_margin_expanded = bodywrapper.css('margin-left');
var ssb_width_expanded = sidebar.width();
// margin-left of the bodywrapper and width of the sidebar
// with the sidebar collapsed
var bw_margin_collapsed = '.8em';
var ssb_width_collapsed = '.8em';
// colors used by the current theme
var dark_color = $('.related').css('background-color');
var light_color = $('.document').css('background-color');
function sidebar_is_collapsed() {
return sidebarwrapper.is(':not(:visible)');
}
function toggle_sidebar() {
if (sidebar_is_collapsed())
expand_sidebar();
else
collapse_sidebar();
}
function collapse_sidebar() {
sidebarwrapper.hide();
sidebar.css('width', ssb_width_collapsed);
bodywrapper.css('margin-left', bw_margin_collapsed);
sidebarbutton.css({
'margin-left': '0',
'height': bodywrapper.height()
});
sidebarbutton.find('span').text('»');
sidebarbutton.attr('title', _('Expand sidebar'));
document.cookie = 'sidebar=collapsed';
}
function expand_sidebar() {
bodywrapper.css('margin-left', bw_margin_expanded);
sidebar.css('width', ssb_width_expanded);
sidebarwrapper.show();
sidebarbutton.css({
'margin-left': ssb_width_expanded-12,
'height': bodywrapper.height()
});
sidebarbutton.find('span').text('«');
sidebarbutton.attr('title', _('Collapse sidebar'));
document.cookie = 'sidebar=expanded';
}
function add_sidebar_button() {
sidebarwrapper.css({
'float': 'left',
'margin-right': '0',
'width': ssb_width_expanded - 28
});
// create the button
sidebar.append(
'<div id="sidebarbutton"><span>&laquo;</span></div>'
);
var sidebarbutton = $('#sidebarbutton');
light_color = sidebarbutton.css('background-color');
// find the height of the viewport to center the '<<' in the page
var viewport_height;
if (window.innerHeight)
viewport_height = window.innerHeight;
else
viewport_height = $(window).height();
sidebarbutton.find('span').css({
'display': 'block',
'margin-top': (viewport_height - sidebar.position().top - 20) / 2
});
sidebarbutton.click(toggle_sidebar);
sidebarbutton.attr('title', _('Collapse sidebar'));
sidebarbutton.css({
'color': '#FFFFFF',
'border-left': '1px solid ' + dark_color,
'font-size': '1.2em',
'cursor': 'pointer',
'height': bodywrapper.height(),
'padding-top': '1px',
'margin-left': ssb_width_expanded - 12
});
sidebarbutton.hover(
function () {
$(this).css('background-color', dark_color);
},
function () {
$(this).css('background-color', light_color);
}
);
}
function set_position_from_cookie() {
if (!document.cookie)
return;
var items = document.cookie.split(';');
for(var k=0; k<items.length; k++) {
var key_val = items[k].split('=');
var key = key_val[0].replace(/ /, ""); // strip leading spaces
if (key == 'sidebar') {
var value = key_val[1];
if ((value == 'collapsed') && (!sidebar_is_collapsed()))
collapse_sidebar();
else if ((value == 'expanded') && (sidebar_is_collapsed()))
expand_sidebar();
}
}
}
add_sidebar_button();
var sidebarbutton = $('#sidebarbutton');
set_position_from_cookie();
});

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

View File

@@ -1,808 +0,0 @@
/*
* websupport.js
* ~~~~~~~~~~~~~
*
* sphinx.websupport utilties for all documentation.
*
* :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
(function($) {
$.fn.autogrow = function() {
return this.each(function() {
var textarea = this;
$.fn.autogrow.resize(textarea);
$(textarea)
.focus(function() {
textarea.interval = setInterval(function() {
$.fn.autogrow.resize(textarea);
}, 500);
})
.blur(function() {
clearInterval(textarea.interval);
});
});
};
$.fn.autogrow.resize = function(textarea) {
var lineHeight = parseInt($(textarea).css('line-height'), 10);
var lines = textarea.value.split('\n');
var columns = textarea.cols;
var lineCount = 0;
$.each(lines, function() {
lineCount += Math.ceil(this.length / columns) || 1;
});
var height = lineHeight * (lineCount + 1);
$(textarea).css('height', height);
};
})(jQuery);
(function($) {
var comp, by;
function init() {
initEvents();
initComparator();
}
function initEvents() {
$('a.comment-close').live("click", function(event) {
event.preventDefault();
hide($(this).attr('id').substring(2));
});
$('a.vote').live("click", function(event) {
event.preventDefault();
handleVote($(this));
});
$('a.reply').live("click", function(event) {
event.preventDefault();
openReply($(this).attr('id').substring(2));
});
$('a.close-reply').live("click", function(event) {
event.preventDefault();
closeReply($(this).attr('id').substring(2));
});
$('a.sort-option').live("click", function(event) {
event.preventDefault();
handleReSort($(this));
});
$('a.show-proposal').live("click", function(event) {
event.preventDefault();
showProposal($(this).attr('id').substring(2));
});
$('a.hide-proposal').live("click", function(event) {
event.preventDefault();
hideProposal($(this).attr('id').substring(2));
});
$('a.show-propose-change').live("click", function(event) {
event.preventDefault();
showProposeChange($(this).attr('id').substring(2));
});
$('a.hide-propose-change').live("click", function(event) {
event.preventDefault();
hideProposeChange($(this).attr('id').substring(2));
});
$('a.accept-comment').live("click", function(event) {
event.preventDefault();
acceptComment($(this).attr('id').substring(2));
});
$('a.delete-comment').live("click", function(event) {
event.preventDefault();
deleteComment($(this).attr('id').substring(2));
});
$('a.comment-markup').live("click", function(event) {
event.preventDefault();
toggleCommentMarkupBox($(this).attr('id').substring(2));
});
}
/**
* Set comp, which is a comparator function used for sorting and
* inserting comments into the list.
*/
function setComparator() {
// If the first three letters are "asc", sort in ascending order
// and remove the prefix.
if (by.substring(0,3) == 'asc') {
var i = by.substring(3);
comp = function(a, b) { return a[i] - b[i]; };
} else {
// Otherwise sort in descending order.
comp = function(a, b) { return b[by] - a[by]; };
}
// Reset link styles and format the selected sort option.
$('a.sel').attr('href', '#').removeClass('sel');
$('a.by' + by).removeAttr('href').addClass('sel');
}
/**
* Create a comp function. If the user has preferences stored in
* the sortBy cookie, use those, otherwise use the default.
*/
function initComparator() {
by = 'rating'; // Default to sort by rating.
// If the sortBy cookie is set, use that instead.
if (document.cookie.length > 0) {
var start = document.cookie.indexOf('sortBy=');
if (start != -1) {
start = start + 7;
var end = document.cookie.indexOf(";", start);
if (end == -1) {
end = document.cookie.length;
by = unescape(document.cookie.substring(start, end));
}
}
}
setComparator();
}
/**
* Show a comment div.
*/
function show(id) {
$('#ao' + id).hide();
$('#ah' + id).show();
var context = $.extend({id: id}, opts);
var popup = $(renderTemplate(popupTemplate, context)).hide();
popup.find('textarea[name="proposal"]').hide();
popup.find('a.by' + by).addClass('sel');
var form = popup.find('#cf' + id);
form.submit(function(event) {
event.preventDefault();
addComment(form);
});
$('#s' + id).after(popup);
popup.slideDown('fast', function() {
getComments(id);
});
}
/**
* Hide a comment div.
*/
function hide(id) {
$('#ah' + id).hide();
$('#ao' + id).show();
var div = $('#sc' + id);
div.slideUp('fast', function() {
div.remove();
});
}
/**
* Perform an ajax request to get comments for a node
* and insert the comments into the comments tree.
*/
function getComments(id) {
$.ajax({
type: 'GET',
url: opts.getCommentsURL,
data: {node: id},
success: function(data, textStatus, request) {
var ul = $('#cl' + id);
var speed = 100;
$('#cf' + id)
.find('textarea[name="proposal"]')
.data('source', data.source);
if (data.comments.length === 0) {
ul.html('<li>No comments yet.</li>');
ul.data('empty', true);
} else {
// If there are comments, sort them and put them in the list.
var comments = sortComments(data.comments);
speed = data.comments.length * 100;
appendComments(comments, ul);
ul.data('empty', false);
}
$('#cn' + id).slideUp(speed + 200);
ul.slideDown(speed);
},
error: function(request, textStatus, error) {
showError('Oops, there was a problem retrieving the comments.');
},
dataType: 'json'
});
}
/**
* Add a comment via ajax and insert the comment into the comment tree.
*/
function addComment(form) {
var node_id = form.find('input[name="node"]').val();
var parent_id = form.find('input[name="parent"]').val();
var text = form.find('textarea[name="comment"]').val();
var proposal = form.find('textarea[name="proposal"]').val();
if (text == '') {
showError('Please enter a comment.');
return;
}
// Disable the form that is being submitted.
form.find('textarea,input').attr('disabled', 'disabled');
// Send the comment to the server.
$.ajax({
type: "POST",
url: opts.addCommentURL,
dataType: 'json',
data: {
node: node_id,
parent: parent_id,
text: text,
proposal: proposal
},
success: function(data, textStatus, error) {
// Reset the form.
if (node_id) {
hideProposeChange(node_id);
}
form.find('textarea')
.val('')
.add(form.find('input'))
.removeAttr('disabled');
var ul = $('#cl' + (node_id || parent_id));
if (ul.data('empty')) {
$(ul).empty();
ul.data('empty', false);
}
insertComment(data.comment);
var ao = $('#ao' + node_id);
ao.find('img').attr({'src': opts.commentBrightImage});
if (node_id) {
// if this was a "root" comment, remove the commenting box
// (the user can get it back by reopening the comment popup)
$('#ca' + node_id).slideUp();
}
},
error: function(request, textStatus, error) {
form.find('textarea,input').removeAttr('disabled');
showError('Oops, there was a problem adding the comment.');
}
});
}
/**
* Recursively append comments to the main comment list and children
* lists, creating the comment tree.
*/
function appendComments(comments, ul) {
$.each(comments, function() {
var div = createCommentDiv(this);
ul.append($(document.createElement('li')).html(div));
appendComments(this.children, div.find('ul.comment-children'));
// To avoid stagnating data, don't store the comments children in data.
this.children = null;
div.data('comment', this);
});
}
/**
* After adding a new comment, it must be inserted in the correct
* location in the comment tree.
*/
function insertComment(comment) {
var div = createCommentDiv(comment);
// To avoid stagnating data, don't store the comments children in data.
comment.children = null;
div.data('comment', comment);
var ul = $('#cl' + (comment.node || comment.parent));
var siblings = getChildren(ul);
var li = $(document.createElement('li'));
li.hide();
// Determine where in the parents children list to insert this comment.
for(i=0; i < siblings.length; i++) {
if (comp(comment, siblings[i]) <= 0) {
$('#cd' + siblings[i].id)
.parent()
.before(li.html(div));
li.slideDown('fast');
return;
}
}
// If we get here, this comment rates lower than all the others,
// or it is the only comment in the list.
ul.append(li.html(div));
li.slideDown('fast');
}
function acceptComment(id) {
$.ajax({
type: 'POST',
url: opts.acceptCommentURL,
data: {id: id},
success: function(data, textStatus, request) {
$('#cm' + id).fadeOut('fast');
$('#cd' + id).removeClass('moderate');
},
error: function(request, textStatus, error) {
showError('Oops, there was a problem accepting the comment.');
}
});
}
function deleteComment(id) {
$.ajax({
type: 'POST',
url: opts.deleteCommentURL,
data: {id: id},
success: function(data, textStatus, request) {
var div = $('#cd' + id);
if (data == 'delete') {
// Moderator mode: remove the comment and all children immediately
div.slideUp('fast', function() {
div.remove();
});
return;
}
// User mode: only mark the comment as deleted
div
.find('span.user-id:first')
.text('[deleted]').end()
.find('div.comment-text:first')
.text('[deleted]').end()
.find('#cm' + id + ', #dc' + id + ', #ac' + id + ', #rc' + id +
', #sp' + id + ', #hp' + id + ', #cr' + id + ', #rl' + id)
.remove();
var comment = div.data('comment');
comment.username = '[deleted]';
comment.text = '[deleted]';
div.data('comment', comment);
},
error: function(request, textStatus, error) {
showError('Oops, there was a problem deleting the comment.');
}
});
}
function showProposal(id) {
$('#sp' + id).hide();
$('#hp' + id).show();
$('#pr' + id).slideDown('fast');
}
function hideProposal(id) {
$('#hp' + id).hide();
$('#sp' + id).show();
$('#pr' + id).slideUp('fast');
}
function showProposeChange(id) {
$('#pc' + id).hide();
$('#hc' + id).show();
var textarea = $('#pt' + id);
textarea.val(textarea.data('source'));
$.fn.autogrow.resize(textarea[0]);
textarea.slideDown('fast');
}
function hideProposeChange(id) {
$('#hc' + id).hide();
$('#pc' + id).show();
var textarea = $('#pt' + id);
textarea.val('').removeAttr('disabled');
textarea.slideUp('fast');
}
function toggleCommentMarkupBox(id) {
$('#mb' + id).toggle();
}
/** Handle when the user clicks on a sort by link. */
function handleReSort(link) {
var classes = link.attr('class').split(/\s+/);
for (var i=0; i<classes.length; i++) {
if (classes[i] != 'sort-option') {
by = classes[i].substring(2);
}
}
setComparator();
// Save/update the sortBy cookie.
var expiration = new Date();
expiration.setDate(expiration.getDate() + 365);
document.cookie= 'sortBy=' + escape(by) +
';expires=' + expiration.toUTCString();
$('ul.comment-ul').each(function(index, ul) {
var comments = getChildren($(ul), true);
comments = sortComments(comments);
appendComments(comments, $(ul).empty());
});
}
/**
* Function to process a vote when a user clicks an arrow.
*/
function handleVote(link) {
if (!opts.voting) {
showError("You'll need to login to vote.");
return;
}
var id = link.attr('id');
if (!id) {
// Didn't click on one of the voting arrows.
return;
}
// If it is an unvote, the new vote value is 0,
// Otherwise it's 1 for an upvote, or -1 for a downvote.
var value = 0;
if (id.charAt(1) != 'u') {
value = id.charAt(0) == 'u' ? 1 : -1;
}
// The data to be sent to the server.
var d = {
comment_id: id.substring(2),
value: value
};
// Swap the vote and unvote links.
link.hide();
$('#' + id.charAt(0) + (id.charAt(1) == 'u' ? 'v' : 'u') + d.comment_id)
.show();
// The div the comment is displayed in.
var div = $('div#cd' + d.comment_id);
var data = div.data('comment');
// If this is not an unvote, and the other vote arrow has
// already been pressed, unpress it.
if ((d.value !== 0) && (data.vote === d.value * -1)) {
$('#' + (d.value == 1 ? 'd' : 'u') + 'u' + d.comment_id).hide();
$('#' + (d.value == 1 ? 'd' : 'u') + 'v' + d.comment_id).show();
}
// Update the comments rating in the local data.
data.rating += (data.vote === 0) ? d.value : (d.value - data.vote);
data.vote = d.value;
div.data('comment', data);
// Change the rating text.
div.find('.rating:first')
.text(data.rating + ' point' + (data.rating == 1 ? '' : 's'));
// Send the vote information to the server.
$.ajax({
type: "POST",
url: opts.processVoteURL,
data: d,
error: function(request, textStatus, error) {
showError('Oops, there was a problem casting that vote.');
}
});
}
/**
* Open a reply form used to reply to an existing comment.
*/
function openReply(id) {
// Swap out the reply link for the hide link
$('#rl' + id).hide();
$('#cr' + id).show();
// Add the reply li to the children ul.
var div = $(renderTemplate(replyTemplate, {id: id})).hide();
$('#cl' + id)
.prepend(div)
// Setup the submit handler for the reply form.
.find('#rf' + id)
.submit(function(event) {
event.preventDefault();
addComment($('#rf' + id));
closeReply(id);
})
.find('input[type=button]')
.click(function() {
closeReply(id);
});
div.slideDown('fast', function() {
$('#rf' + id).find('textarea').focus();
});
}
/**
* Close the reply form opened with openReply.
*/
function closeReply(id) {
// Remove the reply div from the DOM.
$('#rd' + id).slideUp('fast', function() {
$(this).remove();
});
// Swap out the hide link for the reply link
$('#cr' + id).hide();
$('#rl' + id).show();
}
/**
* Recursively sort a tree of comments using the comp comparator.
*/
function sortComments(comments) {
comments.sort(comp);
$.each(comments, function() {
this.children = sortComments(this.children);
});
return comments;
}
/**
* Get the children comments from a ul. If recursive is true,
* recursively include childrens' children.
*/
function getChildren(ul, recursive) {
var children = [];
ul.children().children("[id^='cd']")
.each(function() {
var comment = $(this).data('comment');
if (recursive)
comment.children = getChildren($(this).find('#cl' + comment.id), true);
children.push(comment);
});
return children;
}
/** Create a div to display a comment in. */
function createCommentDiv(comment) {
if (!comment.displayed && !opts.moderator) {
return $('<div class="moderate">Thank you! Your comment will show up '
+ 'once it is has been approved by a moderator.</div>');
}
// Prettify the comment rating.
comment.pretty_rating = comment.rating + ' point' +
(comment.rating == 1 ? '' : 's');
// Make a class (for displaying not yet moderated comments differently)
comment.css_class = comment.displayed ? '' : ' moderate';
// Create a div for this comment.
var context = $.extend({}, opts, comment);
var div = $(renderTemplate(commentTemplate, context));
// If the user has voted on this comment, highlight the correct arrow.
if (comment.vote) {
var direction = (comment.vote == 1) ? 'u' : 'd';
div.find('#' + direction + 'v' + comment.id).hide();
div.find('#' + direction + 'u' + comment.id).show();
}
if (opts.moderator || comment.text != '[deleted]') {
div.find('a.reply').show();
if (comment.proposal_diff)
div.find('#sp' + comment.id).show();
if (opts.moderator && !comment.displayed)
div.find('#cm' + comment.id).show();
if (opts.moderator || (opts.username == comment.username))
div.find('#dc' + comment.id).show();
}
return div;
}
/**
* A simple template renderer. Placeholders such as <%id%> are replaced
* by context['id'] with items being escaped. Placeholders such as <#id#>
* are not escaped.
*/
function renderTemplate(template, context) {
var esc = $(document.createElement('div'));
function handle(ph, escape) {
var cur = context;
$.each(ph.split('.'), function() {
cur = cur[this];
});
return escape ? esc.text(cur || "").html() : cur;
}
return template.replace(/<([%#])([\w\.]*)\1>/g, function() {
return handle(arguments[2], arguments[1] == '%' ? true : false);
});
}
/** Flash an error message briefly. */
function showError(message) {
$(document.createElement('div')).attr({'class': 'popup-error'})
.append($(document.createElement('div'))
.attr({'class': 'error-message'}).text(message))
.appendTo('body')
.fadeIn("slow")
.delay(2000)
.fadeOut("slow");
}
/** Add a link the user uses to open the comments popup. */
$.fn.comment = function() {
return this.each(function() {
var id = $(this).attr('id').substring(1);
var count = COMMENT_METADATA[id];
var title = count + ' comment' + (count == 1 ? '' : 's');
var image = count > 0 ? opts.commentBrightImage : opts.commentImage;
var addcls = count == 0 ? ' nocomment' : '';
$(this)
.append(
$(document.createElement('a')).attr({
href: '#',
'class': 'sphinx-comment-open' + addcls,
id: 'ao' + id
})
.append($(document.createElement('img')).attr({
src: image,
alt: 'comment',
title: title
}))
.click(function(event) {
event.preventDefault();
show($(this).attr('id').substring(2));
})
)
.append(
$(document.createElement('a')).attr({
href: '#',
'class': 'sphinx-comment-close hidden',
id: 'ah' + id
})
.append($(document.createElement('img')).attr({
src: opts.closeCommentImage,
alt: 'close',
title: 'close'
}))
.click(function(event) {
event.preventDefault();
hide($(this).attr('id').substring(2));
})
);
});
};
var opts = {
processVoteURL: '/_process_vote',
addCommentURL: '/_add_comment',
getCommentsURL: '/_get_comments',
acceptCommentURL: '/_accept_comment',
deleteCommentURL: '/_delete_comment',
commentImage: '/static/_static/comment.png',
closeCommentImage: '/static/_static/comment-close.png',
loadingImage: '/static/_static/ajax-loader.gif',
commentBrightImage: '/static/_static/comment-bright.png',
upArrow: '/static/_static/up.png',
downArrow: '/static/_static/down.png',
upArrowPressed: '/static/_static/up-pressed.png',
downArrowPressed: '/static/_static/down-pressed.png',
voting: false,
moderator: false
};
if (typeof COMMENT_OPTIONS != "undefined") {
opts = jQuery.extend(opts, COMMENT_OPTIONS);
}
var popupTemplate = '\
<div class="sphinx-comments" id="sc<%id%>">\
<p class="sort-options">\
Sort by:\
<a href="#" class="sort-option byrating">best rated</a>\
<a href="#" class="sort-option byascage">newest</a>\
<a href="#" class="sort-option byage">oldest</a>\
</p>\
<div class="comment-header">Comments</div>\
<div class="comment-loading" id="cn<%id%>">\
loading comments... <img src="<%loadingImage%>" alt="" /></div>\
<ul id="cl<%id%>" class="comment-ul"></ul>\
<div id="ca<%id%>">\
<p class="add-a-comment">Add a comment\
(<a href="#" class="comment-markup" id="ab<%id%>">markup</a>):</p>\
<div class="comment-markup-box" id="mb<%id%>">\
reStructured text markup: <i>*emph*</i>, <b>**strong**</b>, \
<tt>``code``</tt>, \
code blocks: <tt>::</tt> and an indented block after blank line</div>\
<form method="post" id="cf<%id%>" class="comment-form" action="">\
<textarea name="comment" cols="80"></textarea>\
<p class="propose-button">\
<a href="#" id="pc<%id%>" class="show-propose-change">\
Propose a change &#9657;\
</a>\
<a href="#" id="hc<%id%>" class="hide-propose-change">\
Propose a change &#9663;\
</a>\
</p>\
<textarea name="proposal" id="pt<%id%>" cols="80"\
spellcheck="false"></textarea>\
<input type="submit" value="Add comment" />\
<input type="hidden" name="node" value="<%id%>" />\
<input type="hidden" name="parent" value="" />\
</form>\
</div>\
</div>';
var commentTemplate = '\
<div id="cd<%id%>" class="sphinx-comment<%css_class%>">\
<div class="vote">\
<div class="arrow">\
<a href="#" id="uv<%id%>" class="vote" title="vote up">\
<img src="<%upArrow%>" />\
</a>\
<a href="#" id="uu<%id%>" class="un vote" title="vote up">\
<img src="<%upArrowPressed%>" />\
</a>\
</div>\
<div class="arrow">\
<a href="#" id="dv<%id%>" class="vote" title="vote down">\
<img src="<%downArrow%>" id="da<%id%>" />\
</a>\
<a href="#" id="du<%id%>" class="un vote" title="vote down">\
<img src="<%downArrowPressed%>" />\
</a>\
</div>\
</div>\
<div class="comment-content">\
<p class="tagline comment">\
<span class="user-id"><%username%></span>\
<span class="rating"><%pretty_rating%></span>\
<span class="delta"><%time.delta%></span>\
</p>\
<div class="comment-text comment"><#text#></div>\
<p class="comment-opts comment">\
<a href="#" class="reply hidden" id="rl<%id%>">reply &#9657;</a>\
<a href="#" class="close-reply" id="cr<%id%>">reply &#9663;</a>\
<a href="#" id="sp<%id%>" class="show-proposal">proposal &#9657;</a>\
<a href="#" id="hp<%id%>" class="hide-proposal">proposal &#9663;</a>\
<a href="#" id="dc<%id%>" class="delete-comment hidden">delete</a>\
<span id="cm<%id%>" class="moderation hidden">\
<a href="#" id="ac<%id%>" class="accept-comment">accept</a>\
</span>\
</p>\
<pre class="proposal" id="pr<%id%>">\
<#proposal_diff#>\
</pre>\
<ul class="comment-children" id="cl<%id%>"></ul>\
</div>\
<div class="clearleft"></div>\
</div>\
</div>';
var replyTemplate = '\
<li>\
<div class="reply-div" id="rd<%id%>">\
<form id="rf<%id%>">\
<textarea name="comment" cols="80"></textarea>\
<input type="submit" value="Add reply" />\
<input type="button" value="Cancel" />\
<input type="hidden" name="parent" value="<%id%>" />\
<input type="hidden" name="node" value="" />\
</form>\
</div>\
</li>';
$(document).ready(function() {
init();
});
})(jQuery);
$(document).ready(function() {
// add comment anchors for all paragraphs that are commentable
$('.sphinx-has-comment').comment();
// highlight search words in search results
$("div.context").each(function() {
var params = $.getQueryParameters();
var terms = (params.q) ? params.q[0].split(/\s+/) : [];
var result = $(this);
$.each(terms, function() {
result.highlightText(this.toLowerCase(), 'highlighted');
});
});
// directly open comment window if requested
var anchor = document.location.hash;
if (anchor.substring(0, 9) == '#comment-') {
$('#ao' + anchor.substring(9)).click();
document.location.hash = '#s' + anchor.substring(9);
}
});

View File

@@ -1,79 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Index - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="#" />
<link rel="search" title="Search" href="search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="index.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="index.html"><img
alt="C++ Boost" src="_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
</div>
<h1 id="index">Index</h1>
<div class="genindex-jumpbox">
</div>
<div class="navbar" style="text-align:right;">
</div>
</div>
</body>
</html>

View File

@@ -1,98 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to the documentation of the Boost.Python NumPy extension! - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="#" />
<link rel="next" title="Boost.Python NumPy extension Tutorial" href="tutorial/index.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="#"><img
alt="C++ Boost" src="_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="#">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="next" title="Boost.Python NumPy extension Tutorial" href="tutorial/index.html"><img src="_static/next.png" alt="next"/></a>
</div>
<div class="section" id="welcome-to-the-documentation-of-the-boost-python-numpy-extension">
<h1>Welcome to the documentation of the Boost.Python NumPy extension!</h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="tutorial/index.html">Tutorial</a><ul>
<li class="toctree-l2"><a class="reference internal" href="tutorial/simple.html">A simple tutorial on Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial/dtype.html">How to use dtypes</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial/ndarray.html">Creating ndarrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial/ufunc.html">Ufuncs</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial/fromdata.html">How to access data using raw pointers</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="reference/index.html">Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="reference/dtype.html">dtype</a></li>
<li class="toctree-l2"><a class="reference internal" href="reference/ndarray.html">ndarray</a></li>
<li class="toctree-l2"><a class="reference internal" href="reference/unary_ufunc.html">unary_ufunc</a></li>
<li class="toctree-l2"><a class="reference internal" href="reference/binary_ufunc.html">binary_ufunc</a></li>
<li class="toctree-l2"><a class="reference internal" href="reference/multi_iter.html">multi_iter</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="next" title="Boost.Python NumPy extension Tutorial" href="tutorial/index.html"><img src="_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

Binary file not shown.

View File

@@ -1,211 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>binary_ufunc - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Reference" href="index.html" />
<link rel="next" title="multi_iter" href="multi_iter.html" />
<link rel="prev" title="unary_ufunc" href="unary_ufunc.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="unary_ufunc" href="unary_ufunc.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="multi_iter" href="multi_iter.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="binary-ufunc">
<h1><a class="toc-backref" href="#id1">binary_ufunc</a></h1>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#binary-ufunc" id="id1">binary_ufunc</a><ul>
<li><a class="reference internal" href="#synopsis" id="id2">synopsis</a></li>
<li><a class="reference internal" href="#constructors" id="id3">constructors</a></li>
<li><a class="reference internal" href="#accessors" id="id4">accessors</a></li>
<li><a class="reference internal" href="#example-s" id="id5">Example(s)</a></li>
</ul>
</li>
</ul>
</div>
<p>A <tt class="docutils literal"><span class="pre">binary_ufunc</span></tt> is a struct used as an intermediate step to broadcast two arguments so that a C++ function can be converted to a ufunc like function</p>
<blockquote>
<div><tt class="docutils literal"><span class="pre">&lt;boost/python/numpy/ufunc.hpp&gt;</span></tt> contains the <tt class="docutils literal"><span class="pre">binary_ufunc</span></tt> structure definitions</div></blockquote>
<div class="section" id="synopsis">
<h2><a class="toc-backref" href="#id2">synopsis</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">boost</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">python</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">numpy</span>
<span class="p">{</span>
<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument1</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">first_argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument2</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">second_argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TResult</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">result_type</span><span class="o">&gt;</span>
<span class="k">struct</span> <span class="n">binary_ufunc</span>
<span class="p">{</span>
<span class="k">static</span> <span class="n">object</span> <span class="n">call</span><span class="p">(</span><span class="n">TBinaryFunctor</span> <span class="o">&amp;</span> <span class="n">self</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">input1</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">input2</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">output</span><span class="p">);</span>
<span class="k">static</span> <span class="n">object</span> <span class="nf">make</span><span class="p">();</span>
<span class="p">};</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="constructors">
<h2><a class="toc-backref" href="#id3">constructors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">example_binary_ufunc</span>
<span class="p">{</span>
<span class="k">typedef</span> <span class="n">any_valid</span> <span class="n">first_argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="n">any_valid</span> <span class="n">second_argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="n">any_valid</span> <span class="n">result_type</span><span class="p">;</span>
<span class="p">};</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body">The <tt class="docutils literal"><span class="pre">any_valid</span></tt> type must be defined using typedef as a valid C++ type in order to use the struct methods correctly</td>
</tr>
<tr class="field-even field"><th class="field-name">Note:</th><td class="field-body">The struct must be exposed as a Python class, and an instance of the class must be created to use the <tt class="docutils literal"><span class="pre">call</span></tt> method corresponding to the <tt class="docutils literal"><span class="pre">__call__</span></tt> attribute of the Python object</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="accessors">
<h2><a class="toc-backref" href="#id4">accessors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument1</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">first_argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument2</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">second_argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TResult</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">result_type</span><span class="o">&gt;</span>
<span class="k">static</span> <span class="n">object</span> <span class="n">call</span><span class="p">(</span><span class="n">TBinaryFunctor</span> <span class="o">&amp;</span> <span class="n">self</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">input</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">output</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requires:</th><td class="field-body">Typenames <tt class="docutils literal"><span class="pre">TBinaryFunctor</span></tt> and optionally <tt class="docutils literal"><span class="pre">TArgument1</span></tt> and <tt class="docutils literal"><span class="pre">TArgument2</span></tt> for argument type and <tt class="docutils literal"><span class="pre">TResult</span></tt> for result type</td>
</tr>
<tr class="field-even field"><th class="field-name">Effects:</th><td class="field-body">Passes a Python object to the underlying C++ functor after broadcasting its arguments</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument1</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">first_argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument2</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">second_argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TResult</span><span class="o">=</span><span class="k">typename</span> <span class="n">TBinaryFunctor</span><span class="o">::</span><span class="n">result_type</span><span class="o">&gt;</span>
<span class="k">static</span> <span class="n">object</span> <span class="n">make</span><span class="p">();</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requires:</th><td class="field-body">Typenames <tt class="docutils literal"><span class="pre">TBinaryFunctor</span></tt> and optionally <tt class="docutils literal"><span class="pre">TArgument1</span></tt> and <tt class="docutils literal"><span class="pre">TArgument2</span></tt> for argument type and <tt class="docutils literal"><span class="pre">TResult</span></tt> for result type</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">A Python function object to call the overloaded () operator in the struct (in typical usage)</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="example-s">
<h2><a class="toc-backref" href="#id5">Example(s)</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">BinarySquare</span>
<span class="p">{</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">first_argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">second_argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">result_type</span><span class="p">;</span>
<span class="kt">double</span> <span class="nf">operator</span><span class="p">()(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span><span class="kt">double</span> <span class="n">b</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">b</span><span class="p">)</span> <span class="p">;</span> <span class="p">}</span>
<span class="p">};</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">ud</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">class_</span><span class="o">&lt;</span><span class="n">BinarySquare</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">BinarySquare</span><span class="o">&gt;</span> <span class="o">&gt;</span><span class="p">(</span><span class="s">&quot;BinarySquare&quot;</span><span class="p">).</span><span class="n">def</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">,</span> <span class="n">np</span><span class="o">::</span><span class="n">binary_ufunc</span><span class="o">&lt;</span><span class="n">BinarySquare</span><span class="o">&gt;::</span><span class="n">make</span><span class="p">());</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">inst</span> <span class="o">=</span> <span class="n">ud</span><span class="p">();</span>
<span class="n">result_array</span> <span class="o">=</span> <span class="n">inst</span><span class="p">.</span><span class="n">attr</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">)(</span><span class="n">demo_array</span><span class="p">,</span><span class="n">demo_array</span><span class="p">)</span> <span class="p">;</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Square of list with binary ufunc is &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span> <span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*</span> <span class="o">&gt;</span> <span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">result_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="p">;</span>
</pre></div>
</div>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="unary_ufunc" href="unary_ufunc.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="multi_iter" href="multi_iter.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,195 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dtype - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Reference" href="index.html" />
<link rel="next" title="ndarray" href="ndarray.html" />
<link rel="prev" title="Boost.Python NumPy extension Reference" href="index.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="ndarray" href="ndarray.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="dtype">
<h1><a class="toc-backref" href="#id2">dtype</a></h1>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#dtype" id="id2">dtype</a><ul>
<li><a class="reference internal" href="#synopsis" id="id3">synopsis</a></li>
<li><a class="reference internal" href="#constructors" id="id4">constructors</a></li>
<li><a class="reference internal" href="#accessors" id="id5">accessors</a></li>
<li><a class="reference internal" href="#example-s" id="id6">Example(s)</a></li>
</ul>
</li>
</ul>
</div>
<p>A <a class="reference external" href="http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#data-type-objects-dtype">dtype</a> is an object describing the type of the elements of an ndarray</p>
<blockquote>
<div><tt class="docutils literal"><span class="pre">&lt;boost/python/numpy/dtype.hpp&gt;</span></tt> contains the method calls necessary to generate a python object equivalent to a numpy.dtype from builtin C++ objects, as well as to create custom dtypes from user defined types</div></blockquote>
<div class="section" id="synopsis">
<h2><a class="toc-backref" href="#id3">synopsis</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">boost</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">python</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">numpy</span>
<span class="p">{</span>
<span class="k">class</span> <span class="nc">dtype</span> <span class="o">:</span> <span class="k">public</span> <span class="n">object</span>
<span class="p">{</span>
<span class="k">static</span> <span class="n">python</span><span class="o">::</span><span class="n">detail</span><span class="o">::</span><span class="n">new_reference</span> <span class="n">convert</span><span class="p">(</span><span class="n">object</span><span class="o">::</span><span class="n">object_cref</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="p">);</span>
<span class="nl">public:</span>
<span class="c1">// Convert an arbitrary Python object to a data-type descriptor object.</span>
<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="k">explicit</span> <span class="n">dtype</span><span class="p">(</span><span class="n">T</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="o">=</span><span class="nb">false</span><span class="p">);</span>
<span class="c1">// Get the built-in numpy dtype associated with the given scalar template type.</span>
<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span> <span class="k">static</span> <span class="n">dtype</span> <span class="n">get_builtin</span><span class="p">();</span>
<span class="c1">// Return the size of the data type in bytes.</span>
<span class="kt">int</span> <span class="n">get_itemsize</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="p">};</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="constructors">
<h2><a class="toc-backref" href="#id4">constructors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="k">explicit</span> <span class="n">dtype</span><span class="p">(</span><span class="n">T</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="o">=</span><span class="nb">false</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first"><tt class="docutils literal"><span class="pre">T</span></tt> must be either :</p>
<ul class="simple">
<li>a built-in C++ typename convertible to object</li>
<li>a valid python object or convertible to object</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Effects:</th><td class="field-body"><p class="first">Constructs an object from the supplied python object / convertible
to object / builtin C++ data type</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Throws:</th><td class="field-body"><p class="first last">Nothing</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span> <span class="k">static</span> <span class="n">dtype</span> <span class="n">get_builtin</span><span class="p">();</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body">The typename supplied, <tt class="docutils literal"><span class="pre">T</span></tt> must be a builtin C++ type also supported by numpy</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Numpy dtype corresponding to builtin C++ type</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="accessors">
<h2><a class="toc-backref" href="#id5">accessors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="n">get_itemsize</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">the size of the data type in bytes.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="example-s">
<h2><a class="toc-backref" href="#id6">Example(s)</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;</span><span class="p">();</span>
<span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">for_custom_dtype</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="s">&quot;ha&quot;</span><span class="p">,</span><span class="n">dtype</span><span class="p">);</span>
<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">custom_dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="p">(</span><span class="n">list_for_dtype</span><span class="p">);</span>
</pre></div>
</div>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="ndarray" href="ndarray.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,119 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Boost.Python NumPy extension Reference - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="next" title="dtype" href="dtype.html" />
<link rel="prev" title="How to access data using raw pointers" href="../tutorial/fromdata.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="How to access data using raw pointers" href="../tutorial/fromdata.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="next" title="dtype" href="dtype.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="boost-python-numpy-extension-reference">
<h1>Boost.Python NumPy extension Reference</h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="dtype.html">dtype</a><ul>
<li class="toctree-l2"><a class="reference internal" href="dtype.html#synopsis">synopsis</a></li>
<li class="toctree-l2"><a class="reference internal" href="dtype.html#constructors">constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="dtype.html#accessors">accessors</a></li>
<li class="toctree-l2"><a class="reference internal" href="dtype.html#example-s">Example(s)</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="ndarray.html">ndarray</a><ul>
<li class="toctree-l2"><a class="reference internal" href="ndarray.html#synopsis">synopsis</a></li>
<li class="toctree-l2"><a class="reference internal" href="ndarray.html#constructors">constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="ndarray.html#accessors">accessors</a></li>
<li class="toctree-l2"><a class="reference internal" href="ndarray.html#example-s">Example(s)</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="unary_ufunc.html">unary_ufunc</a><ul>
<li class="toctree-l2"><a class="reference internal" href="unary_ufunc.html#synopsis">synopsis</a></li>
<li class="toctree-l2"><a class="reference internal" href="unary_ufunc.html#constructors">constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="unary_ufunc.html#accessors">accessors</a></li>
<li class="toctree-l2"><a class="reference internal" href="unary_ufunc.html#example-s">Example(s)</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="binary_ufunc.html">binary_ufunc</a><ul>
<li class="toctree-l2"><a class="reference internal" href="binary_ufunc.html#synopsis">synopsis</a></li>
<li class="toctree-l2"><a class="reference internal" href="binary_ufunc.html#constructors">constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="binary_ufunc.html#accessors">accessors</a></li>
<li class="toctree-l2"><a class="reference internal" href="binary_ufunc.html#example-s">Example(s)</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="multi_iter.html">multi_iter</a><ul>
<li class="toctree-l2"><a class="reference internal" href="multi_iter.html#synopsis">synopsis</a></li>
<li class="toctree-l2"><a class="reference internal" href="multi_iter.html#constructors">constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="multi_iter.html#accessors">accessors</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="How to access data using raw pointers" href="../tutorial/fromdata.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="next" title="dtype" href="dtype.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,211 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>multi_iter - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Reference" href="index.html" />
<link rel="prev" title="binary_ufunc" href="binary_ufunc.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="binary_ufunc" href="binary_ufunc.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
</div>
<div class="section" id="multi-iter">
<h1><a class="toc-backref" href="#id1">multi_iter</a></h1>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#multi-iter" id="id1">multi_iter</a><ul>
<li><a class="reference internal" href="#synopsis" id="id2">synopsis</a></li>
<li><a class="reference internal" href="#constructors" id="id3">constructors</a></li>
<li><a class="reference internal" href="#accessors" id="id4">accessors</a></li>
</ul>
</li>
</ul>
</div>
<p>A <tt class="docutils literal"><span class="pre">multi_iter</span></tt> is a Python object, intended to be used as an iterator It should generally only be used in loops.</p>
<blockquote>
<div><tt class="docutils literal"><span class="pre">&lt;boost/python/numpy/ufunc.hpp&gt;</span></tt> contains the class definitions for <tt class="docutils literal"><span class="pre">multi_iter</span></tt></div></blockquote>
<div class="section" id="synopsis">
<h2><a class="toc-backref" href="#id2">synopsis</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">boost</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">python</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">numpy</span>
<span class="p">{</span>
<span class="k">class</span> <span class="nc">multi_iter</span> <span class="o">:</span> <span class="k">public</span> <span class="n">object</span>
<span class="p">{</span>
<span class="nl">public:</span>
<span class="kt">void</span> <span class="n">next</span><span class="p">();</span>
<span class="kt">bool</span> <span class="n">not_done</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="kt">char</span> <span class="o">*</span> <span class="n">get_data</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="kt">int</span> <span class="k">const</span> <span class="n">get_nd</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">get_shape</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="n">shape</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="p">};</span>
<span class="n">multi_iter</span> <span class="nf">make_multi_iter</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a1</span><span class="p">);</span>
<span class="n">multi_iter</span> <span class="nf">make_multi_iter</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a1</span><span class="p">,</span> <span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a2</span><span class="p">);</span>
<span class="n">multi_iter</span> <span class="nf">make_multi_iter</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a1</span><span class="p">,</span> <span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a2</span><span class="p">,</span> <span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a3</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="constructors">
<h2><a class="toc-backref" href="#id3">constructors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">multi_iter</span> <span class="nf">make_multi_iter</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a1</span><span class="p">);</span>
<span class="n">multi_iter</span> <span class="nf">make_multi_iter</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a1</span><span class="p">,</span> <span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a2</span><span class="p">);</span>
<span class="n">multi_iter</span> <span class="nf">make_multi_iter</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a1</span><span class="p">,</span> <span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a2</span><span class="p">,</span> <span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">a3</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A Python iterator object broadcasting over one, two or three sequences as supplied</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="accessors">
<h2><a class="toc-backref" href="#id4">accessors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">void</span> <span class="nf">next</span><span class="p">();</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Effects:</th><td class="field-body">Increments the iterator</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">bool</span> <span class="n">not_done</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">boolean value indicating whether the iterator is at its end</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">char</span> <span class="o">*</span> <span class="n">get_data</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a pointer to the element of the nth broadcasted array.</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="k">const</span> <span class="n">get_nd</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">the number of dimensions of the broadcasted array expression</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">get_shape</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">the shape of the broadcasted array expression as an array of integers.</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="n">shape</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">the shape of the broadcasted array expression in the nth dimension.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="binary_ufunc" href="binary_ufunc.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,628 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ndarray - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Reference" href="index.html" />
<link rel="next" title="unary_ufunc" href="unary_ufunc.html" />
<link rel="prev" title="dtype" href="dtype.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="dtype" href="dtype.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="unary_ufunc" href="unary_ufunc.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="ndarray">
<h1><a class="toc-backref" href="#id2">ndarray</a></h1>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#ndarray" id="id2">ndarray</a><ul>
<li><a class="reference internal" href="#synopsis" id="id3">synopsis</a></li>
<li><a class="reference internal" href="#constructors" id="id4">constructors</a></li>
<li><a class="reference internal" href="#accessors" id="id5">accessors</a></li>
<li><a class="reference internal" href="#example-s" id="id6">Example(s)</a></li>
</ul>
</li>
</ul>
</div>
<p>A <a class="reference external" href="http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html">ndarray</a> is an N-dimensional array which contains items of the same type and size, where N is the number of dimensions and is specified in the form of a <tt class="docutils literal"><span class="pre">shape</span></tt> tuple. Optionally, the numpy <tt class="docutils literal"><span class="pre">dtype</span></tt> for the objects contained may also be specified.</p>
<blockquote>
<div><tt class="docutils literal"><span class="pre">&lt;boost/python/numpy/ndarray.hpp&gt;</span></tt> contains the structures and methods necessary to move raw data between C++ and Python and create ndarrays from the data</div></blockquote>
<div class="section" id="synopsis">
<h2><a class="toc-backref" href="#id3">synopsis</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">boost</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">python</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">numpy</span>
<span class="p">{</span>
<span class="k">class</span> <span class="nc">ndarray</span> <span class="o">:</span> <span class="k">public</span> <span class="n">object</span>
<span class="p">{</span>
<span class="nl">public:</span>
<span class="k">enum</span> <span class="n">bitflag</span>
<span class="p">{</span>
<span class="n">NONE</span><span class="o">=</span><span class="mh">0x0</span><span class="p">,</span> <span class="n">C_CONTIGUOUS</span><span class="o">=</span><span class="mh">0x1</span><span class="p">,</span> <span class="n">F_CONTIGUOUS</span><span class="o">=</span><span class="mh">0x2</span><span class="p">,</span> <span class="n">V_CONTIGUOUS</span><span class="o">=</span><span class="mh">0x1</span><span class="o">|</span><span class="mh">0x2</span><span class="p">,</span>
<span class="n">ALIGNED</span><span class="o">=</span><span class="mh">0x4</span><span class="p">,</span> <span class="n">WRITEABLE</span><span class="o">=</span><span class="mh">0x8</span><span class="p">,</span> <span class="n">BEHAVED</span><span class="o">=</span><span class="mh">0x4</span><span class="o">|</span><span class="mh">0x8</span><span class="p">,</span>
<span class="n">CARRAY_RO</span><span class="o">=</span><span class="mh">0x1</span><span class="o">|</span><span class="mh">0x4</span><span class="p">,</span> <span class="n">CARRAY</span><span class="o">=</span><span class="mh">0x1</span><span class="o">|</span><span class="mh">0x4</span><span class="o">|</span><span class="mh">0x8</span><span class="p">,</span> <span class="n">CARRAY_MIS</span><span class="o">=</span><span class="mh">0x1</span><span class="o">|</span><span class="mh">0x8</span><span class="p">,</span>
<span class="n">FARRAY_RO</span><span class="o">=</span><span class="mh">0x2</span><span class="o">|</span><span class="mh">0x4</span><span class="p">,</span> <span class="n">FARRAY</span><span class="o">=</span><span class="mh">0x2</span><span class="o">|</span><span class="mh">0x4</span><span class="o">|</span><span class="mh">0x8</span><span class="p">,</span> <span class="n">FARRAY_MIS</span><span class="o">=</span><span class="mh">0x2</span><span class="o">|</span><span class="mh">0x8</span><span class="p">,</span>
<span class="n">UPDATE_ALL</span><span class="o">=</span><span class="mh">0x1</span><span class="o">|</span><span class="mh">0x2</span><span class="o">|</span><span class="mh">0x4</span><span class="p">,</span> <span class="n">VARRAY</span><span class="o">=</span><span class="mh">0x1</span><span class="o">|</span><span class="mh">0x2</span><span class="o">|</span><span class="mh">0x8</span><span class="p">,</span> <span class="n">ALL</span><span class="o">=</span><span class="mh">0x1</span><span class="o">|</span><span class="mh">0x2</span><span class="o">|</span><span class="mh">0x4</span><span class="o">|</span><span class="mh">0x8</span>
<span class="p">};</span>
<span class="n">ndarray</span> <span class="n">view</span><span class="p">(</span><span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="n">ndarray</span> <span class="n">astype</span><span class="p">(</span><span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="n">ndarray</span> <span class="n">copy</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="kt">int</span> <span class="k">const</span> <span class="n">shape</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="kt">int</span> <span class="k">const</span> <span class="n">strides</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="kt">char</span> <span class="o">*</span> <span class="n">get_data</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">dtype</span> <span class="n">get_dtype</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">python</span><span class="o">::</span><span class="n">object</span> <span class="n">get_base</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">set_base</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">base</span><span class="p">);</span>
<span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">get_shape</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">get_strides</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="kt">int</span> <span class="k">const</span> <span class="n">get_nd</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">bitflag</span> <span class="k">const</span> <span class="n">get_flags</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">ndarray</span> <span class="n">transpose</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">ndarray</span> <span class="n">squeeze</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="n">ndarray</span> <span class="n">reshape</span><span class="p">(</span><span class="n">tuple</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">shape</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
<span class="n">object</span> <span class="n">scalarize</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="p">};</span>
<span class="n">ndarray</span> <span class="nf">zeros</span><span class="p">(</span><span class="n">tuple</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">zeros</span><span class="p">(</span><span class="kt">int</span> <span class="n">nd</span><span class="p">,</span> <span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">empty</span><span class="p">(</span><span class="n">tuple</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">empty</span><span class="p">(</span><span class="kt">int</span> <span class="n">nd</span><span class="p">,</span> <span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">array</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">array</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Container</span><span class="o">&gt;</span>
<span class="n">ndarray</span> <span class="n">from_data</span><span class="p">(</span><span class="kt">void</span> <span class="o">*</span> <span class="n">data</span><span class="p">,</span><span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span><span class="n">Container</span> <span class="n">shape</span><span class="p">,</span><span class="n">Container</span> <span class="n">strides</span><span class="p">,</span><span class="n">python</span><span class="o">::</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">owner</span><span class="p">);</span>
<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Container</span><span class="o">&gt;</span>
<span class="n">ndarray</span> <span class="n">from_data</span><span class="p">(</span><span class="kt">void</span> <span class="k">const</span> <span class="o">*</span> <span class="n">data</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span> <span class="n">Container</span> <span class="n">shape</span><span class="p">,</span> <span class="n">Container</span> <span class="n">strides</span><span class="p">,</span> <span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">owner</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span><span class="kt">int</span> <span class="n">nd_min</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd_max</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span><span class="kt">int</span> <span class="n">nd</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd_min</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd_max</span><span class="p">,</span><span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">)</span>
<span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="k">operator</span><span class="o">|</span><span class="p">(</span><span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">a</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">b</span><span class="p">)</span> <span class="p">;</span>
<span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="k">operator</span><span class="o">&amp;</span><span class="p">(</span><span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">a</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="constructors">
<h2><a class="toc-backref" href="#id4">constructors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="n">view</span><span class="p">(</span><span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">new ndarray with old ndarray data cast as supplied dtype</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="n">astype</span><span class="p">(</span><span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">new ndarray with old ndarray data converted to supplied dtype</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="n">copy</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Copy of calling ndarray object</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="n">transpose</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">An ndarray with the rows and columns interchanged</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="n">squeeze</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">An ndarray with all unit-shaped dimensions removed</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="n">reshape</span><span class="p">(</span><span class="n">tuple</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">shape</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body">The new <tt class="docutils literal"><span class="pre">shape</span></tt> of the ndarray must be supplied as a tuple</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">An ndarray with the same data but reshaped to the <tt class="docutils literal"><span class="pre">shape</span></tt> supplied</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">object</span> <span class="n">scalarize</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A scalar if the ndarray has only one element, otherwise it returns the entire array</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="nf">zeros</span><span class="p">(</span><span class="n">tuple</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">zeros</span><span class="p">(</span><span class="kt">int</span> <span class="n">nd</span><span class="p">,</span> <span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied as required :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">shape</span></tt> or the size of all dimensions, as a tuple</li>
<li>the <tt class="docutils literal"><span class="pre">dtype</span></tt> of the data</li>
<li>the <tt class="docutils literal"><span class="pre">nd</span></tt> size for a square shaped ndarray</li>
<li>the <tt class="docutils literal"><span class="pre">shape</span></tt> Py_intptr_t</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A new ndarray with the given shape and data type, with data initialized to zero.</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="nf">empty</span><span class="p">(</span><span class="n">tuple</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">empty</span><span class="p">(</span><span class="kt">int</span> <span class="n">nd</span><span class="p">,</span> <span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">shape</span></tt> or the size of all dimensions, as a tuple</li>
<li>the <tt class="docutils literal"><span class="pre">dtype</span></tt> of the data</li>
<li>the <tt class="docutils literal"><span class="pre">shape</span></tt> Py_intptr_t</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A new ndarray with the given shape and data type, with data left uninitialized.</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="nf">array</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">);</span>
<span class="n">ndarray</span> <span class="nf">array</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">A new ndarray from an arbitrary Python sequence, with dtype of each element specified optionally</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">Container</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">ndarray</span> <span class="n">from_data</span><span class="p">(</span><span class="kt">void</span> <span class="o">*</span> <span class="n">data</span><span class="p">,</span><span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span><span class="n">Container</span> <span class="n">shape</span><span class="p">,</span><span class="n">Container</span> <span class="n">strides</span><span class="p">,</span><span class="n">python</span><span class="o">::</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">owner</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">data</span></tt> which is a generic C++ data container</li>
<li>the dtype <tt class="docutils literal"><span class="pre">dt</span></tt> of the data</li>
<li>the <tt class="docutils literal"><span class="pre">shape</span></tt> of the ndarray as Python object</li>
<li>the <tt class="docutils literal"><span class="pre">strides</span></tt> of each dimension of the array as a Python object</li>
<li>the <tt class="docutils literal"><span class="pre">owner</span></tt> of the data, in case it is not the ndarray itself</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">ndarray with attributes and data supplied</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Note:</th><td class="field-body"><p class="first last">The <tt class="docutils literal"><span class="pre">Container</span></tt> typename must be one that is convertible to a std::vector or python object type</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span><span class="kt">int</span> <span class="n">nd_min</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd_max</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">obj</span></tt> Python object to convert to ndarray</li>
<li>the dtype <tt class="docutils literal"><span class="pre">dt</span></tt> of the data</li>
<li>minimum number of dimensions <tt class="docutils literal"><span class="pre">nd_min</span></tt> of the ndarray as Python object</li>
<li>maximum number of dimensions <tt class="docutils literal"><span class="pre">nd_max</span></tt> of the ndarray as Python object</li>
<li>optional <tt class="docutils literal"><span class="pre">flags</span></tt> bitflags</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">ndarray constructed with dimensions and data supplied as parameters</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kr">inline</span> <span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">obj</span></tt> Python object to convert to ndarray</li>
<li>the dtype <tt class="docutils literal"><span class="pre">dt</span></tt> of the data</li>
<li>number of dimensions <tt class="docutils literal"><span class="pre">nd</span></tt> of the ndarray as Python object</li>
<li>optional <tt class="docutils literal"><span class="pre">flags</span></tt> bitflags</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">ndarray with dimensions <tt class="docutils literal"><span class="pre">nd</span></tt> x <tt class="docutils literal"><span class="pre">nd</span></tt> and suplied parameters</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kr">inline</span> <span class="n">ndarray</span> <span class="n">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">dtype</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">dt</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">obj</span></tt> Python object to convert to ndarray</li>
<li>the dtype <tt class="docutils literal"><span class="pre">dt</span></tt> of the data</li>
<li>optional <tt class="docutils literal"><span class="pre">flags</span></tt> bitflags</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Supplied Python object as ndarray</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd_min</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd_max</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">obj</span></tt> Python object to convert to ndarray</li>
<li>minimum number of dimensions <tt class="docutils literal"><span class="pre">nd_min</span></tt> of the ndarray as Python object</li>
<li>maximum number of dimensions <tt class="docutils literal"><span class="pre">nd_max</span></tt> of the ndarray as Python object</li>
<li>optional <tt class="docutils literal"><span class="pre">flags</span></tt> bitflags</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">ndarray with supplied dimension limits and parameters</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Note:</th><td class="field-body"><p class="first last">dtype need not be supplied here</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kr">inline</span> <span class="n">ndarray</span> <span class="nf">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="kt">int</span> <span class="n">nd</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">obj</span></tt> Python object to convert to ndarray</li>
<li>the dtype <tt class="docutils literal"><span class="pre">dt</span></tt> of the data</li>
<li>number of dimensions <tt class="docutils literal"><span class="pre">nd</span></tt> of the ndarray as Python object</li>
<li>optional <tt class="docutils literal"><span class="pre">flags</span></tt> bitflags</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">ndarray of <tt class="docutils literal"><span class="pre">nd</span></tt> x <tt class="docutils literal"><span class="pre">nd</span></tt> dimensions constructed from the supplied object</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kr">inline</span> <span class="n">ndarray</span> <span class="n">from_object</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">obj</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">flags</span><span class="o">=</span><span class="n">ndarray</span><span class="o">::</span><span class="n">NONE</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first">The following parameters must be supplied :</p>
<ul class="simple">
<li>the <tt class="docutils literal"><span class="pre">obj</span></tt> Python object to convert to ndarray</li>
<li>optional <tt class="docutils literal"><span class="pre">flags</span></tt> bitflags</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">ndarray of same dimensions and dtype as supplied Python object</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="accessors">
<h2><a class="toc-backref" href="#id5">accessors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="k">const</span> <span class="n">shape</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The size of the n-th dimension of the ndarray</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="k">const</span> <span class="n">strides</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The stride of the nth dimension.</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">char</span> <span class="o">*</span> <span class="n">get_data</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array&#8217;s raw data pointer as a char</td>
</tr>
<tr class="field-even field"><th class="field-name">Note:</th><td class="field-body">This returns char so stride math works properly on it.User will have to reinterpret_cast it.</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">dtype</span> <span class="n">get_dtype</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array&#8217;s data-type descriptor object (dtype)</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">object</span> <span class="n">get_base</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Object that owns the array&#8217;s data, or None if the array owns its own data.</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">void</span> <span class="nf">set_base</span><span class="p">(</span><span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">base</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Set the object that owns the array&#8217;s data. Exercise caution while using this</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">get_shape</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Shape of the array as an array of integers</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">Py_intptr_t</span> <span class="k">const</span> <span class="o">*</span> <span class="n">get_strides</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Stride of the array as an array of integers</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="k">const</span> <span class="n">get_nd</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Number of array dimensions</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">bitflag</span> <span class="k">const</span> <span class="n">get_flags</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array flags</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kr">inline</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="k">operator</span><span class="o">|</span><span class="p">(</span><span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">a</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">bitflag logically OR-ed as (a | b)</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="kr">inline</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="k">operator</span><span class="o">&amp;</span><span class="p">(</span><span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">a</span><span class="p">,</span> <span class="n">ndarray</span><span class="o">::</span><span class="n">bitflag</span> <span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">bitflag logically AND-ed as (a &amp; b)</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="example-s">
<h2><a class="toc-backref" href="#id6">Example(s)</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">tu</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="sc">&#39;a&#39;</span><span class="p">,</span><span class="sc">&#39;b&#39;</span><span class="p">,</span><span class="sc">&#39;c&#39;</span><span class="p">)</span> <span class="p">;</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">example_tuple</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">array</span> <span class="p">(</span><span class="n">tu</span><span class="p">)</span> <span class="p">;</span>
<span class="n">p</span><span class="o">::</span><span class="n">list</span> <span class="n">l</span> <span class="p">;</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">example_list</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">array</span> <span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="p">;</span>
<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dt</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">example_list1</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">array</span> <span class="p">(</span><span class="n">l</span><span class="p">,</span><span class="n">dt</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">data</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">}</span> <span class="p">;</span>
<span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">shape</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="p">;</span>
<span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">stride</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="p">;</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">own</span> <span class="p">;</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">data_ex</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">from_data</span><span class="p">(</span><span class="n">data</span><span class="p">,</span><span class="n">dt</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">stride</span><span class="p">,</span><span class="n">own</span><span class="p">);</span>
<span class="kt">uint8_t</span> <span class="n">mul_data</span><span class="p">[][</span><span class="mi">4</span><span class="p">]</span> <span class="o">=</span> <span class="p">{{</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">},{</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">},{</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">}};</span>
<span class="n">shape</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span> <span class="p">;</span>
<span class="n">stride</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span> <span class="p">;</span>
<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dt1</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">uint8_t</span><span class="o">&gt;</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">mul_data_ex</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">from_data</span><span class="p">(</span><span class="n">mul_data</span><span class="p">,</span><span class="n">dt1</span><span class="p">,</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">),</span><span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span><span class="n">p</span><span class="o">::</span><span class="n">object</span><span class="p">());</span>
<span class="n">mul_data_ex</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">from_data</span><span class="p">(</span><span class="n">mul_data</span><span class="p">,</span><span class="n">dt1</span><span class="p">,</span> <span class="n">shape</span><span class="p">,</span><span class="n">stride</span><span class="p">,</span><span class="n">p</span><span class="o">::</span><span class="n">object</span><span class="p">());</span>
</pre></div>
</div>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="dtype" href="dtype.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="unary_ufunc" href="unary_ufunc.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,202 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>unary_ufunc - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Reference" href="index.html" />
<link rel="next" title="binary_ufunc" href="binary_ufunc.html" />
<link rel="prev" title="ndarray" href="ndarray.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="ndarray" href="ndarray.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="binary_ufunc" href="binary_ufunc.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="unary-ufunc">
<h1><a class="toc-backref" href="#id1">unary_ufunc</a></h1>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#unary-ufunc" id="id1">unary_ufunc</a><ul>
<li><a class="reference internal" href="#synopsis" id="id2">synopsis</a></li>
<li><a class="reference internal" href="#constructors" id="id3">constructors</a></li>
<li><a class="reference internal" href="#accessors" id="id4">accessors</a></li>
<li><a class="reference internal" href="#example-s" id="id5">Example(s)</a></li>
</ul>
</li>
</ul>
</div>
<p>A <tt class="docutils literal"><span class="pre">unary_ufunc</span></tt> is a struct used as an intermediate step to broadcast a single argument so that a C++ function can be converted to a ufunc like function</p>
<blockquote>
<div><tt class="docutils literal"><span class="pre">&lt;boost/python/numpy/ufunc.hpp&gt;</span></tt> contains the <tt class="docutils literal"><span class="pre">unary_ufunc</span></tt> structure definitions</div></blockquote>
<div class="section" id="synopsis">
<h2><a class="toc-backref" href="#id2">synopsis</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">boost</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">python</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">numpy</span>
<span class="p">{</span>
<span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument</span><span class="o">=</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="o">::</span><span class="n">argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TResult</span><span class="o">=</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="o">::</span><span class="n">result_type</span><span class="o">&gt;</span>
<span class="k">struct</span> <span class="n">unary_ufunc</span>
<span class="p">{</span>
<span class="k">static</span> <span class="n">object</span> <span class="n">call</span><span class="p">(</span><span class="n">TUnaryFunctor</span> <span class="o">&amp;</span> <span class="n">self</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">input</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">output</span><span class="p">)</span> <span class="p">;</span>
<span class="k">static</span> <span class="n">object</span> <span class="nf">make</span><span class="p">();</span>
<span class="p">};</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="constructors">
<h2><a class="toc-backref" href="#id3">constructors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">example_unary_ufunc</span>
<span class="p">{</span>
<span class="k">typedef</span> <span class="n">any_valid_type</span> <span class="n">argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="n">any_valid_type</span> <span class="n">result_type</span><span class="p">;</span>
<span class="p">};</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body">The <tt class="docutils literal"><span class="pre">any_valid</span></tt> type must be defined using typedef as a valid C++ type in order to use the struct methods correctly</td>
</tr>
<tr class="field-even field"><th class="field-name">Note:</th><td class="field-body">The struct must be exposed as a Python class, and an instance of the class must be created to use the <tt class="docutils literal"><span class="pre">call</span></tt> method corresponding to the <tt class="docutils literal"><span class="pre">__call__</span></tt> attribute of the Python object</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="accessors">
<h2><a class="toc-backref" href="#id4">accessors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument</span><span class="o">=</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="o">::</span><span class="n">argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TResult</span><span class="o">=</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="o">::</span><span class="n">result_type</span><span class="o">&gt;</span>
<span class="k">static</span> <span class="n">object</span> <span class="n">call</span><span class="p">(</span><span class="n">TUnaryFunctor</span> <span class="o">&amp;</span> <span class="n">self</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">input</span><span class="p">,</span>
<span class="n">object</span> <span class="k">const</span> <span class="o">&amp;</span> <span class="n">output</span><span class="p">);</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requires:</th><td class="field-body">Typenames <tt class="docutils literal"><span class="pre">TUnaryFunctor</span></tt> and optionally <tt class="docutils literal"><span class="pre">TArgument</span></tt> for argument type and <tt class="docutils literal"><span class="pre">TResult</span></tt> for result type</td>
</tr>
<tr class="field-even field"><th class="field-name">Effects:</th><td class="field-body">Passes a Python object to the underlying C++ functor after broadcasting its arguments</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TArgument</span><span class="o">=</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="o">::</span><span class="n">argument_type</span><span class="p">,</span>
<span class="k">typename</span> <span class="n">TResult</span><span class="o">=</span><span class="k">typename</span> <span class="n">TUnaryFunctor</span><span class="o">::</span><span class="n">result_type</span><span class="o">&gt;</span>
<span class="k">static</span> <span class="n">object</span> <span class="n">make</span><span class="p">();</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requires:</th><td class="field-body">Typenames <tt class="docutils literal"><span class="pre">TUnaryFunctor</span></tt> and optionally <tt class="docutils literal"><span class="pre">TArgument</span></tt> for argument type and <tt class="docutils literal"><span class="pre">TResult</span></tt> for result type</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">A Python function object to call the overloaded () operator in the struct (in typical usage)</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="example-s">
<h2><a class="toc-backref" href="#id5">Example(s)</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">UnarySquare</span>
<span class="p">{</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">result_type</span><span class="p">;</span>
<span class="kt">double</span> <span class="k">operator</span><span class="p">()(</span><span class="kt">double</span> <span class="n">r</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="n">r</span> <span class="o">*</span> <span class="n">r</span><span class="p">;}</span>
<span class="p">};</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">ud</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">class_</span><span class="o">&lt;</span><span class="n">UnarySquare</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">UnarySquare</span><span class="o">&gt;</span> <span class="o">&gt;</span><span class="p">(</span><span class="s">&quot;UnarySquare&quot;</span><span class="p">).</span><span class="n">def</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">,</span> <span class="n">np</span><span class="o">::</span><span class="n">unary_ufunc</span><span class="o">&lt;</span><span class="n">UnarySquare</span><span class="o">&gt;::</span><span class="n">make</span><span class="p">());</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">inst</span> <span class="o">=</span> <span class="n">ud</span><span class="p">();</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Square of unary scalar 1.0 is &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span> <span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*</span> <span class="o">&gt;</span> <span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">inst</span><span class="p">.</span><span class="n">attr</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">)(</span><span class="mf">1.0</span><span class="p">)))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="p">;</span>
</pre></div>
</div>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="ndarray" href="ndarray.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="binary_ufunc" href="binary_ufunc.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,93 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/searchtools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="#" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="index.html" />
<script type="text/javascript">
jQuery(function() { Search.loadIndex("searchindex.js"); });
</script>
<script type="text/javascript" id="searchindexloader"></script>
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="index.html"><img
alt="C++ Boost" src="_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
</div>
<h1 id="search-documentation">Search</h1>
<div id="fallback" class="admonition warning">
<script type="text/javascript">$('#fallback').hide();</script>
<p>
Please activate JavaScript to enable the search
functionality.
</p>
</div>
<p>
From here you can search these documents. Enter your search
words into the box below and click "search". Note that the search
function will automatically search for all of the words. Pages
containing fewer words won't appear in the result list.
</p>
<form action="" method="get">
<input type="text" name="q" value="" />
<input type="submit" value="search" />
<span id="search-progress" style="padding-left: 10px"></span>
</form>
<div id="search-results">
</div>
<div class="navbar" style="text-align:right;">
</div>
</div>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -1,132 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How to use dtypes - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Tutorial" href="index.html" />
<link rel="next" title="Creating ndarrays" href="ndarray.html" />
<link rel="prev" title="A simple tutorial on Arrays" href="simple.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="A simple tutorial on Arrays" href="simple.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="Creating ndarrays" href="ndarray.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="how-to-use-dtypes">
<h1>How to use dtypes</h1>
<p>Here is a brief tutorial to show how to create ndarrays with built-in python data types, and extract the types and values of member variables</p>
<p>Like before, first get the necessary headers, setup the namespaces and initialize the Python runtime and numpy module:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;boost/python/numpy.hpp&gt;</span>
<span class="cp">#include &lt;iostream&gt;</span>
<span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">Py_Initialize</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">initialize</span><span class="p">();</span>
</pre></div>
</div>
<p>Next, we create the shape and dtype. We use the get_builtin method to get the numpy dtype corresponding to the builtin C++ dtype
Here, we will create a 3x3 array passing a tuple with (3,3) for the size, and double as the data type</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">shape</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">);</span>
<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span><span class="p">);</span>
</pre></div>
</div>
<p>Finally, we can print the array using the extract method in the python namespace.
Here, we first convert the variable into a string, and then extract it as a C++ character array from the python string using the &lt;char const * &gt; template</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Original array:</span><span class="se">\n</span><span class="s">&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">a</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>We can also print the dtypes of the data members of the ndarray by using the get_dtype method for the ndarray</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Datatype is:</span><span class="se">\n</span><span class="s">&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">get_dtype</span><span class="p">()))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="p">;</span>
</pre></div>
</div>
<p>We can also create custom dtypes and build ndarrays with the custom dtypes</p>
<p>We use the dtype constructor to create a custom dtype. This constructor takes a list as an argument.</p>
<p>The list should contain one or more tuples of the format (variable name, variable type)</p>
<p>So first create a tuple with a variable name and its dtype, double, to create a custom dtype</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">for_custom_dtype</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="s">&quot;ha&quot;</span><span class="p">,</span><span class="n">dtype</span><span class="p">)</span> <span class="p">;</span>
</pre></div>
</div>
<p>Next, create a list, and add this tuple to the list. Then use the list to create the custom dtype</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">list</span> <span class="n">list_for_dtype</span> <span class="p">;</span>
<span class="n">list_for_dtype</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">for_custom_dtype</span><span class="p">)</span> <span class="p">;</span>
<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">custom_dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="p">(</span><span class="n">list_for_dtype</span><span class="p">)</span> <span class="p">;</span>
</pre></div>
</div>
<p>We are now ready to create an ndarray with dimensions specified by *shape* and of custom dtpye</p>
<div class="highlight-c++"><div class="highlight"><pre> <span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">new_array</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span><span class="n">custom_dtype</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="A simple tutorial on Arrays" href="simple.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="Creating ndarrays" href="ndarray.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,135 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How to access data using raw pointers - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Tutorial" href="index.html" />
<link rel="next" title="Boost.Python NumPy extension Reference" href="../reference/index.html" />
<link rel="prev" title="Ufuncs" href="ufunc.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="Ufuncs" href="ufunc.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="Boost.Python NumPy extension Reference" href="../reference/index.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="how-to-access-data-using-raw-pointers">
<h1>How to access data using raw pointers</h1>
<p>One of the advantages of the ndarray wrapper is that the same data can be used in both Python and C++ and changes can be made to reflect at both ends.
The from_data method makes this possible.</p>
<p>Like before, first get the necessary headers, setup the namespaces and initialize the Python runtime and numpy module:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;boost/python/numpy.hpp&gt;</span>
<span class="cp">#include &lt;iostream&gt;</span>
<span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">Py_Initialize</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">initialize</span><span class="p">();</span>
</pre></div>
</div>
<p>Create an array in C++ , and pass the pointer to it to the from_data method to create an ndarray:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="n">arr</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">};</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">py_array</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">from_data</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="p">(),</span>
<span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span>
<span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)),</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span><span class="p">());</span>
</pre></div>
</div>
<p>Print the source C++ array, as well as the ndarray, to check if they are the same:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;C++ array :&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="mi">4</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">arr</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39; &#39;</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span>
<span class="o">&lt;&lt;</span> <span class="s">&quot;Python ndarray :&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">py_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Now, change an element in the Python ndarray, and check if the value changed correspondingly in the source C++ array:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">py_array</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">5</span> <span class="p">;</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Is the change reflected in the C++ array used to create the ndarray ? &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="mi">5</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">arr</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39; &#39;</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Next, change an element of the source C++ array and see if it is reflected in the Python ndarray:</p>
<div class="highlight-c++"><div class="highlight"><pre> <span class="n">arr</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="mi">8</span><span class="p">;</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span>
<span class="o">&lt;&lt;</span> <span class="s">&quot;Is the change reflected in the Python ndarray ?&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span>
<span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">py_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<p>As we can see, the changes are reflected across the ends. This happens because the from_data method passes the C++ array by reference to create the ndarray, and thus uses the same locations for storing data.</p>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="Ufuncs" href="ufunc.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="Boost.Python NumPy extension Reference" href="../reference/index.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,90 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Boost.Python NumPy extension Tutorial - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="next" title="A simple tutorial on Arrays" href="simple.html" />
<link rel="prev" title="Welcome to the documentation of the Boost.Python NumPy extension!" href="../index.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="Welcome to the documentation of the Boost.Python NumPy extension!" href="../index.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="next" title="A simple tutorial on Arrays" href="simple.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="boost-python-numpy-extension-tutorial">
<h1>Boost.Python NumPy extension Tutorial</h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="simple.html">A simple tutorial on Arrays</a></li>
<li class="toctree-l1"><a class="reference internal" href="dtype.html">How to use dtypes</a></li>
<li class="toctree-l1"><a class="reference internal" href="ndarray.html">Creating ndarrays</a></li>
<li class="toctree-l1"><a class="reference internal" href="ufunc.html">Ufuncs</a></li>
<li class="toctree-l1"><a class="reference internal" href="fromdata.html">How to access data using raw pointers</a></li>
</ul>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="Welcome to the documentation of the Boost.Python NumPy extension!" href="../index.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="next" title="A simple tutorial on Arrays" href="simple.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,178 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Creating ndarrays - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Tutorial" href="index.html" />
<link rel="next" title="Ufuncs" href="ufunc.html" />
<link rel="prev" title="How to use dtypes" href="dtype.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="How to use dtypes" href="dtype.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="Ufuncs" href="ufunc.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="creating-ndarrays">
<h1>Creating ndarrays</h1>
<p>The Boost.Numpy library exposes quite a few methods to create ndarrays. ndarrays can be created in a variety of ways, include empty arrays and zero filled arrays.
ndarrays can also be created from arbitrary python sequences as well as from data and dtypes.</p>
<p>This tutorial will introduce you to some of the ways in which you can create ndarrays. The methods covered here include creating ndarrays from arbitrary Python sequences, as well as from C++ containers, using both unit and non-unit strides</p>
<p>First, as before, initialise the necessary namepaces and runtimes</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;boost/python/numpy.hpp&gt;</span>
<span class="cp">#include &lt;iostream&gt;</span>
<span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">Py_Initialize</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">initialize</span><span class="p">();</span>
</pre></div>
</div>
<p>Let&#8217;s now create an ndarray from a simple tuple. We first create a tuple object, and then pass it to the array method, to generate the necessary tuple</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">tu</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="sc">&#39;a&#39;</span><span class="p">,</span><span class="sc">&#39;b&#39;</span><span class="p">,</span><span class="sc">&#39;c&#39;</span><span class="p">);</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">example_tuple</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">array</span><span class="p">(</span><span class="n">tu</span><span class="p">);</span>
</pre></div>
</div>
<p>Let&#8217;s now try the same with a list. We create an empty list, add an element using the append method, and as before, call the array method</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">list</span> <span class="n">l</span><span class="p">;</span>
<span class="n">l</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="sc">&#39;a&#39;</span><span class="p">);</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">example_list</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">array</span> <span class="p">(</span><span class="n">l</span><span class="p">);</span>
</pre></div>
</div>
<p>Optionally, we can also specify a dtype for the array</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dt</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">example_list1</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">array</span> <span class="p">(</span><span class="n">l</span><span class="p">,</span><span class="n">dt</span><span class="p">);</span>
</pre></div>
</div>
<p>We can also create an array by supplying data arrays and a few other parameters.</p>
<p>First,create an integer array</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="n">data</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">};</span>
</pre></div>
</div>
<p>Create a shape, and strides, needed by the function</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">shape</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
<span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">stride</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span>
</pre></div>
</div>
<p>Here, shape is (4,) , and the stride is <cite>sizeof(int)`</cite>.
A stride is the number of bytes that must be traveled to get to the next desired element while constructing the ndarray.</p>
<p>The function also needs an owner, to keep track of the data array passed. Passing none is dangerous</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">own</span><span class="p">;</span>
</pre></div>
</div>
<p>The from_data function takes the data array, datatype,shape,stride and owner as arguments and returns an ndarray</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">data_ex1</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">from_data</span><span class="p">(</span><span class="n">data</span><span class="p">,</span><span class="n">dt</span><span class="p">,</span> <span class="n">shape</span><span class="p">,</span><span class="n">stride</span><span class="p">,</span><span class="n">own</span><span class="p">);</span>
</pre></div>
</div>
<p>Now let&#8217;s print the ndarray we created</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Single dimensional array ::&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span>
<span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">data_ex</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Let&#8217;s make it a little more interesting. Lets make an 3x2 ndarray from a multi-dimensional array using non-unit strides</p>
<p>First lets create a 3x4 array of 8-bit integers</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">uint8_t</span> <span class="n">mul_data</span><span class="p">[][</span><span class="mi">4</span><span class="p">]</span> <span class="o">=</span> <span class="p">{{</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">},{</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">},{</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">}};</span>
</pre></div>
</div>
<p>Now let&#8217;s create an array of 3x2 elements, picking the first and third elements from each row . For that, the shape will be 3x2.
The strides will be 4x2 i.e. 4 bytes to go to the next desired row, and 2 bytes to go to the next desired column</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">shape</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">);</span>
<span class="n">stride</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">uint8_t</span><span class="p">)</span><span class="o">*</span><span class="mi">2</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">uint8_t</span><span class="p">));</span>
</pre></div>
</div>
<p>Get the numpy dtype for the built-in 8-bit integer data type</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dt1</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">uint8_t</span><span class="o">&gt;</span><span class="p">();</span>
</pre></div>
</div>
<p>Now lets first create and print out the ndarray as is.
Notice how we can pass the shape and strides in the function directly, as well as the owner. The last part can be done because we don&#8217;t have any use to
manipulate the &#8220;owner&#8221; object</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">mul_data_ex</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">from_data</span><span class="p">(</span><span class="n">mul_data</span><span class="p">,</span> <span class="n">dt1</span><span class="p">,</span>
<span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">),</span>
<span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span><span class="p">());</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Original multi dimensional array :: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span>
<span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">mul_data_ex</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Now create the new ndarray using the shape and strides and print out the array we created using non-unit strides</p>
<div class="highlight-c++"><div class="highlight"><pre> <span class="n">mul_data_ex</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">from_data</span><span class="p">(</span><span class="n">mul_data</span><span class="p">,</span> <span class="n">dt1</span><span class="p">,</span> <span class="n">shape</span><span class="p">,</span> <span class="n">stride</span><span class="p">,</span> <span class="n">p</span><span class="o">::</span><span class="n">object</span><span class="p">());</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Selective multidimensional array :: &quot;</span><span class="o">&lt;&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">endl</span>
<span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">mul_data_ex</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The from_data method will throw <tt class="docutils literal"><span class="pre">error_already_set</span></tt> if the number of elements dictated by the shape and the corresponding strides don&#8217;t match.</p>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="How to use dtypes" href="dtype.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="Ufuncs" href="ufunc.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,120 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A simple tutorial on Arrays - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Tutorial" href="index.html" />
<link rel="next" title="How to use dtypes" href="dtype.html" />
<link rel="prev" title="Boost.Python NumPy extension Tutorial" href="index.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="How to use dtypes" href="dtype.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="a-simple-tutorial-on-arrays">
<h1>A simple tutorial on Arrays</h1>
<p>Let&#8217;s start with a simple tutorial to create and modify arrays.</p>
<p>Get the necessary headers for numpy components and set up necessary namespaces:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;boost/python/numpy.hpp&gt;</span>
<span class="cp">#include &lt;iostream&gt;</span>
<span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
</pre></div>
</div>
<p>Initialise the Python runtime, and the numpy module. Failure to call these results in segmentation errors:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">Py_Initialize</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">initialize</span><span class="p">();</span>
</pre></div>
</div>
<p>Zero filled n-dimensional arrays can be created using the shape and data-type of the array as a parameter. Here, the shape is 3x3 and the datatype is the built-in float type:</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">shape</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">);</span>
<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">float</span><span class="o">&gt;</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span><span class="p">);</span>
</pre></div>
</div>
<p>You can also create an empty array like this</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">empty</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span><span class="n">dtype</span><span class="p">);</span>
</pre></div>
</div>
<p>Print the original and reshaped array. The array a which is a list is first converted to a string, and each value in the list is extracted using extract&lt; &gt;:</p>
<div class="highlight-c++"><div class="highlight"><pre> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Original array:</span><span class="se">\n</span><span class="s">&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">a</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
<span class="c1">// Reshape the array into a 1D array</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">9</span><span class="p">));</span>
<span class="c1">// Print it again.</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Reshaped array:</span><span class="se">\n</span><span class="s">&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">a</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="How to use dtypes" href="dtype.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,198 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ufuncs - Boost.Python NumPy extension 1.0 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
<link rel="up" title="Boost.Python NumPy extension Tutorial" href="index.html" />
<link rel="next" title="How to access data using raw pointers" href="fromdata.html" />
<link rel="prev" title="Creating ndarrays" href="ndarray.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!-- <h2 align="center">CallPolicies Concept</h2>-->
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="Creating ndarrays" href="ndarray.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="How to access data using raw pointers" href="fromdata.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="ufuncs">
<h1>Ufuncs</h1>
<p>Ufuncs or universal functions operate on ndarrays element by element, and support array broadcasting, type casting, and other features.</p>
<p>Lets try and see how we can use the binary and unary ufunc methods</p>
<p>After the neccessary includes</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;boost/python/numpy.hpp&gt;</span>
<span class="cp">#include &lt;iostream&gt;</span>
<span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
</pre></div>
</div>
<p>Now we create the structs necessary to implement the ufuncs. The typedefs <em>must</em> be made as the ufunc generators take these typedefs as inputs and return an error otherwise</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">UnarySquare</span>
<span class="p">{</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">result_type</span><span class="p">;</span>
<span class="kt">double</span> <span class="k">operator</span><span class="p">()(</span><span class="kt">double</span> <span class="n">r</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="n">r</span> <span class="o">*</span> <span class="n">r</span><span class="p">;}</span>
<span class="p">};</span>
<span class="k">struct</span> <span class="n">BinarySquare</span>
<span class="p">{</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">first_argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">second_argument_type</span><span class="p">;</span>
<span class="k">typedef</span> <span class="kt">double</span> <span class="n">result_type</span><span class="p">;</span>
<span class="kt">double</span> <span class="nf">operator</span><span class="p">()(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span><span class="kt">double</span> <span class="n">b</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span><span class="o">*</span><span class="n">b</span><span class="p">)</span> <span class="p">;</span> <span class="p">}</span>
<span class="p">};</span>
</pre></div>
</div>
<p>Initialise the Python runtime and the numpy module</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">Py_Initialize</span><span class="p">();</span>
<span class="n">np</span><span class="o">::</span><span class="n">initialize</span><span class="p">();</span>
</pre></div>
</div>
<p>Now expose the struct UnarySquare to Python as a class, and let ud be the class object.</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">ud</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">class_</span><span class="o">&lt;</span><span class="n">UnarySquare</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">UnarySquare</span><span class="o">&gt;</span> <span class="o">&gt;</span><span class="p">(</span><span class="s">&quot;UnarySquare&quot;</span><span class="p">);</span>
<span class="n">ud</span><span class="p">.</span><span class="n">def</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">,</span> <span class="n">np</span><span class="o">::</span><span class="n">unary_ufunc</span><span class="o">&lt;</span><span class="n">UnarySquare</span><span class="o">&gt;::</span><span class="n">make</span><span class="p">());</span>
</pre></div>
</div>
<p>Let inst be an instance of the class ud</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">inst</span> <span class="o">=</span> <span class="n">ud</span><span class="p">();</span>
</pre></div>
</div>
<p>Use the &#8220;__call__&#8221; method to call the overloaded () operator and print the value</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Square of unary scalar 1.0 is &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">inst</span><span class="p">.</span><span class="n">attr</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">)(</span><span class="mf">1.0</span><span class="p">)))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Create an array in C++</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="n">arr</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">}</span> <span class="p">;</span>
</pre></div>
</div>
<p>..and use it to create the ndarray in Python</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">np</span><span class="o">::</span><span class="n">ndarray</span> <span class="n">demo_array</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">from_data</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="p">(),</span>
<span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span>
<span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span>
<span class="n">p</span><span class="o">::</span><span class="n">object</span><span class="p">());</span>
</pre></div>
</div>
<p>Print out the demo array</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Demo array is &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">demo_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Call the &#8220;__call__&#8221; method to perform the operation and assign the value to result_array</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">object</span> <span class="n">result_array</span> <span class="o">=</span> <span class="n">inst</span><span class="p">.</span><span class="n">attr</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">)(</span><span class="n">demo_array</span><span class="p">);</span>
</pre></div>
</div>
<p>Print the resultant array</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Square of demo array is &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">result_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Lets try the same with a list</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">p</span><span class="o">::</span><span class="n">list</span> <span class="n">li</span><span class="p">;</span>
<span class="n">li</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="mi">3</span><span class="p">);</span>
<span class="n">li</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="mi">7</span><span class="p">);</span>
</pre></div>
</div>
<p>Print out the demo list</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Demo list is &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">li</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Call the ufunc for the list</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">result_array</span> <span class="o">=</span> <span class="n">inst</span><span class="p">.</span><span class="n">attr</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">)(</span><span class="n">li</span><span class="p">);</span>
</pre></div>
</div>
<p>And print the list out</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Square of demo list is &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">result_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Now lets try Binary ufuncs. Again, expose the struct BinarySquare to Python as a class, and let ud be the class object</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">ud</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">class_</span><span class="o">&lt;</span><span class="n">BinarySquare</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">BinarySquare</span><span class="o">&gt;</span> <span class="o">&gt;</span><span class="p">(</span><span class="s">&quot;BinarySquare&quot;</span><span class="p">);</span>
<span class="n">ud</span><span class="p">.</span><span class="n">def</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">,</span> <span class="n">np</span><span class="o">::</span><span class="n">binary_ufunc</span><span class="o">&lt;</span><span class="n">BinarySquare</span><span class="o">&gt;::</span><span class="n">make</span><span class="p">());</span>
</pre></div>
</div>
<p>And initialise ud</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">inst</span> <span class="o">=</span> <span class="n">ud</span><span class="p">();</span>
</pre></div>
</div>
<p>Print the two input lists</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;The two input list for binary ufunc are &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span>
<span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">demo_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span>
<span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">demo_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
</pre></div>
</div>
<p>Call the binary ufunc taking demo_array as both inputs</p>
<div class="highlight-c++"><div class="highlight"><pre><span class="n">result_array</span> <span class="o">=</span> <span class="n">inst</span><span class="p">.</span><span class="n">attr</span><span class="p">(</span><span class="s">&quot;__call__&quot;</span><span class="p">)(</span><span class="n">demo_array</span><span class="p">,</span><span class="n">demo_array</span><span class="p">);</span>
</pre></div>
</div>
<p>And print the output</p>
<div class="highlight-c++"><div class="highlight"><pre> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Square of list with binary ufunc is &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">p</span><span class="o">::</span><span class="n">extract</span><span class="o">&lt;</span><span class="kt">char</span> <span class="k">const</span> <span class="o">*&gt;</span><span class="p">(</span><span class="n">p</span><span class="o">::</span><span class="n">str</span><span class="p">(</span><span class="n">result_array</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="Creating ndarrays" href="ndarray.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Boost.Python NumPy extension Tutorial" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="How to access data using raw pointers" href="fromdata.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
</body>
</html>

View File

@@ -1,58 +0,0 @@
index.html
concepts.html
concepts/dereferenceable.html
concepts/extractor.html
concepts/holdergenerator.html
concepts/resultconverter.html
concepts/objectwrapper.html
high_level_components.html
high_level_components/boost_python_def_hpp.html
high_level_components/boost_python_def_visitor_hpp.html
high_level_components/boost_python_docstring_options_h.html
high_level_components/boost_python_enum_hpp.html
high_level_components/boost_python_errors_hpp.html
high_level_components/boost_python_exception_translato.html
high_level_components/boost_python_init_hpp.html
high_level_components/boost_python_iterator_hpp.html
high_level_components/boost_python_module_hpp.html
high_level_components/boost_python_operators_hpp.html
high_level_components/boost_python_scope_hpp.html
high_level_components/boost_python_stl_iterator_hpp.html
high_level_components/boost_python_wrapper_hpp.html
object_wrappers.html
object_wrappers/boost_python_list_hpp.html
object_wrappers/boost_python_long_hpp.html
object_wrappers/boost_python_object_hpp.html
object_wrappers/boost_python_str_hpp.html
object_wrappers/boost_python_slice_hpp.html
object_wrappers/boost_python_tuple_hpp.html
function_invocation_and_creation.html
function_invocation_and_creation/boost_python_call_hpp.html
function_invocation_and_creation/boost_python_call_method_hpp.html
function_invocation_and_creation/boost_python_data_members_hpp.html
function_invocation_and_creation/boost_python_make_function_hpp.html
function_invocation_and_creation/boost_python_overloads_hpp.html
function_invocation_and_creation/boost_python_ptr_hpp.html
function_invocation_and_creation/boost_python_raw_function_hpp.html
function_invocation_and_creation/function_documentation.html
function_invocation_and_creation/models_of_callpolicies.html
function_invocation_and_creation/models_of_resultconverter.html
function_invocation_and_creation/models_of_resultconvertergenerat.html
to_from_python_type_conversion.html
to_from_python_type_conversion/boost_python_implicit_hpp.html
to_from_python_type_conversion/boost_python_lvalue_from_pytype_.html
to_from_python_type_conversion/boost_python_opaque_pointer_conv.html
to_from_python_type_conversion/boost_python_to_python_converter.html
to_from_python_type_conversion/boost_python_register_ptr_to_pyt.html
embedding.html
embedding/boost_python_import_hpp.html
utility_and_infrastructure.html
utility_and_infrastructure/boost_python_instance_holder_hpp.html
utility_and_infrastructure/boost_python_pointee_hpp.html
utility_and_infrastructure/boost_python_handle_hpp.html
utility_and_infrastructure/boost_python_type_id_hpp.html
utility_and_infrastructure/boost_python_ssize_t_hpp.html
topics.html
topics/pickle_support.html
topics/indexing_support.html
glossary.html

View File

@@ -1,261 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Chapter&#160;1.&#160;Concepts</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Boost.Python Reference Manual">
<link rel="up" href="index.html" title="Boost.Python Reference Manual">
<link rel="prev" href="index.html" title="Boost.Python Reference Manual">
<link rel="next" href="concepts/dereferenceable.html" title="Dereferenceable">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="index.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="concepts/dereferenceable.html"><img src="../images/next.png" alt="Next"></a>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="concepts"></a>Chapter&#160;1.&#160;Concepts</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="section"><a href="concepts.html#concepts.callpolicies">CallPolicies</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.callpolicies_composition">CallPolicies
Composition</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/dereferenceable.html">Dereferenceable</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/dereferenceable.html#concepts.dereferenceable.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/dereferenceable.html#concepts.dereferenceable.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/extractor.html">Extractor</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.concept_requirements">Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/extractor.html#concepts.extractor.notes">Notes</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/holdergenerator.html">HolderGenerator</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/holdergenerator.html#concepts.holdergenerator.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/holdergenerator.html#concepts.holdergenerator.concept_requirements">Concept
Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/resultconverter.html">ResultConverter</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.resultconverter_concept_requirem">ResultConverter
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/resultconverter.html#concepts.resultconverter.resultconvertergenerator_concept">ResultConverterGenerator
Concept Requirements</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="concepts/objectwrapper.html">ObjectWrapper</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.objectwrapper_concept_requiremen">ObjectWrapper
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements">TypeWrapper
Concept Requirements</a></span></dt>
<dt><span class="section"><a href="concepts/objectwrapper.html#concepts.objectwrapper.caveat">Caveat</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.callpolicies"></a><a class="link" href="concepts.html#concepts.callpolicies" title="CallPolicies">CallPolicies</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.callpolicies_composition">CallPolicies
Composition</a></span></dt>
<dt><span class="section"><a href="concepts.html#concepts.callpolicies.concept_requirements">Concept
Requirements</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.callpolicies.introduction"></a><a class="link" href="concepts.html#concepts.callpolicies.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Models of the CallPolicies concept are used to specialize the behavior
of Python callable objects generated by Boost.Python to wrapped C++ objects
like function and member function pointers, providing three behaviors:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<code class="computeroutput"><span class="identifier">precall</span></code> - Python argument
tuple management before the wrapped object is invoked
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">result_converter</span></code> -
C++ return value handling
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">postcall</span></code> - Python argument
tuple and result management after the wrapped object is invoked
</li>
<li class="listitem">
<code class="computeroutput"><span class="identifier">extract_return_type</span></code>
- metafunction for extracting the return type from a given signature
type sequence
</li>
</ol></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.callpolicies.callpolicies_composition"></a><a class="link" href="concepts.html#concepts.callpolicies.callpolicies_composition" title="CallPolicies Composition">CallPolicies
Composition</a>
</h3></div></div></div>
<p>
In order to allow the use of multiple models of CallPolicies in the same
callable object, Boost.Python's CallPolicies class templates provide a
chaining interface which allows them to be recursively composed. This interface
takes the form of an optional template parameter, <code class="computeroutput"><span class="identifier">Base</span></code>,
which defaults to <code class="computeroutput"><span class="identifier">default_call_policies</span></code>.
By convention, the <code class="computeroutput"><span class="identifier">precall</span></code>
function of the <code class="computeroutput"><span class="identifier">Base</span></code> is
invoked after the <code class="computeroutput"><span class="identifier">precall</span></code>
function supplied by the <code class="computeroutput"><span class="identifier">outer</span></code>
template, and the <code class="computeroutput"><span class="identifier">postcall</span></code>
function of the <code class="computeroutput"><span class="identifier">Base</span></code> is
invoked before the <code class="computeroutput"><span class="identifier">postcall</span></code>
function of the <code class="computeroutput"><span class="identifier">outer</span></code> template.
If a <code class="computeroutput"><span class="identifier">result_converter</span></code> is
supplied by the <code class="computeroutput"><span class="identifier">outer</span></code> template,
it replaces any <code class="computeroutput"><span class="identifier">result_converter</span></code>
supplied by the <code class="computeroutput"><span class="identifier">Base</span></code>. For
an example, see <code class="computeroutput"><span class="identifier">return_internal_reference</span></code>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.callpolicies.concept_requirements"></a><a class="link" href="concepts.html#concepts.callpolicies.concept_requirements" title="Concept Requirements">Concept
Requirements</a>
</h3></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Type
</p>
</th>
<th>
<p>
Result/Semantics
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">x</span><span class="special">.</span><span class="identifier">precall</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
convertible to <code class="computeroutput"><span class="keyword">bool</span></code>
</p>
</td>
<td>
<p>
returns <code class="computeroutput"><span class="keyword">false</span></code> and
<code class="computeroutput"><span class="identifier">PyErr_Occurred</span><span class="special">()</span> <span class="special">!=</span>
<span class="number">0</span></code> upon failure, <code class="computeroutput"><span class="keyword">true</span></code> otherwise.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">P</span><span class="special">::</span><span class="identifier">result_converter</span></code>
</p>
</td>
<td>
<p>
A model of <code class="computeroutput"><span class="identifier">ResultConverterGenerator</span></code>.
</p>
</td>
<td>
<p>
An MPL unary Metafunction Class used produce the "preliminary"
result object.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">x</span><span class="special">.</span><span class="identifier">postcall</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
<span class="identifier">r</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
convertible to <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="number">0</span></code> and <code class="computeroutput"><span class="identifier">PyErr_Occurred</span><span class="special">()</span>
<span class="special">!=</span> <span class="number">0</span></code>
upon failure. Must "conserve references" even in the
event of an exception. In other words, if <code class="computeroutput"><span class="identifier">r</span></code>
is not returned, its reference count must be decremented; if
another existing object is returned, its reference count must
be incremented.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">P</span><span class="special">::</span><span class="identifier">extract_return_type</span></code>
</p>
</td>
<td>
<p>
A model of Metafunction.
</p>
</td>
<td>
<p>
An MPL unary Metafunction used extract the return type from a
given signature. By default it is derived from <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">front</span></code>.
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="index.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="concepts/dereferenceable.html"><img src="../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,104 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Dereferenceable</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="prev" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="next" href="extractor.html" title="Extractor">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../concepts.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="extractor.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.dereferenceable"></a><a class="link" href="dereferenceable.html" title="Dereferenceable">Dereferenceable</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="dereferenceable.html#concepts.dereferenceable.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="dereferenceable.html#concepts.dereferenceable.concept_requirements">Concept
Requirements</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.dereferenceable.introduction"></a><a class="link" href="dereferenceable.html#concepts.dereferenceable.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
Instances of a <code class="computeroutput"><span class="identifier">Dereferenceable</span></code>
type can be used like a pointer to access an lvalue.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.dereferenceable.concept_requirements"></a><a class="link" href="dereferenceable.html#concepts.dereferenceable.concept_requirements" title="Concept Requirements">Concept
Requirements</a>
</h3></div></div></div>
<p>
In the table below, <code class="computeroutput"><span class="identifier">T</span></code> is
a model of Dereferenceable, and <code class="computeroutput"><span class="identifier">x</span></code>
denotes an object of type <code class="computeroutput"><span class="identifier">T</span></code>.
In addition, all pointers are <code class="computeroutput"><span class="identifier">Dereferenceable</span></code>.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Result
</p>
</th>
<th>
<p>
Operational Semantics
</p>
</th>
</tr></thead>
<tbody><tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">get_pointer</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
convertible to <code class="computeroutput"><span class="identifier">pointee</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">*</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">&amp;*</span><span class="identifier">x</span></code>,
or a null pointer
</p>
</td>
</tr></tbody>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../concepts.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="extractor.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -1,135 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Extractor</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../concepts.html" title="Chapter&#160;1.&#160;Concepts">
<link rel="prev" href="dereferenceable.html" title="Dereferenceable">
<link rel="next" href="holdergenerator.html" title="HolderGenerator">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/bpl.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="dereferenceable.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="holdergenerator.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts.extractor"></a><a class="link" href="extractor.html" title="Extractor">Extractor</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="extractor.html#concepts.extractor.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="extractor.html#concepts.extractor.concept_requirements">Concept Requirements</a></span></dt>
<dt><span class="section"><a href="extractor.html#concepts.extractor.notes">Notes</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.extractor.introduction"></a><a class="link" href="extractor.html#concepts.extractor.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
An Extractor is a class which Boost.Python can use to extract C++ objects
from Python objects, and is typically used by facilities that define <code class="computeroutput"><span class="identifier">from_python</span></code> conversions for "traditional"
Python extension types.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.extractor.concept_requirements"></a><a class="link" href="extractor.html#concepts.extractor.concept_requirements" title="Concept Requirements">Concept Requirements</a>
</h3></div></div></div>
<p>
In the table below, <code class="computeroutput"><span class="identifier">X</span></code> denotes
a model of <code class="computeroutput"><span class="identifier">Extractor</span></code> and
<code class="computeroutput"><span class="identifier">a</span></code> denotes an instance of
a Python object type.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Expression
</p>
</th>
<th>
<p>
Type
</p>
</th>
<th>
<p>
Semantics
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">X</span><span class="special">::</span><span class="identifier">execute</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code>
</p>
</td>
<td>
<p>
non-void
</p>
</td>
<td>
<p>
Returns the C++ object being extracted. The execute function
must not be overloaded.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">&amp;</span><span class="identifier">a</span><span class="special">.</span><span class="identifier">ob_type</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="identifier">PyTypeObject</span><span class="special">**</span></code>
</p>
</td>
<td>
<p>
Points to the <code class="computeroutput"><span class="identifier">ob_type</span></code>
field of an object which is layout-compatible with <code class="computeroutput"><span class="identifier">PyObject</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts.extractor.notes"></a><a class="link" href="extractor.html#concepts.extractor.notes" title="Notes">Notes</a>
</h3></div></div></div>
<p>
Informally, an Extractor's execute member must be a non-overloaded static
function whose single argument is a Python object type. Acceptable Python
object types include those publicly (and unambiguously) derived from PyObject,
and POD types which are layout-compatible with PyObject.
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="dereferenceable.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../concepts.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="holdergenerator.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show More