From 924eeccd532a2182b7e33126eaad046a76016fc9 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 13 Sep 2006 00:02:56 +0000 Subject: [PATCH] merged from trunk [SVN r35080] --- test/numpy.cpp | 81 ++++++++++++++++++++++++++++++------------------ test/pickle3.cpp | 4 +++ 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/test/numpy.cpp b/test/numpy.cpp index 4c7f0a12..deb9667b 100644 --- a/test/numpy.cpp +++ b/test/numpy.cpp @@ -10,6 +10,10 @@ using namespace boost::python; +#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) +# define make_tuple boost::python::make_tuple +#endif + // See if we can invoke array() from C++ object new_array() { @@ -35,16 +39,33 @@ void info(numeric::array const& z) z.info(); } +#define CHECK(expr) \ +{ \ + object result; \ + try { result = object(expr); } \ + catch(error_already_set) \ + { \ + PyObject* type, *value, *traceback; \ + PyErr_Fetch(&type, &value, &traceback); \ + handle<> ty(type), v(value), tr(traceback); \ + str format("exception type: %s\n"); \ + format += "exception value: %s\n"; \ + format += "traceback:\n%s" ; \ + result = format % boost::python::make_tuple(ty, v, tr); \ + } \ + check(result); \ +} + // Tests which work on both Numeric and numarray array objects. Of // course all of the operators "just work" since numeric::array // inherits that behavior from object. void exercise(numeric::array& y, object check) { y[make_tuple(2,1)] = 3; - check(y); - check(y.astype('D')); - check(y.copy()); - check(y.typecode()); + CHECK(y); + CHECK(y.astype('D')); + CHECK(y.copy()); + CHECK(y.typecode()); } // numarray-specific tests. check is a callable object which we can @@ -52,43 +73,43 @@ void exercise(numeric::array& y, object check) // the results of corresponding python operations. void exercise_numarray(numeric::array& y, object check) { - check(y.astype()); + CHECK(y.astype()); - check(y.argmax()); - check(y.argmax(0)); + CHECK(y.argmax()); + CHECK(y.argmax(0)); - check(y.argmin()); - check(y.argmin(0)); + CHECK(y.argmin()); + CHECK(y.argmin(0)); - check(y.argsort()); - check(y.argsort(1)); + CHECK(y.argsort()); + CHECK(y.argsort(1)); y.byteswap(); - check(y); + CHECK(y); - check(y.diagonal()); - check(y.diagonal(1)); - check(y.diagonal(0, 1)); - check(y.diagonal(0, 1, 0)); + CHECK(y.diagonal()); + CHECK(y.diagonal(1)); + CHECK(y.diagonal(0, 1)); + CHECK(y.diagonal(0, 1, 0)); - check(y.is_c_array()); - check(y.isbyteswapped()); + CHECK(y.is_c_array()); + CHECK(y.isbyteswapped()); - check(y.trace()); - check(y.trace(1)); - check(y.trace(0, 1)); - check(y.trace(0, 1, 0)); + CHECK(y.trace()); + CHECK(y.trace(1)); + CHECK(y.trace(0, 1)); + CHECK(y.trace(0, 1, 0)); - check(y.new_('D')); + CHECK(y.new_('D')); y.sort(); - check(y); - check(y.type()); + CHECK(y); + CHECK(y.type()); - check(y.factory(make_tuple(1.2, 3.4))); - check(y.factory(make_tuple(1.2, 3.4), "Double")); - check(y.factory(make_tuple(1.2, 3.4), "Double", make_tuple(1,2,1))); - check(y.factory(make_tuple(1.2, 3.4), "Double", make_tuple(2,1,1), false)); - check(y.factory(make_tuple(1.2, 3.4), "Double", make_tuple(2), true, true)); + CHECK(y.factory(make_tuple(1.2, 3.4))); + CHECK(y.factory(make_tuple(1.2, 3.4), "Double")); + CHECK(y.factory(make_tuple(1.2, 3.4), "Double", make_tuple(1,2,1))); + CHECK(y.factory(make_tuple(1.2, 3.4), "Double", make_tuple(2,1,1), false)); + CHECK(y.factory(make_tuple(1.2, 3.4), "Double", make_tuple(2), true, true)); } BOOST_PYTHON_MODULE(numpy_ext) diff --git a/test/pickle3.cpp b/test/pickle3.cpp index cffcb9c0..2816a428 100644 --- a/test/pickle3.cpp +++ b/test/pickle3.cpp @@ -25,6 +25,10 @@ #include #include +#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) +# define make_tuple boost::python::make_tuple +#endif + namespace { // Avoid cluttering the global namespace. // A friendly class.