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
8e93df82
Commit
8e93df82
authored
May 01, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor clarification regarding keep_alive; fixed some typos
parent
c993bcec
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
docs/advanced.rst
+11
-10
No files found.
docs/advanced.rst
View file @
8e93df82
...
@@ -515,12 +515,13 @@ specified to indicate dependencies between parameters. There is currently just
...
@@ -515,12 +515,13 @@ specified to indicate dependencies between parameters. There is currently just
one policy named ``keep_alive<Nurse, Patient>``, which indicates that the
one policy named ``keep_alive<Nurse, Patient>``, which indicates that the
argument with index ``Patient`` should be kept alive at least until the
argument with index ``Patient`` should be kept alive at least until the
argument with index ``Nurse`` is freed by the garbage collector; argument
argument with index ``Nurse`` is freed by the garbage collector; argument
indices start at one, while zero refers to the return value. Arbitrarily many
indices start at one, while zero refers to the return value. For methods, index
call policies can be specified.
one refers to the implicit ``this`` pointer, while regular arguments begin at
index two. Arbitrarily many call policies can be specified.
For instance, binding code for a a list append operation that ties the lifetime
Consider the following example: the binding code for a list append operation
of the newly added element to the underlying container might be declared as
that ties the lifetime of the newly added element to the underlying container
follows:
might be declared as
follows:
.. code-block:: cpp
.. code-block:: cpp
...
@@ -542,7 +543,7 @@ Implicit type conversions
...
@@ -542,7 +543,7 @@ Implicit type conversions
=========================
=========================
Suppose that instances of two types ``A`` and ``B`` are used in a project, and
Suppose that instances of two types ``A`` and ``B`` are used in a project, and
that an ``A`` can easily be converted into a
a
n instance of type ``B`` (examples of this
that an ``A`` can easily be converted into an instance of type ``B`` (examples of this
could be a fixed and an arbitrary precision number type).
could be a fixed and an arbitrary precision number type).
.. code-block:: cpp
.. code-block:: cpp
...
@@ -815,7 +816,7 @@ we want to bind the following simplistic Matrix class:
...
@@ -815,7 +816,7 @@ we want to bind the following simplistic Matrix class:
};
};
The following binding code exposes the ``Matrix`` contents as a buffer object,
The following binding code exposes the ``Matrix`` contents as a buffer object,
making it possible to cast Matri
x
es into NumPy arrays. It is even possible to
making it possible to cast Matri
c
es into NumPy arrays. It is even possible to
completely avoid copy operations with Python expressions like
completely avoid copy operations with Python expressions like
``np.array(matrix_instance, copy = False)``.
``np.array(matrix_instance, copy = False)``.
...
@@ -930,7 +931,7 @@ After including the ``pybind11/numpy.h`` header, this is extremely simple:
...
@@ -930,7 +931,7 @@ After including the ``pybind11/numpy.h`` header, this is extremely simple:
m.def("vectorized_func", py::vectorize(my_func));
m.def("vectorized_func", py::vectorize(my_func));
Invoking the function like below causes 4 calls to be made to ``my_func`` with
Invoking the function like below causes 4 calls to be made to ``my_func`` with
each of the
the
array elements. The significant advantage of this compared to
each of the array elements. The significant advantage of this compared to
solutions like ``numpy.vectorize()`` is that the loop over the elements runs
solutions like ``numpy.vectorize()`` is that the loop over the elements runs
entirely on the C++ side and can be crunched down into a tight, optimized loop
entirely on the C++ side and can be crunched down into a tight, optimized loop
by the compiler. The result is returned as a NumPy array of type
by the compiler. The result is returned as a NumPy array of type
...
@@ -948,7 +949,7 @@ arrays ``x`` and ``y`` are automatically converted into the right types (they
...
@@ -948,7 +949,7 @@ arrays ``x`` and ``y`` are automatically converted into the right types (they
are of type ``numpy.dtype.int64`` but need to be ``numpy.dtype.int32`` and
are of type ``numpy.dtype.int64`` but need to be ``numpy.dtype.int32`` and
``numpy.dtype.float32``, respectively)
``numpy.dtype.float32``, respectively)
Sometimes we might want to explitly exclude an argument from the vectorization
Sometimes we might want to expli
ci
tly exclude an argument from the vectorization
because it makes little sense to wrap it in a NumPy array. For instance,
because it makes little sense to wrap it in a NumPy array. For instance,
suppose the function signature was
suppose the function signature was
...
@@ -1255,7 +1256,7 @@ the declaration
...
@@ -1255,7 +1256,7 @@ the declaration
PYBIND11_MAKE_OPAQUE(std::vector<int>);
PYBIND11_MAKE_OPAQUE(std::vector<int>);
before any binding code (e.g. invocations to ``class_::def()``, etc). This
before any binding code (e.g. invocations to ``class_::def()``, etc
.
). This
macro must be specified at the top level, since instantiates a partial template
macro must be specified at the top level, since instantiates a partial template
overload. If your binding code consists of multiple compilation units, it must
overload. If your binding code consists of multiple compilation units, it must
be present in every file preceding any usage of ``std::vector<int>``. Opaque
be present in every file preceding any usage of ``std::vector<int>``. Opaque
...
...
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