ufunc_mod.cpp
Go to the documentation of this file.
00001 // Copyright Jim Bosch & Ankit Daftery 2010-2012.
00002 // Distributed under the Boost Software License, Version 1.0.
00003 //    (See accompanying file LICENSE_1_0.txt or copy at
00004 //          http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #include <boost/numpy.hpp>
00007 
00008 namespace p = boost::python;
00009 namespace np = boost::numpy;
00010 
00011 struct UnaryCallable 
00012 {
00013   typedef double argument_type;
00014   typedef double result_type;
00015 
00016   double operator()(double r) const { return r * 2;}
00017 };
00018 
00019 struct BinaryCallable 
00020 {
00021   typedef double first_argument_type;
00022   typedef double second_argument_type;
00023   typedef double result_type;
00024 
00025   double operator()(double a, double b) const { return a * 2 + b * 3;}
00026 };
00027 
00028 BOOST_PYTHON_MODULE(ufunc_mod) 
00029 {
00030   np::initialize();
00031   p::class_<UnaryCallable>("UnaryCallable")
00032     .def("__call__", np::unary_ufunc<UnaryCallable>::make());
00033   p::class_< BinaryCallable>("BinaryCallable")
00034     .def("__call__", np::binary_ufunc<BinaryCallable>::make());
00035 }


boost_numpy
Author(s): Jim Bosch, Ankit Daftery
autogenerated on Fri Aug 28 2015 10:10:40