2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-20 04:42:28 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Christopher Hite
6f68994b33 optional_optimization branch
[SVN r77091]
2012-02-22 10:37:27 +00:00
15 changed files with 91 additions and 80 deletions

View File

@@ -396,33 +396,27 @@
</blockquote>
</dd>
<dt><b><a href="http://pyrap.googlecode.com/">Pyrap</a></b></dt>
<dd>
<p><a href="diepen@astron.nl"
>Ger van Diepen</a> writes:</p>
<blockquote>
<p>Pyrap is the python interface to the Radio-Astronomical Package
casacore (<a href="http://casacore.googlecode.com/"
>casacore.googlecode.com</a>). Astronomers love pyrap because
it makes it easily possible to get their data (observed with
radio-astronomical telescopes like LOFAR, ASKAP, and eVLA) in numpy
arrays and do basic data inspection and manipulation using the many
python packages that are available.</p>
<p>Boost.Python made it quite easily possible to create converters for
the various data types, also for numpy arrays and individual elements
of a numpy array. It's nice they work fully recursively. Mapping C++
functions to Python was straightforward.</p>
</blockquote>
</dd>
<dt><b><a href="http://www.rdkit.org/"
>RDKit: Cheminformatics and Machine Learning Software</a></b></dt>
<dt><b><a href="http://www.rationaldiscovery.com">Rational Discovery
LLC</a></b></dt>
<dd>
A collection of cheminformatics and machine-learning software
written in C++ and Python.
Rational Discovery provides computational modeling, combinatorial
library design and custom software development services to the
pharmaceutical, biotech and chemical industries. We do a substantial
amount of internal research to develop new approaches for applying
machine-learning techniques to solve chemical problems. Because we're a
small organization and chemistry is a large and complex field, it is
essential that we be able to quickly and easily prototype and test new
algorithms.
<p>For our internal software, we implement core data structures in C
and expose them to Python using Boost.Python. Algorithm development is
done in Python and then translated to C if required (often it's not).
This hybrid development approach not only greatly increases our
productivity, but it also allows "non-developers" (people without C
experience) to take part in method development. Learning C is a
daunting task, but "Python fits your brain." (Thanks to Bruce Eckel for
the quote.)</p>
</dd>
</dl>

View File

@@ -372,8 +372,8 @@ Namespaces are one honking great idea -- let's do more of those!
or writing thin wrappers:
</p>
<pre class="programlisting"><span class="comment">// write "thin wrappers"</span>
<span class="keyword">int</span> <span class="identifier">f1</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">f2</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span><span class="identifier">y</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">f1</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span> <span class="special">}</span>
<span class="keyword">int</span> <span class="identifier">f2</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">f</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span><span class="identifier">y</span><span class="special">);</span> <span class="special">}</span>
<span class="comment">/*...*/</span>

View File

@@ -901,8 +901,8 @@ wrapping as outlined in the [link python.overloading previous section], or
writing thin wrappers:
// write "thin wrappers"
int f1(int x) { return f(x); }
int f2(int x, double y) { return f(x,y); }
int f1(int x) { f(x); }
int f2(int x, double y) { f(x,y); }
/*...*/

View File

