removed useless files

This commit is contained in:
Philippe Tillet
2015-01-16 07:36:01 -05:00
parent faa3974f3c
commit f9e5221ec8
17 changed files with 0 additions and 668 deletions

View File

@@ -1,65 +0,0 @@
project(BoostNumpyTests)
if (WIN32)
set(runCmakeTest runCmakeTest.bat)
foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
message( STATUS "configuring runCmakeTest for cfg=${cfg}" )
CONFIGURE_FILE( ${runCmakeTest}.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${cfg}/${runCmakeTest} @ONLY )
endforeach()
else()
set(runCmakeTest runCmakeTest.sh)
CONFIGURE_FILE( ${runCmakeTest}.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${runCmakeTest} @ONLY )
endif()
set( TEST_SOURCE_DIR ${PROJECT_SOURCE_DIR} )
set( TestCommand ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${runCmakeTest} )
# custom macro with most of the redundant code for making a python test
macro( addPythonTest _name _srcpy )
# make the pyd library link against boost_numpy python and boost
TARGET_LINK_LIBRARIES(${_name} boost_numpy ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
# make a test of the module using the python source file in the test directory
ADD_TEST(${_name} ${TestCommand} ${TEST_SOURCE_DIR}/${_srcpy})
# set the regex to use to recognize a failure since `python testfoo.py`
# does not seem to return non-zero with a test failure
set_property(TEST ${_name} PROPERTY FAIL_REGULAR_EXPRESSION "ERROR\\:" "ImportError\\: DLL load failed\\: " )
# put the test target into a VS solution folder named test (should
# be a no-op for Linux)
SET_PROPERTY(TARGET ${_name} PROPERTY FOLDER "test")
endmacro()
PYTHON_ADD_MODULE(dtype_mod dtype_mod.cpp)
addPythonTest( dtype_mod dtype.py )
PYTHON_ADD_MODULE(indexing_mod indexing_mod.cpp)
addPythonTest( indexing_mod indexing.py )
PYTHON_ADD_MODULE(ndarray_mod ndarray_mod.cpp)
addPythonTest( ndarray_mod ndarray.py )
PYTHON_ADD_MODULE(shapes_mod shapes_mod.cpp)
addPythonTest( shapes_mod shapes.py )
PYTHON_ADD_MODULE(templates_mod templates_mod.cpp)
addPythonTest( templates_mod templates.py )
PYTHON_ADD_MODULE(ufunc_mod ufunc_mod.cpp)
addPythonTest( ufunc_mod ufunc.py )
# installation logic (skip until it is better thought out)
# set(DEST_TEST boost.numpy/test)
#
# # copy the extension modules to DEST_TEST
# install(TARGETS dtype_mod indexing_mod ndarray_mod shapes_mod templates_mod ufunc_mod LIBRARY
# DESTINATION ${DEST_TEST}
# ${INSTALL_PERMSSIONS_RUNTIME}
# )
#
# # copy the source test python modules to DEST_TEST too
# install(FILES dtype.py indexing.py ndarray.py shapes.py templates.py ufunc.py
# DESTINATION ${DEST_TEST}
# ${INSTALL_PERMSSIONS_SRC}
# )

View File

@@ -1,23 +0,0 @@
import testing ;
import python ;
use-project /boost/numpy : ../src ;
project /boost/numpy/test ;
rule numpy-test ( name : sources * : requirements * )
{
sources ?= $(name).py $(name)_mod.cpp ;
return [ testing.make-test run-pyd : $(sources) /boost/numpy//boost_numpy
: $(requirements) : $(name) ] ;
}
test-suite numpy
:
[ numpy-test templates ]
[ numpy-test ufunc ]
[ numpy-test shapes ]
[ numpy-test ndarray ]
[ numpy-test indexing ]
;

View File

@@ -1,35 +0,0 @@
# -*- python -*-
# Copyright Jim Bosch 2010-2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
Import("env")
import os
import sys
test_env = env.Clone()
lib_path = os.path.abspath(os.path.join("..", "src"))
test_env.Append(LIBPATH=[lib_path])
test_env.Append(RPATH=[lib_path])
test_env.Append(LINKFLAGS = ["$__RPATH"]) # workaround for SCons bug #1644t
test_env.Append(LIBS=["boost_numpy"])
test = []
def RunPythonUnitTest(target, source, env):
if not env.Execute('%s %s' % (sys.executable, source[0].abspath)):
env.Execute(Touch(target))
def PythonUnitTest(env, script, dependencies):
run = env.Command(".%s.succeeded" % str(script), script, RunPythonUnitTest)
env.Depends(run, dependencies)
return run
for name in ("dtype", "ufunc", "templates", "ndarray", "indexing", "shapes"):
mod = test_env.LoadableModule("%s_mod" % name, "%s_mod.cpp" % name, LDMODULEPREFIX="")
test.extend(PythonUnitTest(test_env, "%s.py" % name, mod))
Return("test")

View File

@@ -1,60 +0,0 @@
#!/usr/bin/env python
# Copyright Jim Bosch & Ankit Daftery 2010-2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import dtype_mod
import unittest
import numpy
class DtypeTestCase(unittest.TestCase):
def assertEquivalent(self, a, b):
return self.assert_(dtype_mod.equivalent(a, b), "%r is not equivalent to %r")
def testIntegers(self):
for bits in (8, 16, 32, 64):
s = getattr(numpy, "int%d" % bits)
u = getattr(numpy, "uint%d" % bits)
fs = getattr(dtype_mod, "accept_int%d" % bits)
fu = getattr(dtype_mod, "accept_uint%d" % bits)
self.assertEquivalent(fs(s(1)), numpy.dtype(s))
self.assertEquivalent(fu(u(1)), numpy.dtype(u))
# these should just use the regular Boost.Python converters
self.assertEquivalent(fs(True), numpy.dtype(s))
self.assertEquivalent(fu(True), numpy.dtype(u))
self.assertEquivalent(fs(int(1)), numpy.dtype(s))
self.assertEquivalent(fu(int(1)), numpy.dtype(u))
self.assertEquivalent(fs(long(1)), numpy.dtype(s))
self.assertEquivalent(fu(long(1)), numpy.dtype(u))
for name in ("bool_", "byte", "ubyte", "short", "ushort", "intc", "uintc"):
t = getattr(numpy, name)
ft = getattr(dtype_mod, "accept_%s" % name)
self.assertEquivalent(ft(t(1)), numpy.dtype(t))
# these should just use the regular Boost.Python converters
self.assertEquivalent(ft(True), numpy.dtype(t))
if name != "bool_":
self.assertEquivalent(ft(int(1)), numpy.dtype(t))
self.assertEquivalent(ft(long(1)), numpy.dtype(t))
def testFloats(self):
f = numpy.float32
c = numpy.complex64
self.assertEquivalent(dtype_mod.accept_float32(f(numpy.pi)), numpy.dtype(f))
self.assertEquivalent(dtype_mod.accept_complex64(c(1+2j)), numpy.dtype(c))
f = numpy.float64
c = numpy.complex128
self.assertEquivalent(dtype_mod.accept_float64(f(numpy.pi)), numpy.dtype(f))
self.assertEquivalent(dtype_mod.accept_complex128(c(1+2j)), numpy.dtype(c))
if hasattr(numpy, "longdouble"):
f = numpy.longdouble
c = numpy.clongdouble
self.assertEquivalent(dtype_mod.accept_longdouble(f(numpy.pi)), numpy.dtype(f))
self.assertEquivalent(dtype_mod.accept_clongdouble(c(1+2j)), numpy.dtype(c))
if __name__=="__main__":
unittest.main()

View File

@@ -1,48 +0,0 @@
// Copyright Jim Bosch & Ankit Daftery 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/numpy.hpp>
#include <boost/cstdint.hpp>
namespace p = boost::python;
namespace np = boost::numpy;
template <typename T>
np::dtype accept(T) {
return np::dtype::get_builtin<T>();
}
BOOST_PYTHON_MODULE(dtype_mod)
{
np::initialize();
// wrap dtype equivalence test, since it isn't available in Python API.
p::def("equivalent", np::equivalent);
// integers, by number of bits
p::def("accept_int8", accept<boost::int8_t>);
p::def("accept_uint8", accept<boost::uint8_t>);
p::def("accept_int16", accept<boost::int16_t>);
p::def("accept_uint16", accept<boost::uint16_t>);
p::def("accept_int32", accept<boost::int32_t>);
p::def("accept_uint32", accept<boost::uint32_t>);
p::def("accept_int64", accept<boost::int64_t>);
p::def("accept_uint64", accept<boost::uint64_t>);
// integers, by C name according to NumPy
p::def("accept_bool_", accept<bool>);
p::def("accept_byte", accept<signed char>);
p::def("accept_ubyte", accept<unsigned char>);
p::def("accept_short", accept<short>);
p::def("accept_ushort", accept<unsigned short>);
p::def("accept_intc", accept<int>);
p::def("accept_uintc", accept<unsigned int>);
// floats and complex
p::def("accept_float32", accept<float>);
p::def("accept_complex64", accept< std::complex<float> >);
p::def("accept_float64", accept<double>);
p::def("accept_complex128", accept< std::complex<double> >);
if (sizeof(long double) > sizeof(double)) {
p::def("accept_longdouble", accept<long double>);
p::def("accept_clongdouble", accept< std::complex<long double> >);
}
}

View File

@@ -1,55 +0,0 @@
#!/usr/bin/env python
# Copyright Jim Bosch & Ankit Daftery 2010-2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import unittest
import numpy
import indexing_mod
class TestIndexing(unittest.TestCase):
def testSingle(self):
x = numpy.arange(0,10)
for i in range(0,10):
numpy.testing.assert_equal(indexing_mod.single(x,i), i)
for i in range(-10,0):
numpy.testing.assert_equal(indexing_mod.single(x,i),10+i)
def testSlice(self):
x = numpy.arange(0,10)
sl = slice(3,8)
b = [3,4,5,6,7]
numpy.testing.assert_equal(indexing_mod.slice(x,sl), b)
def testStepSlice(self):
x = numpy.arange(0,10)
sl = slice(3,8,2)
b = [3,5,7]
numpy.testing.assert_equal(indexing_mod.slice(x,sl), b)
def testIndex(self):
x = numpy.arange(0,10)
chk = numpy.array([3,4,5,6])
numpy.testing.assert_equal(indexing_mod.indexarray(x,chk),chk)
chk = numpy.array([[0,1],[2,3]])
numpy.testing.assert_equal(indexing_mod.indexarray(x,chk),chk)
x = numpy.arange(9).reshape(3,3)
y = numpy.array([0,1])
z = numpy.array([0,2])
chk = numpy.array([0,5])
numpy.testing.assert_equal(indexing_mod.indexarray(x,y,z),chk)
x = numpy.arange(0,10)
b = x>4
chk = numpy.array([5,6,7,8,9])
numpy.testing.assert_equal(indexing_mod.indexarray(x,b),chk)
x = numpy.arange(9).reshape(3,3)
b = numpy.array([0,2])
sl = slice(0,3)
chk = numpy.array([[0,1,2],[6,7,8]])
numpy.testing.assert_equal(indexing_mod.indexslice(x,b,sl),chk)
if __name__=="__main__":
unittest.main()

View File

@@ -1,27 +0,0 @@
// Copyright Jim Bosch & Ankit Daftery 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/numpy.hpp>
#include <boost/python/slice.hpp>
namespace p = boost::python;
namespace np = boost::numpy;
p::object single(np::ndarray ndarr, int i) { return ndarr[i];}
p::object slice(np::ndarray ndarr, p::slice sl) { return ndarr[sl];}
p::object indexarray(np::ndarray ndarr, np::ndarray d1) { return ndarr[d1];}
p::object indexarray_2d(np::ndarray ndarr, np::ndarray d1,np::ndarray d2) { return ndarr[p::make_tuple(d1,d2)];}
p::object indexslice(np::ndarray ndarr, np::ndarray d1, p::slice sl) { return ndarr[p::make_tuple(d1, sl)];}
BOOST_PYTHON_MODULE(indexing_mod)
{
np::initialize();
p::def("single", single);
p::def("slice", slice);
p::def("indexarray", indexarray);
p::def("indexarray", indexarray_2d);
p::def("indexslice", indexslice);
}

View File

@@ -1,79 +0,0 @@
#!/usr/bin/env python
# Copyright Jim Bosch & Ankit Daftery 2010-2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import ndarray_mod
import unittest
import numpy
class TestNdarray(unittest.TestCase):
def testNdzeros(self):
for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
v = numpy.zeros(60, dtype=dtp)
dt = numpy.dtype(dtp)
for shape in ((60,),(6,10),(4,3,5),(2,2,3,5)):
a1 = ndarray_mod.zeros(shape,dt)
a2 = v.reshape(a1.shape)
self.assertEqual(shape,a1.shape)
self.assert_((a1 == a2).all())
def testNdzeros_matrix(self):
for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
dt = numpy.dtype(dtp)
shape = (6, 10)
a1 = ndarray_mod.zeros_matrix(shape, dt)
a2 = numpy.matrix(numpy.zeros(shape, dtype=dtp))
self.assertEqual(shape,a1.shape)
self.assert_((a1 == a2).all())
self.assertEqual(type(a1), type(a2))
def testNdarray(self):
a = range(0,60)
for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
v = numpy.array(a, dtype=dtp)
dt = numpy.dtype(dtp)
a1 = ndarray_mod.array(a)
a2 = ndarray_mod.array(a,dt)
self.assert_((a1 == v).all())
self.assert_((a2 == v).all())
for shape in ((60,),(6,10),(4,3,5),(2,2,3,5)):
a1 = a1.reshape(shape)
self.assertEqual(shape,a1.shape)
a2 = a2.reshape(shape)
self.assertEqual(shape,a2.shape)
def testNdempty(self):
for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
dt = numpy.dtype(dtp)
for shape in ((60,),(6,10),(4,3,5),(2,2,3,5)):
a1 = ndarray_mod.empty(shape,dt)
a2 = ndarray_mod.c_empty(shape,dt)
self.assertEqual(shape,a1.shape)
self.assertEqual(shape,a2.shape)
def testTranspose(self):
for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
dt = numpy.dtype(dtp)
for shape in ((6,10),(4,3,5),(2,2,3,5)):
a1 = numpy.empty(shape,dt)
a2 = a1.transpose()
a1 = ndarray_mod.transpose(a1)
self.assertEqual(a1.shape,a2.shape)
def testSqueeze(self):
a1 = numpy.array([[[3,4,5]]])
a2 = a1.squeeze()
a1 = ndarray_mod.squeeze(a1)
self.assertEqual(a1.shape,a2.shape)
def testReshape(self):
a1 = numpy.empty((2,2))
a2 = ndarray_mod.reshape(a1,(1,4))
self.assertEqual(a2.shape,(1,4))
if __name__=="__main__":
unittest.main()

View File

@@ -1,45 +0,0 @@
// Copyright Jim Bosch & Ankit Daftery 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/numpy.hpp>
namespace p = boost::python;
namespace np = boost::numpy;
np::ndarray zeros(p::tuple shape, np::dtype dt) { return np::zeros(shape, dt);}
np::ndarray array2(p::object obj, np::dtype dt) { return np::array(obj,dt);}
np::ndarray array1(p::object obj) { return np::array(obj);}
np::ndarray empty1(p::tuple shape, np::dtype dt) { return np::empty(shape,dt);}
np::ndarray c_empty(p::tuple shape, np::dtype dt)
{
// convert 'shape' to a C array so we can test the corresponding
// version of the constructor
unsigned len = p::len(shape);
Py_intptr_t *c_shape = new Py_intptr_t[len];
for (unsigned i = 0; i != len; ++i)
c_shape[i] = p::extract<Py_intptr_t>(shape[i]);
np::ndarray result = np::empty(len, c_shape, dt);
delete [] c_shape;
return result;
}
np::ndarray transpose(np::ndarray arr) { return arr.transpose();}
np::ndarray squeeze(np::ndarray arr) { return arr.squeeze();}
np::ndarray reshape(np::ndarray arr,p::tuple tup) { return arr.reshape(tup);}
BOOST_PYTHON_MODULE(ndarray_mod)
{
np::initialize();
p::def("zeros", zeros);
p::def("zeros_matrix", zeros, np::as_matrix<>());
p::def("array", array2);
p::def("array", array1);
p::def("empty", empty1);
p::def("c_empty", c_empty);
p::def("transpose", transpose);
p::def("squeeze", squeeze);
p::def("reshape", reshape);
}

View File

@@ -1,4 +0,0 @@
set local
set PYTHONPATH=@CMAKE_LIBRARY_OUTPUT_DIRECTORY@/@cfg@;%PYTHONPATH%
python %1
endlocal

View File

@@ -1,3 +0,0 @@
#!/bin/bash
export PYTHONPATH=@CMAKE_LIBRARY_OUTPUT_DIRECTORY@:${PYTHONPATH}
python $1

View File

@@ -1,21 +0,0 @@
#!/usr/bin/env python
# Copyright Jim Bosch & Ankit Daftery 2010-2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import shapes_mod
import unittest
import numpy
class TestShapes(unittest.TestCase):
def testShapes(self):
a1 = numpy.array([(0,1),(2,3)])
a1_shape = (1,4)
a1 = shapes_mod.reshape(a1,a1_shape)
self.assertEqual(a1_shape,a1.shape)
if __name__=="__main__":
unittest.main()

View File

@@ -1,21 +0,0 @@
// Copyright Jim Bosch & Ankit Daftery 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/numpy.hpp>
namespace p = boost::python;
namespace np = boost::numpy;
np::ndarray reshape(np::ndarray old_array, p::tuple shape)
{
np::ndarray local_shape = old_array.reshape(shape);
return local_shape;
}
BOOST_PYTHON_MODULE(shapes_mod)
{
np::initialize();
p::def("reshape", reshape);
}

View File

@@ -1,28 +0,0 @@
#!/usr/bin/env python
# Copyright Jim Bosch & Ankit Daftery 2010-2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import templates_mod
import unittest
import numpy
class TestTemplates(unittest.TestCase):
def testTemplates(self):
for dtype in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
v = numpy.arange(12, dtype=dtype)
for shape in ((12,), (4, 3), (2, 6)):
a1 = numpy.zeros(shape, dtype=dtype)
a2 = v.reshape(a1.shape)
templates_mod.fill(a1)
self.assert_((a1 == a2).all())
a1 = numpy.zeros((12,), dtype=numpy.float64)
self.assertRaises(TypeError, templates_mod.fill, a1)
a1 = numpy.zeros((12,2,3), dtype=numpy.float32)
self.assertRaises(TypeError, templates_mod.fill, a1)
if __name__=="__main__":
unittest.main()

View File

@@ -1,62 +0,0 @@
// Copyright Jim Bosch & Ankit Daftery 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/numpy.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector_c.hpp>
namespace p = boost::python;
namespace np = boost::numpy;
struct ArrayFiller
{
typedef boost::mpl::vector< short, int, float, std::complex<double> > TypeSequence;
typedef boost::mpl::vector_c< int, 1, 2 > DimSequence;
explicit ArrayFiller(np::ndarray const & arg) : argument(arg) {}
template <typename T, int N>
void apply() const
{
if (N == 1)
{
char * p = argument.get_data();
int stride = argument.strides(0);
int size = argument.shape(0);
for (int n = 0; n != size; ++n, p += stride)
*reinterpret_cast<T*>(p) = static_cast<T>(n);
}
else
{
char * row_p = argument.get_data();
int row_stride = argument.strides(0);
int col_stride = argument.strides(1);
int rows = argument.shape(0);
int cols = argument.shape(1);
int i = 0;
for (int n = 0; n != rows; ++n, row_p += row_stride)
{
char * col_p = row_p;
for (int m = 0; m != cols; ++i, ++m, col_p += col_stride)
*reinterpret_cast<T*>(col_p) = static_cast<T>(i);
}
}
}
np::ndarray argument;
};
void fill(np::ndarray const & arg)
{
ArrayFiller filler(arg);
np::invoke_matching_array<ArrayFiller::TypeSequence, ArrayFiller::DimSequence >(arg, filler);
}
BOOST_PYTHON_MODULE(templates_mod)
{
np::initialize();
p::def("fill", fill);
}

View File

@@ -1,57 +0,0 @@
#!/usr/bin/env python
# Copyright Jim Bosch & Ankit Daftery 2010-2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import ufunc_mod
import unittest
import numpy
from numpy.testing.utils import assert_array_almost_equal
class TestUnary(unittest.TestCase):
def testScalar(self):
f = ufunc_mod.UnaryCallable()
assert_array_almost_equal(f(1.0), 2.0)
assert_array_almost_equal(f(3.0), 6.0)
def testArray(self):
f = ufunc_mod.UnaryCallable()
a = numpy.arange(5, dtype=float)
b = f(a)
assert_array_almost_equal(b, a*2.0)
c = numpy.zeros(5, dtype=float)
d = f(a,output=c)
self.assert_(c is d)
assert_array_almost_equal(d, a*2.0)
def testList(self):
f = ufunc_mod.UnaryCallable()
a = range(5)
b = f(a)
assert_array_almost_equal(b/2.0, a)
class TestBinary(unittest.TestCase):
def testScalar(self):
f = ufunc_mod.BinaryCallable()
assert_array_almost_equal(f(1.0, 3.0), 11.0)
assert_array_almost_equal(f(3.0, 2.0), 12.0)
def testArray(self):
f = ufunc_mod.BinaryCallable()
a = numpy.random.randn(5)
b = numpy.random.randn(5)
assert_array_almost_equal(f(a,b), (a*2+b*3))
c = numpy.zeros(5, dtype=float)
d = f(a,b,output=c)
self.assert_(c is d)
assert_array_almost_equal(d, a*2 + b*3)
assert_array_almost_equal(f(a, 2.0), a*2 + 6.0)
assert_array_almost_equal(f(1.0, b), 2.0 + b*3)
if __name__=="__main__":
unittest.main()

View File

@@ -1,35 +0,0 @@
// Copyright Jim Bosch & Ankit Daftery 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/numpy.hpp>
namespace p = boost::python;
namespace np = boost::numpy;
struct UnaryCallable
{
typedef double argument_type;
typedef double result_type;
double operator()(double r) const { return r * 2;}
};
struct BinaryCallable
{
typedef double first_argument_type;
typedef double second_argument_type;
typedef double result_type;
double operator()(double a, double b) const { return a * 2 + b * 3;}
};
BOOST_PYTHON_MODULE(ufunc_mod)
{
np::initialize();
p::class_<UnaryCallable>("UnaryCallable")
.def("__call__", np::unary_ufunc<UnaryCallable>::make());
p::class_< BinaryCallable>("BinaryCallable")
.def("__call__", np::binary_ufunc<BinaryCallable>::make());
}