mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 18:12:43 +00:00
https://svn.boost.org/svn/boost/trunk ................ r43810 | eric_niebler | 2008-03-23 14:51:40 -0700 (Sun, 23 Mar 2008) | 1 line mark up new foreach tests ................ r43823 | fmhess | 2008-03-24 08:07:00 -0700 (Mon, 24 Mar 2008) | 3 lines Fixed compile error with new enable_shared_from_this code, reported by Tim Blechmann ................ r43825 | ramey | 2008-03-24 08:46:09 -0700 (Mon, 24 Mar 2008) | 1 line removed EXIT_SUCCESS ................ r43826 | ramey | 2008-03-24 08:46:43 -0700 (Mon, 24 Mar 2008) | 1 line fixed minor typo ................ r43829 | pdimov | 2008-03-24 09:00:28 -0700 (Mon, 24 Mar 2008) | 1 line New enable_shared_from_this tests, fix. ................ r43838 | danieljames | 2008-03-24 10:03:15 -0700 (Mon, 24 Mar 2008) | 12 lines Merge new changes to unordered & hash. - Unordered tests can run lightweight test or Boost.Test (at least theoretically). - Workaround Open BSD's incorrect numeric_limits. - Move the hash extensions in their own file. - Various small improvements to the unordered docs. - Fix some unordered examples. Merged revisions 43117-43837 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk ................ r43845 | dave | 2008-03-24 11:27:22 -0700 (Mon, 24 Mar 2008) | 1 line Work around vc9 bugs ................ r43847 | anthonyw | 2008-03-24 14:44:36 -0700 (Mon, 24 Mar 2008) | 1 line removed forward declaration for undefined type exclusive_lock ................ r43852 | hkaiser | 2008-03-25 06:40:53 -0700 (Tue, 25 Mar 2008) | 1 line Wave: Removed an assertion causing compilation problems on certain platforms. ................ r43856 | pdimov | 2008-03-25 08:46:40 -0700 (Tue, 25 Mar 2008) | 1 line _internal_accept_owner now checks if _owned isn't already true. ................ r43861 | dave | 2008-03-25 13:47:38 -0700 (Tue, 25 Mar 2008) | 2 lines Work around intel-10.0-win compiler bug ................ r43864 | dave | 2008-03-25 15:28:59 -0700 (Tue, 25 Mar 2008) | 2 lines Account for intel 10.x compiler bug ................ r43865 | dave | 2008-03-25 16:06:50 -0700 (Tue, 25 Mar 2008) | 2 lines Work around intel-win-10.0 preprocessor bug ................ r43866 | danieljames | 2008-03-26 02:10:29 -0700 (Wed, 26 Mar 2008) | 3 lines Boost.Thread's documentation no longer has a build section - so just link to the library's documentation like we do for other libraries. ................ r43867 | bemandawes | 2008-03-26 08:59:52 -0700 (Wed, 26 Mar 2008) | 1 line Initial commit ................ r43873 | pdimov | 2008-03-26 11:34:29 -0700 (Wed, 26 Mar 2008) | 1 line Added "Throws: nothing" to get_deleter. ................ r43875 | bemandawes | 2008-03-26 14:26:55 -0700 (Wed, 26 Mar 2008) | 1 line Initial commit ................ r43876 | danieljames | 2008-03-26 22:49:45 -0700 (Wed, 26 Mar 2008) | 2 lines Update the thread links in the generated getting started documentation. ................ r43879 | chris_kohlhoff | 2008-03-27 07:18:07 -0700 (Thu, 27 Mar 2008) | 3 lines Fix double-free error that occurs when an exception is thrown from a handler that has been dispatched (i.e. not posted) through a strand. ................ r43880 | ramey | 2008-03-27 08:53:37 -0700 (Thu, 27 Mar 2008) | 1 line removed suppression of builds for certain platforms with shared libraries ................ r43882 | ramey | 2008-03-27 10:11:23 -0700 (Thu, 27 Mar 2008) | 1 line tweaks to sneak past PGI compiler error message ................ r43883 | ramey | 2008-03-27 10:12:22 -0700 (Thu, 27 Mar 2008) | 1 line added test to check warnings on type trait ................ r43884 | dgregor | 2008-03-27 12:44:37 -0700 (Thu, 27 Mar 2008) | 1 line Change Boost.Function allocator behavior, from Emil Dotchevski ................ r43887 | pdimov | 2008-03-27 15:13:55 -0700 (Thu, 27 Mar 2008) | 1 line Silence unused parameter warning. ................ r43888 | pdimov | 2008-03-27 15:20:11 -0700 (Thu, 27 Mar 2008) | 1 line detail::yield(k) added. ................ r43895 | danieljames | 2008-03-27 16:38:01 -0700 (Thu, 27 Mar 2008) | 25 lines Merged revisions 43838-43894 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk ........ r43840 | danieljames | 2008-03-24 17:25:07 +0000 (Mon, 24 Mar 2008) | 1 line Fix a g++ warning. ........ r43844 | danieljames | 2008-03-24 17:56:28 +0000 (Mon, 24 Mar 2008) | 1 line It's a new-ish year. ........ r43885 | danieljames | 2008-03-27 20:36:10 +0000 (Thu, 27 Mar 2008) | 1 line The release script doesn't need to copy images and css - because that's now done in the jamfiles. Also tweak the shell script a tad bit. ........ r43890 | danieljames | 2008-03-27 23:01:40 +0000 (Thu, 27 Mar 2008) | 1 line Starting to add a docbook bibliography. ........ r43894 | danieljames | 2008-03-27 23:24:18 +0000 (Thu, 27 Mar 2008) | 1 line Redeclare 'data' in iterator_base to help compilers which have trouble with accessing the nested typedef. ........ ................ r43900 | noel_belcourt | 2008-03-27 19:10:04 -0700 (Thu, 27 Mar 2008) | 4 lines Fix address-model support for 32/64 bit code generation. Replaced -mcmodel with -m32 / -m64. ................ r43901 | bemandawes | 2008-03-27 19:11:13 -0700 (Thu, 27 Mar 2008) | 1 line Remove per email from Dave ................ r43906 | eric_niebler | 2008-03-27 23:10:55 -0700 (Thu, 27 Mar 2008) | 1 line proto support for BOOST_PROTO_MAX_FUNCTION_CALL_ARITY ................ [SVN r43910]
137 lines
4.1 KiB
C++
137 lines
4.1 KiB
C++
// Copyright David Abrahams 2002.
|
|
// 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/python/numeric.hpp>
|
|
#include <boost/python/tuple.hpp>
|
|
#include <boost/python/module.hpp>
|
|
#include <boost/python/def.hpp>
|
|
#include <boost/python/str.hpp>
|
|
|
|
using namespace boost::python;
|
|
namespace py = boost::python;
|
|
|
|
// See if we can invoke array() from C++
|
|
numeric::array new_array()
|
|
{
|
|
return numeric::array(
|
|
py::make_tuple(
|
|
py::make_tuple(1,2,3)
|
|
, py::make_tuple(4,5,6)
|
|
, py::make_tuple(7,8,9)
|
|
)
|
|
);
|
|
}
|
|
|
|
// test argument conversion
|
|
void take_array(numeric::array /*x*/)
|
|
{
|
|
}
|
|
|
|
// A separate function to invoke the info() member. Must happen
|
|
// outside any doctests since this prints directly to stdout and the
|
|
// result text includes the address of the 'self' array.
|
|
void info(numeric::array const& z)
|
|
{
|
|
z.info();
|
|
}
|
|
|
|
namespace
|
|
{
|
|
object handle_error()
|
|
{
|
|
PyObject* type, *value, *traceback;
|
|
PyErr_Fetch(&type, &value, &traceback);
|
|
handle<> ty(type), v(value), tr(traceback);
|
|
return object("exception");
|
|
str format("exception type: %sn");
|
|
format += "exception value: %sn";
|
|
format += "traceback:n%s" ;
|
|
object ret = format % py::make_tuple(ty, v, tr);
|
|
return ret;
|
|
}
|
|
}
|
|
#define CHECK(expr) \
|
|
{ \
|
|
object result; \
|
|
try { result = object(expr); } \
|
|
catch(error_already_set) \
|
|
{ \
|
|
result = handle_error(); \
|
|
} \
|
|
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[py::make_tuple(2,1)] = 3;
|
|
CHECK(y);
|
|
CHECK(y.astype('D'));
|
|
CHECK(y.copy());
|
|
CHECK(y.typecode());
|
|
}
|
|
|
|
// numarray-specific tests. check is a callable object which we can
|
|
// use to record intermediate results, which are later compared with
|
|
// the results of corresponding python operations.
|
|
void exercise_numarray(numeric::array& y, object check)
|
|
{
|
|
CHECK(str(y));
|
|
|
|
CHECK(y.argmax());
|
|
CHECK(y.argmax(0));
|
|
|
|
CHECK(y.argmin());
|
|
CHECK(y.argmin(0));
|
|
|
|
CHECK(y.argsort());
|
|
CHECK(y.argsort(1));
|
|
|
|
y.byteswap();
|
|
CHECK(y);
|
|
|
|
CHECK(y.diagonal());
|
|
CHECK(y.diagonal(1));
|
|
CHECK(y.diagonal(0, 0));
|
|
CHECK(y.diagonal(0, 1, 0));
|
|
|
|
CHECK(y.is_c_array());
|
|
CHECK(y.isbyteswapped());
|
|
|
|
CHECK(y.trace());
|
|
CHECK(y.trace(1));
|
|
CHECK(y.trace(0, 0));
|
|
CHECK(y.trace(0, 1, 0));
|
|
|
|
CHECK(y.new_("D").getshape());
|
|
CHECK(y.new_("D").type());
|
|
y.sort();
|
|
CHECK(y);
|
|
CHECK(y.type());
|
|
|
|
CHECK(y.factory(py::make_tuple(1.2, 3.4)));
|
|
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8"));
|
|
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true));
|
|
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false));
|
|
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object()));
|
|
CHECK (y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object(), py::make_tuple(1,2,1)));
|
|
|
|
}
|
|
|
|
BOOST_PYTHON_MODULE(numpy_ext)
|
|
{
|
|
def("new_array", new_array);
|
|
def("take_array", take_array);
|
|
def("exercise", exercise);
|
|
def("exercise_numarray", exercise_numarray);
|
|
def("set_module_and_type", &numeric::array::set_module_and_type);
|
|
def("get_module_name", &numeric::array::get_module_name);
|
|
def("info", info);
|
|
}
|
|
|
|
#include "module_tail.cpp"
|