@@ -96,10 +96,10 @@ template &lt;class F, class Policies, class Keywords, class Signature&gt;
to <code>f</code>. <ul>
<li> If <code>policies</code> are supplied, it
will be applied to the function as described <a href=
"CallPolicies.html">here</a>.
"CallPolicies.html">here</a>.
<li>If <code>keywords</code> are
supplied, the keywords will be applied in order to the final
arguments of the resulting function.
arguments of the resulting function.
<li>If <code>Signature</code>
is supplied, it should be an instance of an <a
href="../../../mpl/doc/refmanual/front-extensible-sequence.html">MPL front-extensible
@@ -125,33 +125,36 @@ template &lt;class F, class Policies, class Keywords, class Signature&gt;
</dl>
<pre>
<a name="make_constructor-spec">template &lt;class F&gt;</a>
<a href="object.html#object-spec">object</a> make_constructor(F f)
template &lt;class F, class Policies&gt;
<a name=
"make_constructor-spec"></a>template &lt;class T, class ArgList, class Generator&gt;
<a href="object.html#object-spec">object</a> make_constructor();
template &lt;class ArgList, class Generator, class Policies&gt;
<a href=
"object.html#object-spec">object</a> make_constructor(F f, Policies const&amp; policies)
template &lt;class F, class Policies, class KeywordsOrSignature&gt;
<a href=
"object.html#object-spec">object</a> make_constructor(F f, Policies const&amp; policies, KeywordsOrSignature const&amp; ks)
template &lt;class F, class Policies, class Keywords, class Signature&gt;
<a href=
"object.html#object-spec">object</a> make_constructor(F f, Policies const&amp; policies, Keywords const&amp; kw, Signature const&amp; sig)
"object.html#object-spec">object</a> make_constructor(Policies const&amp; policies)
</pre>
<dl class="function-semantics">
<dt><b>Requires:</b> <code>F</code> is a
function pointer type. If <code>policies</code> are supplied, it must
be a model of <a href="CallPolicies.html">CallPolicies</a>. If
<code>kewords</code> are supplied, it must be the result of a <a href=
"args.html#keyword-expression"><em>keyword-expression</em></a>
specifying no more arguments than the <a href=
"definitions.html#arity">arity</a> of <code>f</code>.</dt>
<dt><b>Requires:</b> <code>T</code> is a class type.
<code>Policies</code> is a model of <a href=
"CallPolicies.html">CallPolicies</a>. <code>ArgList</code> is an <a
href="../../../mpl/doc/refmanual/forward-sequence.html">MPL sequence</a> of C++ argument
types (<i>A1,&nbsp;A2,...&nbsp;AN</i>) such that if
<code>a1,&nbsp;a2</code>...&nbsp;<code>aN</code> are objects of type
<i>A1,&nbsp;A2,...&nbsp;AN</i> respectively, the expression <code>new
Generator::apply&lt;T&gt;::type(a1,&nbsp;a2</code>...&nbsp;<code>aN</code>)
is valid. Generator is a model of <a href=
"HolderGenerator.html">HolderGenerator</a>.</dt>
<dt><b>Effects:</b> Creates a Python callable object which, when called
from Python, converts its arguments to C++ and calls <code>f</code>.</dt>
from Python, expects its first argument to be a Boost.Python extension
class object. It converts its remaining its arguments to C++ and passes
them to the constructor of a dynamically-allocated
<code>Generator::apply&lt;T&gt;::type</code> object, which is then
installed in the extension class object. In the second form, the
<code>policies</code> are applied to the arguments and result (<a href=
"http://www.python.org/doc/current/lib/bltin-null-object.html">None</a>)
of the Python callable object</dt>
<dt><b>Returns:</b> An instance of <a href=
"object.html#object-spec">object</a> which holds the new Python
@@ -183,7 +186,7 @@ BOOST_PYTHON_MODULE(make_function_test)
def("choose_function", choose_function);
}
</pre>
It can be used this way in Python:
It can be used this way in Python:
<pre>
&gt;&gt;&gt; from make_function_test import *
&gt;&gt;&gt; f = choose_function(1)

View File

@@ -11,10 +11,7 @@ use-project boost
# boost_python library from the project whose global ID is
# /boost/python.
project
: requirements <library>/boost/python//boost_python
<implicit-dependency>/boost//headers
: usage-requirements <implicit-dependency>/boost//headers
;
: requirements <library>/boost/python//boost_python ;
# Declare the three extension modules. You can specify multiple
# source files after the colon separated by spaces.

View File

@@ -12,8 +12,6 @@ use-project boost
# /boost/python.
project boost-python-quickstart
: requirements <library>/boost/python//boost_python
<implicit-dependency>/boost//headers
: usage-requirements <implicit-dependency>/boost//headers
;
# Make the definition of the python-extension rule available

View File

@@ -20,10 +20,7 @@ use-project boost
# boost_python library from the project whose global ID is
# /boost/python.
project
: requirements <library>/boost/python//boost_python
<implicit-dependency>/boost//headers
: usage-requirements <implicit-dependency>/boost//headers
;
: requirements <library>/boost/python//boost_python ;
# Declare the three extension modules. You can specify multiple
# source files after the colon separated by spaces.

View File

@@ -19,6 +19,7 @@
# include <boost/python/detail/copy_ctor_mutates_rhs.hpp>
# include <boost/python/detail/void_ptr.hpp>
# include <boost/python/detail/void_return.hpp>
# include <boost/utility.hpp>
# include <boost/call_traits.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) || BOOST_WORKAROUND(BOOST_INTEL_WIN, <= 900)

View File

@@ -7,7 +7,7 @@
# include <boost/python/detail/prefix.hpp>
# include <boost/noncopyable.hpp>
# include <boost/utility.hpp>
# include <boost/python/type_id.hpp>
# include <cstddef>

View File

@@ -6,6 +6,7 @@
# define CLASS_DWA20011214_HPP
# include <boost/python/detail/prefix.hpp>
# include <boost/utility.hpp>
# include <boost/python/object_core.hpp>
# include <boost/python/type_id.hpp>
# include <cstddef>

View File

@@ -348,14 +348,31 @@ namespace api
// Macros for forwarding constructors in classes derived from
// object. Derived classes will usually want these as an
// implementation detail
# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(derived, base) \
inline explicit derived(::boost::python::detail::borrowed_reference p) \
: base(p) {} \
inline explicit derived(::boost::python::detail::new_reference p) \
: base(p) {} \
inline explicit derived(::boost::python::detail::new_non_null_reference p) \
# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived, base) \
inline explicit derived(python::detail::borrowed_reference p) \
: base(p) {} \
inline explicit derived(python::detail::new_reference p) \
: base(p) {} \
inline explicit derived(python::detail::new_non_null_reference p) \
: base(p) {}
# if !defined(BOOST_MSVC) || BOOST_MSVC >= 1300
# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_
# else
// MSVC6 has a bug which causes an explicit template constructor to
// be preferred over an appropriate implicit conversion operator
// declared on the argument type. Normally, that would cause a
// runtime failure when using extract<T> to extract a type with a
// templated constructor. This additional constructor will turn that
// runtime failure into an ambiguity error at compile-time due to
// the lack of partial ordering, or at least a link-time error if no
// generalized template constructor is declared.
# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(derived, base) \
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived, base) \
template <class T> \
explicit derived(extract<T> const&);
# endif
//
// object_initializer -- get the handle to construct the object with,
// based on whether T is a proxy or derived from object

View File

@@ -182,12 +182,13 @@ PyTypeObject opaque<Pointee>::type_object =
# define BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(Pointee) \
namespace boost { namespace python { \
template<> \
inline type_info type_id<Pointee>() \
inline type_info type_id<Pointee>(BOOST_PYTHON_EXPLICIT_TT_DEF(Pointee)) \
{ \
return type_info (typeid (Pointee *)); \
} \
template<> \
inline type_info type_id<const volatile Pointee&>() \
inline type_info type_id<const volatile Pointee&>( \
BOOST_PYTHON_EXPLICIT_TT_DEF(const volatile Pointee&)) \
{ \
return type_info (typeid (Pointee *)); \
} \

View File

@@ -8,6 +8,7 @@
# include <boost/python/detail/prefix.hpp>
# include <boost/python/object.hpp>
# include <boost/python/refcount.hpp>
# include <boost/utility.hpp>
namespace boost { namespace python {

View File

@@ -69,9 +69,11 @@ struct type_info : private totally_ordered<type_info>
base_id_t m_base_type;
};
// This macro is obsolete. Port away and remove.
# define BOOST_PYTHON_EXPLICIT_TT_DEF(T)
# ifdef BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS
# define BOOST_PYTHON_EXPLICIT_TT_DEF(T) ::boost::type<T>*
# else
# define BOOST_PYTHON_EXPLICIT_TT_DEF(T)
# endif
template <class T>
inline type_info type_id(BOOST_EXPLICIT_TEMPLATE_TYPE(T))
@@ -97,7 +99,7 @@ inline type_info type_id(BOOST_EXPLICIT_TEMPLATE_TYPE(T))
# define BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(T) \
template <> \
inline type_info type_id<T>() \
inline type_info type_id<T>(BOOST_PYTHON_EXPLICIT_TT_DEF(T)) \
{ \
return type_info(typeid(T)); \
}
@@ -171,13 +173,13 @@ BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_info const&);
# if !BOOST_WORKAROUND(BOOST_MSVC, == 1200)
template<>
inline type_info type_id<void>()
inline type_info type_id<void>(BOOST_PYTHON_EXPLICIT_TT_DEF(void))
{
return type_info (typeid (void *));
}
# ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
template<>
inline type_info type_id<const volatile void>()
inline type_info type_id<const volatile void>(BOOST_PYTHON_EXPLICIT_TT_DEF(const volatile void))
{
return type_info (typeid (void *));
}

View File

@@ -377,8 +377,7 @@ namespace
static unaryfunc* get_slot(PyObject* obj)
{
#if PY_VERSION_HEX >= 0x03000000
return (PyUnicode_Check(obj)) ? &py_unicode_as_string_unaryfunc :
PyBytes_Check(obj) ? &py_object_identity : 0;
return (PyUnicode_Check(obj)) ? &py_unicode_as_string_unaryfunc : 0;
#else
return (PyString_Check(obj)) ? &obj->ob_type->tp_str : 0;