Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
8f4eb006
Commit
8f4eb006
authored
Oct 15, 2015
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
last breaking change: be consistent about the project name
parent
607654f7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
164 additions
and
162 deletions
+164
-162
CMakeLists.txt
+8
-8
docs/advanced.rst
+15
-15
docs/basics.rst
+40
-40
docs/classes.rst
+3
-3
docs/reference.rst
+5
-5
example/example.h
+2
-2
example/example10.cpp
+1
-1
example/example12.cpp
+1
-1
example/example2.cpp
+1
-1
example/example3.cpp
+1
-1
example/example5.cpp
+1
-1
example/example6.cpp
+2
-2
example/example8.cpp
+1
-4
include/pybind11/cast.h
+12
-6
include/pybind11/common.h
+4
-4
include/pybind11/complex.h
+4
-4
include/pybind11/functional.h
+5
-5
include/pybind11/numpy.h
+6
-6
include/pybind11/operators.h
+6
-6
include/pybind11/pybind11.h
+29
-29
include/pybind11/pytypes.h
+9
-9
include/pybind11/stl.h
+4
-4
include/pybind11/typeid.h
+4
-5
No files found.
CMakeLists.txt
View file @
8f4eb006
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
cmake_minimum_required
(
VERSION 2.8
)
cmake_minimum_required
(
VERSION 2.8
)
project
(
pybind
)
project
(
pybind
11
)
# Add a CMake parameter for choosing a desired Python version
# Add a CMake parameter for choosing a desired Python version
set
(
PYBIND_PYTHON_VERSION
""
CACHE STRING
"Python version to use for compiling the example application"
)
set
(
PYBIND_PYTHON_VERSION
""
CACHE STRING
"Python version to use for compiling the example application"
)
...
@@ -55,13 +55,13 @@ include_directories(include)
...
@@ -55,13 +55,13 @@ include_directories(include)
# Create the binding library
# Create the binding library
add_library
(
example SHARED
add_library
(
example SHARED
include/pybind/cast.h
include/pybind
11
/cast.h
include/pybind/common.h
include/pybind
11
/common.h
include/pybind/operators.h
include/pybind
11
/operators.h
include/pybind
/pybind
.h
include/pybind
11/pybind11
.h
include/pybind/pytypes.h
include/pybind
11
/pytypes.h
include/pybind/typeid.h
include/pybind
11
/typeid.h
include/pybind/numpy.h
include/pybind
11
/numpy.h
example/example.cpp
example/example.cpp
example/example1.cpp
example/example1.cpp
example/example2.cpp
example/example2.cpp
...
...
docs/advanced.rst
View file @
8f4eb006
...
@@ -8,9 +8,9 @@ present:
...
@@ -8,9 +8,9 @@ present:
.. code-block:: cpp
.. code-block:: cpp
#include <pybind
/pybind
.h>
#include <pybind
11/pybind11
.h>
namespace py = pybind
;
namespace py = pybind
11
Operator overloading
Operator overloading
====================
====================
...
@@ -43,10 +43,10 @@ to Python.
...
@@ -43,10 +43,10 @@ to Python.
.. code-block:: cpp
.. code-block:: cpp
#include <pybind/operators.h>
#include <pybind
11
/operators.h>
PYBIND_PLUGIN(example) {
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<Vector2>(m, "Vector2")
py::class_<Vector2>(m, "Vector2")
.def(py::init<float, float>())
.def(py::init<float, float>())
...
@@ -79,7 +79,7 @@ C++ side, or to perform other types of customization.
...
@@ -79,7 +79,7 @@ C++ side, or to perform other types of customization.
.. note::
.. note::
To use the more convenient ``py::self`` notation, the additional
To use the more convenient ``py::self`` notation, the additional
header file :file:`pybind/operators.h` must be included.
header file :file:`pybind
11
/operators.h` must be included.
.. seealso::
.. seealso::
...
@@ -120,15 +120,15 @@ its return value upon execution.
...
@@ -120,15 +120,15 @@ its return value upon execution.
};
};
}
}
After including the extra header file :file:`pybind/functional.h`, it is almost
After including the extra header file :file:`pybind
11
/functional.h`, it is almost
trivial to generate binding code for both of these functions.
trivial to generate binding code for both of these functions.
.. code-block:: cpp
.. code-block:: cpp
#include <pybind/functional.h>
#include <pybind
11
/functional.h>
PYBIND_PLUGIN(example) {
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
m.def("func_arg", &func_arg);
m.def("func_arg", &func_arg);
m.def("func_ret", &func_ret);
m.def("func_ret", &func_ret);
...
@@ -200,7 +200,7 @@ Normally, the binding code for these classes would look as follows:
...
@@ -200,7 +200,7 @@ Normally, the binding code for these classes would look as follows:
.. code-block:: cpp
.. code-block:: cpp
PYBIND_PLUGIN(example) {
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<Animal> animal(m, "Animal");
py::class_<Animal> animal(m, "Animal");
animal
animal
...
@@ -248,7 +248,7 @@ a default implementation. The binding code also needs a few minor adaptations
...
@@ -248,7 +248,7 @@ a default implementation. The binding code also needs a few minor adaptations
:emphasize-lines: 4,6,7
:emphasize-lines: 4,6,7
PYBIND_PLUGIN(example) {
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<PyAnimal> animal(m, "Animal");
py::class_<PyAnimal> animal(m, "Animal");
animal
animal
...
@@ -295,11 +295,11 @@ a virtual method call.
...
@@ -295,11 +295,11 @@ a virtual method call.
Passing STL data structures
Passing STL data structures
===========================
===========================
When including the additional header file :file:`pybind/stl.h`, conversions
When including the additional header file :file:`pybind
11
/stl.h`, conversions
between ``std::vector<>`` and ``std::map<>`` and the Python ``list`` and
between ``std::vector<>`` and ``std::map<>`` and the Python ``list`` and
``dict`` data structures are automatically enabled. The types ``std::pair<>``
``dict`` data structures are automatically enabled. The types ``std::pair<>``
and ``std::tuple<>`` are already supported out of the box with just the core
and ``std::tuple<>`` are already supported out of the box with just the core
:file:`pybind
/pybind
.h` header.
:file:`pybind
11/pybind11
.h` header.
.. note::
.. note::
...
@@ -376,7 +376,7 @@ See below for an example that uses the
...
@@ -376,7 +376,7 @@ See below for an example that uses the
};
};
PYBIND_PLUGIN(example) {
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<Example>(m, "Example")
py::class_<Example>(m, "Example")
.def(py::init<>())
.def(py::init<>())
...
@@ -620,7 +620,7 @@ dense array of doubles in C-style ordering.
...
@@ -620,7 +620,7 @@ dense array of doubles in C-style ordering.
When it is invoked with a different type (e.g. an integer), the binding code
When it is invoked with a different type (e.g. an integer), the binding code
will attempt to cast the input into a NumPy array of the requested type.
will attempt to cast the input into a NumPy array of the requested type.
Note that this feature requires the ``pybind/numpy.h`` header to be included.
Note that this feature requires the ``pybind
11
/numpy.h`` header to be included.
Vectorizing functions
Vectorizing functions
=====================
=====================
...
@@ -633,7 +633,7 @@ N-D arrays) in addition to its normal arguments:
...
@@ -633,7 +633,7 @@ N-D arrays) in addition to its normal arguments:
double my_func(int x, float y, double z);
double my_func(int x, float y, double z);
After including the ``pybind/numpy.h`` header, this is extremely simple:
After including the ``pybind
11
/numpy.h`` header, this is extremely simple:
.. code-block:: cpp
.. code-block:: cpp
...
...
docs/basics.rst
View file @
8f4eb006
...
@@ -37,7 +37,7 @@ Windows
...
@@ -37,7 +37,7 @@ Windows
On Windows, use the `CMake GUI`_ to create a Visual Studio project. Note that
On Windows, use the `CMake GUI`_ to create a Visual Studio project. Note that
only the 2015 release and newer versions are supported since pybind11 relies on
only the 2015 release and newer versions are supported since pybind11 relies on
various C++11 language features that break older versions of Visual Studio.
various C++11 language features that break older versions of Visual Studio.
After running CMake, open the created :file:`pybind.sln` file and perform a
After running CMake, open the created :file:`pybind
11
.sln` file and perform a
release build, which will will produce a file named
release build, which will will produce a file named
:file:`Release\\example.pyd`. Copy this file to the :file:`example` directory
:file:`Release\\example.pyd`. Copy this file to the :file:`example` directory
and run :file:`example\\run_test.py` using the targeted Python version.
and run :file:`example\\run_test.py` using the targeted Python version.
...
@@ -79,16 +79,16 @@ a file named :file:`example.cpp` with the following contents:
...
@@ -79,16 +79,16 @@ a file named :file:`example.cpp` with the following contents:
.. code-block:: cpp
.. code-block:: cpp
#include <pybind
/pybind
.h>
#include <pybind
11/pybind11
.h>
int add(int i, int j) {
int add(int i, int j) {
return i + j;
return i + j;
}
}
namespace py = pybind
;
namespace py = pybind
11
PYBIND_PLUGIN(example) {
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
m.def("add", &add, "A function which adds two numbers");
m.def("add", &add, "A function which adds two numbers");
...
@@ -117,7 +117,7 @@ example can be compiled using the following command
...
@@ -117,7 +117,7 @@ example can be compiled using the following command
.. code-block:: bash
.. code-block:: bash
$ c++ -O3 -shared -std=c++11 -I <path-to-pybind>/include `python-config --cflags --libs` example.cpp -o example.so
$ c++ -O3 -shared -std=c++11 -I <path-to-pybind
11
>/include `python-config --cflags --libs` example.cpp -o example.so
In general, it is advisable to include several additional build parameters
In general, it is advisable to include several additional build parameters
that can considerably reduce the size of the created binary. Refer to section
that can considerably reduce the size of the created binary. Refer to section
...
@@ -222,41 +222,41 @@ The following basic data types are supported out of the box (some may require
...
@@ -222,41 +222,41 @@ The following basic data types are supported out of the box (some may require
an additional extension header to be included). To pass other data structures
an additional extension header to be included). To pass other data structures
as arguments and return values, refer to the section on binding :ref:`classes`.
as arguments and return values, refer to the section on binding :ref:`classes`.
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| Data type | Description | Header file |
| Data type | Description | Header file
|
+========================+==========================+=====================+
+========================+==========================+=====================
==
+
| int8_t, uint8_t | 8-bit integers | pybind
/pybind.h
|
| int8_t, uint8_t | 8-bit integers | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| int16_t, uint16_t | 16-bit integers | pybind
/pybind.h
|
| int16_t, uint16_t | 16-bit integers | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| int32_t, uint32_t | 32-bit integers | pybind
/pybind.h
|
| int32_t, uint32_t | 32-bit integers | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| int64_t, uint64_t | 64-bit integers | pybind
/pybind.h
|
| int64_t, uint64_t | 64-bit integers | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| ssize_t, size_t | Platform-dependent size | pybind
/pybind.h
|
| ssize_t, size_t | Platform-dependent size | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| float, double | Floating point types | pybind
/pybind.h
|
| float, double | Floating point types | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| bool | Two-state Boolean type | pybind
/pybind.h
|
| bool | Two-state Boolean type | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| char | Character literal | pybind
/pybind.h
|
| char | Character literal | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| const char * | UTF-8 string literal | pybind
/pybind.h
|
| const char * | UTF-8 string literal | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| std::string | STL dynamic UTF-8 string | pybind
/pybind.h
|
| std::string | STL dynamic UTF-8 string | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| std::pair<T1, T2> | Pair of two custom types | pybind
/pybind.h
|
| std::pair<T1, T2> | Pair of two custom types | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| std::tuple<....> | Arbitrary tuple of types | pybind
/pybind.h
|
| std::tuple<....> | Arbitrary tuple of types | pybind
11/pybind11.h
|
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| std::complex<T> | Complex numbers | pybind/complex.h |
| std::complex<T> | Complex numbers | pybind
11
/complex.h |
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| std::vector<T> | STL dynamic array | pybind/stl.h |
| std::vector<T> | STL dynamic array | pybind
11
/stl.h |
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| std::map<T1, T2> | STL dynamic maps | pybind/stl.h |
| std::map<T1, T2> | STL dynamic maps | pybind
11
/stl.h |
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| std::function<...> | STL polymorphic function | pybind/functional.h |
| std::function<...> | STL polymorphic function | pybind
11
/functional.h |
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
.. [#f1] In practice, implementation and binding code will generally be located
.. [#f1] In practice, implementation and binding code will generally be located
...
...
docs/classes.rst
View file @
8f4eb006
...
@@ -23,12 +23,12 @@ The binding code for ``Pet`` looks as follows:
...
@@ -23,12 +23,12 @@ The binding code for ``Pet`` looks as follows:
.. code-block:: cpp
.. code-block:: cpp
#include <pybind
/pybind
.h>
#include <pybind
11/pybind11
.h>
namespace py = pybind
;
namespace py = pybind
11
PYBIND_PLUGIN(example) {
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<Pet>(m, "Pet")
py::class_<Pet>(m, "Pet")
.def(py::init<const std::string &>())
.def(py::init<const std::string &>())
...
...
docs/reference.rst
View file @
8f4eb006
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
Please be advised that the reference documentation discussing pybind11
Please be advised that the reference documentation discussing pybind11
internals is currently incomplete. Please refer to the previous sections
internals is currently incomplete. Please refer to the previous sections
and the pybind header files for the nitty gritty details.
and the pybind
11
header files for the nitty gritty details.
Reference
Reference
#########
#########
...
@@ -22,7 +22,7 @@ Macros
...
@@ -22,7 +22,7 @@ Macros
.. code-block:: cpp
.. code-block:: cpp
PYBIND_PLUGIN(example) {
PYBIND_PLUGIN(example) {
pybind
::module m("example", "pybind
example plugin");
pybind
11::module m("example", "pybind11
example plugin");
/// Set up bindings here
/// Set up bindings here
return m.ptr();
return m.ptr();
}
}
...
@@ -188,9 +188,9 @@ Convenience classes for specific Python types
...
@@ -188,9 +188,9 @@ Convenience classes for specific Python types
.. code-block:: cpp
.. code-block:: cpp
pybind
::module m("example", "pybind
example plugin");
pybind
11::module m("example", "pybind11
example plugin");
pybind::module m2 = m.def_submodule("sub", "A submodule of 'example'");
pybind
11
::module m2 = m.def_submodule("sub", "A submodule of 'example'");
pybind::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
pybind
11
::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
.. cpp:function:: template <typename Func, typename ... Extra> module& module::def(const char *name, Func && f, Extra && ... extra)
.. cpp:function:: template <typename Func, typename ... Extra> module& module::def(const char *name, Func && f, Extra && ... extra)
...
...
example/example.h
View file @
8f4eb006
#include <pybind
/pybind
.h>
#include <pybind
11/pybind11
.h>
#include <iostream>
#include <iostream>
using
std
::
cout
;
using
std
::
cout
;
using
std
::
endl
;
using
std
::
endl
;
namespace
py
=
pybind
;
namespace
py
=
pybind
11
;
example/example10.cpp
View file @
8f4eb006
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
*/
*/
#include "example.h"
#include "example.h"
#include <pybind/numpy.h>
#include <pybind
11
/numpy.h>
double
my_func
(
int
x
,
float
y
,
double
z
)
{
double
my_func
(
int
x
,
float
y
,
double
z
)
{
std
::
cout
<<
"my_func(x:int="
<<
x
<<
", y:float="
<<
y
<<
", z:float="
<<
z
<<
")"
<<
std
::
endl
;
std
::
cout
<<
"my_func(x:int="
<<
x
<<
", y:float="
<<
y
<<
", z:float="
<<
z
<<
")"
<<
std
::
endl
;
...
...
example/example12.cpp
View file @
8f4eb006
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*/
*/
#include "example.h"
#include "example.h"
#include <pybind/functional.h>
#include <pybind
11
/functional.h>
/* This is an example class that we'll want to be able to extend from Python */
/* This is an example class that we'll want to be able to extend from Python */
class
Example12
{
class
Example12
{
...
...
example/example2.cpp
View file @
8f4eb006
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
*/
*/
#include "example.h"
#include "example.h"
#include <pybind/stl.h>
#include <pybind
11
/stl.h>
class
Example2
{
class
Example2
{
public
:
public
:
...
...
example/example3.cpp
View file @
8f4eb006
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*/
*/
#include "example.h"
#include "example.h"
#include <pybind/operators.h>
#include <pybind
11
/operators.h>
class
Vector2
{
class
Vector2
{
public
:
public
:
...
...
example/example5.cpp
View file @
8f4eb006
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
*/
*/
#include "example.h"
#include "example.h"
#include <pybind/functional.h>
#include <pybind
11
/functional.h>
class
Pet
{
class
Pet
{
...
...
example/example6.cpp
View file @
8f4eb006
...
@@ -9,8 +9,8 @@
...
@@ -9,8 +9,8 @@
*/
*/
#include "example.h"
#include "example.h"
#include <pybind/operators.h>
#include <pybind
11
/operators.h>
#include <pybind/stl.h>
#include <pybind
11
/stl.h>
class
Sequence
{
class
Sequence
{
public
:
public
:
...
...
example/example8.cpp
View file @
8f4eb006
...
@@ -32,10 +32,7 @@ private:
...
@@ -32,10 +32,7 @@ private:
};
};
/// Make pybind aware of the ref-counted wrapper type
/// Make pybind aware of the ref-counted wrapper type
namespace
pybind
{
namespace
detail
{
PYBIND_DECLARE_HOLDER_TYPE
(
T
,
ref
<
T
>
);
template
<
typename
T
>
class
type_caster
<
ref
<
T
>>
:
public
type_caster_holder
<
T
,
ref
<
T
>>
{
};
}}
Object
*
make_object_1
()
{
return
new
MyObject
(
1
);
}
Object
*
make_object_1
()
{
return
new
MyObject
(
1
);
}
ref
<
Object
>
make_object_2
()
{
return
new
MyObject
(
2
);
}
ref
<
Object
>
make_object_2
()
{
return
new
MyObject
(
2
);
}
...
...
include/pybind/cast.h
→
include/pybind
11
/cast.h
View file @
8f4eb006
/*
/*
pybind/cast.h: Partial template specializations to cast between
pybind
11
/cast.h: Partial template specializations to cast between
C++ and Python types
C++ and Python types
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -10,12 +10,12 @@
...
@@ -10,12 +10,12 @@
#pragma once
#pragma once
#include
<pybind/pytypes.h>
#include
"pytypes.h"
#include
<pybind/typeid.h>
#include
"typeid.h"
#include <array>
#include <array>
#include <limits>
#include <limits>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
NAMESPACE_BEGIN
(
detail
)
NAMESPACE_BEGIN
(
detail
)
#if defined(_MSC_VER)
#if defined(_MSC_VER)
...
@@ -527,6 +527,12 @@ protected:
...
@@ -527,6 +527,12 @@ protected:
holder_type
holder
;
holder_type
holder
;
};
};
#define PYBIND_DECLARE_HOLDER_TYPE(type, holder_type) \
namespace pybind11 { namespace detail { \
template <typename type> class type_caster<holder_type> \
: public type_caster_holder<type, holder_type> { }; \
}}
template
<>
class
type_caster
<
handle
>
{
template
<>
class
type_caster
<
handle
>
{
public
:
public
:
bool
load
(
PyObject
*
src
)
{
bool
load
(
PyObject
*
src
)
{
...
@@ -571,7 +577,7 @@ template <typename T> inline object cast(const T &value, return_value_policy pol
...
@@ -571,7 +577,7 @@ template <typename T> inline object cast(const T &value, return_value_policy pol
return
object
(
detail
::
type_caster
<
typename
detail
::
decay
<
T
>::
type
>::
cast
(
value
,
policy
,
parent
),
false
);
return
object
(
detail
::
type_caster
<
typename
detail
::
decay
<
T
>::
type
>::
cast
(
value
,
policy
,
parent
),
false
);
}
}
template
<
typename
T
>
inline
T
handle
::
cast
()
{
return
pybind
::
cast
<
T
>
(
m_ptr
);
}
template
<
typename
T
>
inline
T
handle
::
cast
()
{
return
pybind
11
::
cast
<
T
>
(
m_ptr
);
}
template
<>
inline
void
handle
::
cast
()
{
return
;
}
template
<>
inline
void
handle
::
cast
()
{
return
;
}
template
<
typename
...
Args
>
inline
object
handle
::
call
(
Args
&&
...
args_
)
{
template
<
typename
...
Args
>
inline
object
handle
::
call
(
Args
&&
...
args_
)
{
...
@@ -601,4 +607,4 @@ template <typename... Args> inline object handle::call(Args&&... args_) {
...
@@ -601,4 +607,4 @@ template <typename... Args> inline object handle::call(Args&&... args_) {
return
object
(
result
,
false
);
return
object
(
result
,
false
);
}
}
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/common.h
→
include/pybind
11
/common.h
View file @
8f4eb006
/*
/*
pybind/common.h -- Basic macros
pybind
11
/common.h -- Basic macros
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -68,7 +68,7 @@
...
@@ -68,7 +68,7 @@
extern "C" PYBIND_EXPORT PyObject *init##name()
extern "C" PYBIND_EXPORT PyObject *init##name()
#endif
#endif
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
typedef
Py_ssize_t
ssize_t
;
typedef
Py_ssize_t
ssize_t
;
...
@@ -192,7 +192,7 @@ NAMESPACE_END(detail)
...
@@ -192,7 +192,7 @@ NAMESPACE_END(detail)
struct
stop_iteration
:
public
std
::
runtime_error
{
public
:
stop_iteration
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
struct
stop_iteration
:
public
std
::
runtime_error
{
public
:
stop_iteration
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
struct
index_error
:
public
std
::
runtime_error
{
public
:
index_error
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
struct
index_error
:
public
std
::
runtime_error
{
public
:
index_error
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
struct
error_already_set
:
public
std
::
runtime_error
{
public
:
error_already_set
()
:
std
::
runtime_error
(
detail
::
error_string
())
{}
};
struct
error_already_set
:
public
std
::
runtime_error
{
public
:
error_already_set
()
:
std
::
runtime_error
(
detail
::
error_string
())
{}
};
/// Thrown when pybind::cast or handle::call fail due to a type casting error
/// Thrown when pybind
11
::cast or handle::call fail due to a type casting error
struct
cast_error
:
public
std
::
runtime_error
{
public
:
cast_error
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
struct
cast_error
:
public
std
::
runtime_error
{
public
:
cast_error
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/complex.h
→
include/pybind
11
/complex.h
View file @
8f4eb006
/*
/*
pybind/complex.h: Complex number support
pybind
11
/complex.h: Complex number support
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -9,10 +9,10 @@
...
@@ -9,10 +9,10 @@
#pragma once
#pragma once
#include
<pybind/pybind.h>
#include
"pybind11.h"
#include <complex>
#include <complex>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
PYBIND_DECL_FMT
(
std
::
complex
<
float
>
,
"Zf"
);
PYBIND_DECL_FMT
(
std
::
complex
<
float
>
,
"Zf"
);
PYBIND_DECL_FMT
(
std
::
complex
<
double
>
,
"Zd"
);
PYBIND_DECL_FMT
(
std
::
complex
<
double
>
,
"Zd"
);
...
@@ -37,4 +37,4 @@ public:
...
@@ -37,4 +37,4 @@ public:
PYBIND_TYPE_CASTER
(
std
::
complex
<
T
>
,
"complex"
);
PYBIND_TYPE_CASTER
(
std
::
complex
<
T
>
,
"complex"
);
};
};
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/functional.h
→
include/pybind
11
/functional.h
View file @
8f4eb006
/*
/*
pybind/functional.h: std::function<> support
pybind
11
/functional.h: std::function<> support
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -9,10 +9,10 @@
...
@@ -9,10 +9,10 @@
#pragma once
#pragma once
#include
<pybind/pybind.h>
#include
"pybind11.h"
#include <functional>
#include <functional>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
NAMESPACE_BEGIN
(
detail
)
NAMESPACE_BEGIN
(
detail
)
template
<
typename
Return
,
typename
...
Args
>
struct
type_caster
<
std
::
function
<
Return
(
Args
...)
>>
{
template
<
typename
Return
,
typename
...
Args
>
struct
type_caster
<
std
::
function
<
Return
(
Args
...)
>>
{
...
@@ -24,7 +24,7 @@ public:
...
@@ -24,7 +24,7 @@ public:
return
false
;
return
false
;
object
src
(
src_
,
true
);
object
src
(
src_
,
true
);
value
=
[
src
](
Args
...
args
)
->
Return
{
value
=
[
src
](
Args
...
args
)
->
Return
{
object
retval
(
pybind
::
handle
(
src
).
call
(
std
::
move
(
args
)...));
object
retval
(
pybind
11
::
handle
(
src
).
call
(
std
::
move
(
args
)...));
/* Visual studio 2015 parser issue: need parentheses around this expression */
/* Visual studio 2015 parser issue: need parentheses around this expression */
return
(
retval
.
template
cast
<
Return
>
());
return
(
retval
.
template
cast
<
Return
>
());
};
};
...
@@ -46,4 +46,4 @@ public:
...
@@ -46,4 +46,4 @@ public:
};
};
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/numpy.h
→
include/pybind
11
/numpy.h
View file @
8f4eb006
/*
/*
pybind/numpy.h: Basic NumPy support, auto-vectorization support
pybind
11
/numpy.h: Basic NumPy support, auto-vectorization support
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -9,15 +9,15 @@
...
@@ -9,15 +9,15 @@
#pragma once
#pragma once
#include
<pybind/pybind.h>
#include
"pybind11.h"
#include
<pybind/complex.h>
#include
"complex.h"
#if defined(_MSC_VER)
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(push)
#pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#endif
#endif
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
template
<
typename
type
>
struct
npy_format_descriptor
{
};
template
<
typename
type
>
struct
npy_format_descriptor
{
};
...
@@ -196,7 +196,7 @@ struct vectorize_helper {
...
@@ -196,7 +196,7 @@ struct vectorize_helper {
/* Check if the parameters are actually compatible */
/* Check if the parameters are actually compatible */
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
if
(
buffers
[
i
].
count
!=
1
&&
(
buffers
[
i
].
ndim
!=
ndim
||
buffers
[
i
].
shape
!=
shape
))
if
(
buffers
[
i
].
count
!=
1
&&
(
buffers
[
i
].
ndim
!=
ndim
||
buffers
[
i
].
shape
!=
shape
))
throw
std
::
runtime_error
(
"pybind::vectorize: incompatible size/dimension of inputs!"
);
throw
std
::
runtime_error
(
"pybind
11
::vectorize: incompatible size/dimension of inputs!"
);
}
}
/* Call the function */
/* Call the function */
...
@@ -234,7 +234,7 @@ template <typename func> auto vectorize(func &&f) -> decltype(
...
@@ -234,7 +234,7 @@ template <typename func> auto vectorize(func &&f) -> decltype(
&
std
::
remove_reference
<
func
>::
type
::
operator
())
>::
type
*
)
nullptr
);
&
std
::
remove_reference
<
func
>::
type
::
operator
())
>::
type
*
)
nullptr
);
}
}
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
#if defined(_MSC_VER)
#if defined(_MSC_VER)
#pragma warning(pop)
#pragma warning(pop)
...
...
include/pybind/operators.h
→
include/pybind
11
/operators.h
View file @
8f4eb006
/*
/*
pybind/operator.h: Metatemplates for operator overloading
pybind
11
/operator.h: Metatemplates for operator overloading
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -9,10 +9,10 @@
...
@@ -9,10 +9,10 @@
#pragma once
#pragma once
#include
<pybind/pybind.h>
#include
"pybind11.h"
#include <type_traits>
#include <type_traits>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
NAMESPACE_BEGIN
(
detail
)
NAMESPACE_BEGIN
(
detail
)
/// Enumeration with all supported operator types
/// Enumeration with all supported operator types
...
@@ -45,13 +45,13 @@ template <op_id, op_type, typename B, typename L, typename R> struct op_impl { }
...
@@ -45,13 +45,13 @@ template <op_id, op_type, typename B, typename L, typename R> struct op_impl { }
/// Operator implementation generator
/// Operator implementation generator
template
<
op_id
id
,
op_type
ot
,
typename
L
,
typename
R
>
struct
op_
{
template
<
op_id
id
,
op_type
ot
,
typename
L
,
typename
R
>
struct
op_
{
template
<
typename
Base
,
typename
Holder
,
typename
...
Extra
>
void
execute
(
pybind
::
class_
<
Base
,
Holder
>
&
class_
,
Extra
&&
...
extra
)
const
{
template
<
typename
Base
,
typename
Holder
,
typename
...
Extra
>
void
execute
(
pybind
11
::
class_
<
Base
,
Holder
>
&
class_
,
Extra
&&
...
extra
)
const
{
typedef
typename
std
::
conditional
<
std
::
is_same
<
L
,
self_t
>::
value
,
Base
,
L
>::
type
L_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
L
,
self_t
>::
value
,
Base
,
L
>::
type
L_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
R
,
self_t
>::
value
,
Base
,
R
>::
type
R_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
R
,
self_t
>::
value
,
Base
,
R
>::
type
R_type
;
typedef
op_impl
<
id
,
ot
,
Base
,
L_type
,
R_type
>
op
;
typedef
op_impl
<
id
,
ot
,
Base
,
L_type
,
R_type
>
op
;
class_
.
def
(
op
::
name
(),
&
op
::
execute
,
std
::
forward
<
Extra
>
(
extra
)...);
class_
.
def
(
op
::
name
(),
&
op
::
execute
,
std
::
forward
<
Extra
>
(
extra
)...);
}
}
template
<
typename
Base
,
typename
Holder
,
typename
...
Extra
>
void
execute_cast
(
pybind
::
class_
<
Base
,
Holder
>
&
class_
,
Extra
&&
...
extra
)
const
{
template
<
typename
Base
,
typename
Holder
,
typename
...
Extra
>
void
execute_cast
(
pybind
11
::
class_
<
Base
,
Holder
>
&
class_
,
Extra
&&
...
extra
)
const
{
typedef
typename
std
::
conditional
<
std
::
is_same
<
L
,
self_t
>::
value
,
Base
,
L
>::
type
L_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
L
,
self_t
>::
value
,
Base
,
L
>::
type
L_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
R
,
self_t
>::
value
,
Base
,
R
>::
type
R_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
R
,
self_t
>::
value
,
Base
,
R
>::
type
R_type
;
typedef
op_impl
<
id
,
ot
,
Base
,
L_type
,
R_type
>
op
;
typedef
op_impl
<
id
,
ot
,
Base
,
L_type
,
R_type
>
op
;
...
@@ -146,4 +146,4 @@ NAMESPACE_END(detail)
...
@@ -146,4 +146,4 @@ NAMESPACE_END(detail)
using
detail
::
self
;
using
detail
::
self
;
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind
/pybind
.h
→
include/pybind
11/pybind11
.h
View file @
8f4eb006
This diff is collapsed.
Click to expand it.
include/pybind/pytypes.h
→
include/pybind
11
/pytypes.h
View file @
8f4eb006
/*
/*
pybind/typeid.h: Convenience wrapper classes for basic Python types
pybind
11
/typeid.h: Convenience wrapper classes for basic Python types
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -9,10 +9,10 @@
...
@@ -9,10 +9,10 @@
#pragma once
#pragma once
#include
<pybind/common.h>
#include
"common.h"
#include <utility>
#include <utility>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
/* A few forward declarations */
/* A few forward declarations */
class
object
;
class
object
;
...
@@ -37,7 +37,7 @@ public:
...
@@ -37,7 +37,7 @@ public:
inline
detail
::
accessor
operator
[](
const
char
*
key
);
inline
detail
::
accessor
operator
[](
const
char
*
key
);
inline
detail
::
accessor
attr
(
handle
key
);
inline
detail
::
accessor
attr
(
handle
key
);
inline
detail
::
accessor
attr
(
const
char
*
key
);
inline
detail
::
accessor
attr
(
const
char
*
key
);
inline
pybind
::
str
str
()
const
;
inline
pybind
11
::
str
str
()
const
;
template
<
typename
T
>
T
cast
();
template
<
typename
T
>
T
cast
();
template
<
typename
...
Args
>
object
call
(
Args
&&
...
args_
);
template
<
typename
...
Args
>
object
call
(
Args
&&
...
args_
);
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
...
@@ -230,13 +230,13 @@ private:
...
@@ -230,13 +230,13 @@ private:
#endif
#endif
};
};
inline
pybind
::
str
handle
::
str
()
const
{
inline
pybind
11
::
str
handle
::
str
()
const
{
PyObject
*
str
=
PyObject_Str
(
m_ptr
);
PyObject
*
str
=
PyObject_Str
(
m_ptr
);
#if PY_MAJOR_VERSION < 3
#if PY_MAJOR_VERSION < 3
PyObject
*
unicode
=
PyUnicode_FromEncodedObject
(
str
,
"utf-8"
,
nullptr
);
PyObject
*
unicode
=
PyUnicode_FromEncodedObject
(
str
,
"utf-8"
,
nullptr
);
Py_XDECREF
(
str
);
str
=
unicode
;
Py_XDECREF
(
str
);
str
=
unicode
;
#endif
#endif
return
pybind
::
str
(
str
,
false
);
return
pybind
11
::
str
(
str
,
false
);
}
}
class
bool_
:
public
object
{
class
bool_
:
public
object
{
...
@@ -370,12 +370,12 @@ inline internals &get_internals() {
...
@@ -370,12 +370,12 @@ inline internals &get_internals() {
if
(
internals_ptr
)
if
(
internals_ptr
)
return
*
internals_ptr
;
return
*
internals_ptr
;
handle
builtins
(
PyEval_GetBuiltins
());
handle
builtins
(
PyEval_GetBuiltins
());
capsule
caps
(
builtins
[
"__pybind__"
]);
capsule
caps
(
builtins
[
"__pybind
11
__"
]);
if
(
caps
.
check
())
{
if
(
caps
.
check
())
{
internals_ptr
=
caps
;
internals_ptr
=
caps
;
}
else
{
}
else
{
internals_ptr
=
new
internals
();
internals_ptr
=
new
internals
();
builtins
[
"__pybind__"
]
=
capsule
(
internals_ptr
);
builtins
[
"__pybind
11
__"
]
=
capsule
(
internals_ptr
);
}
}
return
*
internals_ptr
;
return
*
internals_ptr
;
}
}
...
@@ -413,4 +413,4 @@ inline handle get_type_handle(const std::type_info &tp) {
...
@@ -413,4 +413,4 @@ inline handle get_type_handle(const std::type_info &tp) {
}
}
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/stl.h
→
include/pybind
11
/stl.h
View file @
8f4eb006
/*
/*
pybind/complex.h: Complex number support
pybind
11
/complex.h: Complex number support
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#pragma once
#pragma once
#include
<pybind/pybind.h>
#include
"pybind11.h"
#include <map>
#include <map>
#include <iostream>
#include <iostream>
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
#pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#endif
#endif
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
NAMESPACE_BEGIN
(
detail
)
NAMESPACE_BEGIN
(
detail
)
template
<
typename
Value
>
struct
type_caster
<
std
::
vector
<
Value
>>
{
template
<
typename
Value
>
struct
type_caster
<
std
::
vector
<
Value
>>
{
...
@@ -104,7 +104,7 @@ NAMESPACE_END(detail)
...
@@ -104,7 +104,7 @@ NAMESPACE_END(detail)
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
object
&
obj
)
{
os
<<
(
const
char
*
)
obj
.
str
();
return
os
;
}
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
object
&
obj
)
{
os
<<
(
const
char
*
)
obj
.
str
();
return
os
;
}
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
#if defined(_MSC_VER)
#if defined(_MSC_VER)
#pragma warning(pop)
#pragma warning(pop)
...
...
include/pybind/typeid.h
→
include/pybind
11
/typeid.h
View file @
8f4eb006
/*
/*
pybind/typeid.h: Compiler-independent access to type identifiers
pybind
11
/typeid.h: Compiler-independent access to type identifiers
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
@@ -9,14 +9,13 @@
...
@@ -9,14 +9,13 @@
#pragma once
#pragma once
#include <pybind/typeid.h>
#include <cstdio>
#include <cstdio>
#include <cstdlib>
#include <cstdlib>
#if defined(__GNUG__)
#if defined(__GNUG__)
#include <cxxabi.h>
#include <cxxabi.h>
#endif
#endif
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
NAMESPACE_BEGIN
(
detail
)
NAMESPACE_BEGIN
(
detail
)
/// Erase all occurrences of a substring
/// Erase all occurrences of a substring
inline
void
erase_all
(
std
::
string
&
string
,
const
std
::
string
&
search
)
{
inline
void
erase_all
(
std
::
string
&
string
,
const
std
::
string
&
search
)
{
...
@@ -39,7 +38,7 @@ inline void clean_type_id(std::string &name) {
...
@@ -39,7 +38,7 @@ inline void clean_type_id(std::string &name) {
detail
::
erase_all
(
name
,
"struct "
);
detail
::
erase_all
(
name
,
"struct "
);
detail
::
erase_all
(
name
,
"enum "
);
detail
::
erase_all
(
name
,
"enum "
);
#endif
#endif
detail
::
erase_all
(
name
,
"pybind::"
);
detail
::
erase_all
(
name
,
"pybind
11
::"
);
}
}
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
...
@@ -50,4 +49,4 @@ template <typename T> static std::string type_id() {
...
@@ -50,4 +49,4 @@ template <typename T> static std::string type_id() {
return
name
;
return
name
;
}
}
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment