]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/numpy/ufunc.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / python / test / numpy / ufunc.cpp
1 // Copyright Jim Bosch & Ankit Daftery 2010-2012.
2 // Copyright Stefan Seefeld 2016.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <boost/python/numpy.hpp>
8
9 namespace p = boost::python;
10 namespace np = boost::python::numpy;
11
12 struct UnaryCallable
13 {
14 typedef double argument_type;
15 typedef double result_type;
16
17 double operator()(double r) const { return r * 2;}
18 };
19
20 struct BinaryCallable
21 {
22 typedef double first_argument_type;
23 typedef double second_argument_type;
24 typedef double result_type;
25
26 double operator()(double a, double b) const { return a * 2 + b * 3;}
27 };
28
29 BOOST_PYTHON_MODULE(ufunc_ext)
30 {
31 np::initialize();
32 p::class_<UnaryCallable>("UnaryCallable")
33 .def("__call__", np::unary_ufunc<UnaryCallable>::make());
34 p::class_< BinaryCallable>("BinaryCallable")
35 .def("__call__", np::binary_ufunc<BinaryCallable>::make());
36 }