2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-21 17:12:22 +00:00

Fix lots of bugs in the numeric interface and tests.

Tests:
* Coerce a result to bool to deal with Python's new Bool type
* Better reporting of mismatches in expected and received results
* Remove bogus nullary y.astype() call
* Fix all uses of trace and diagonal so they don't cause errors
* Use appropriate typecodes
* Use doctest detailed API to run just the relevant tests
* Factor out error handling from macro

API:
* Added get_module_name() function to get current numeric module
* new_(x) now returns an array instead of object
* Fixed the signatures of the factory() family of functions
* Updated docs accordingly.


[SVN r35528]
This commit is contained in:
Dave Abrahams
2006-10-09 04:05:25 +00:00
parent 545be29ad3
commit 49d4aac8ec
5 changed files with 267 additions and 210 deletions

View File

@@ -17,6 +17,8 @@
namespace boost { namespace python { namespace numeric {
struct array;
namespace aux
{
struct BOOST_PYTHON_DECL array_base : object
@@ -36,18 +38,19 @@ namespace aux
void info() const;
bool is_c_array() const;
bool isbyteswapped() const;
object new_(object type) const;
array new_(object type) const;
void sort();
object trace(long offset = 0, long axis1 = 0, long axis2 = 1) const;
object type() const;
char typecode() const;
object factory(object const& buffer=object()
, object const& type=object()
, object const& shape=object()
, bool copy = true
, bool savespace = false
, object typecode = object());
object factory(
object const& sequence = object()
, object const& typecode = object()
, bool copy = true
, bool savespace = false
, object type = object()
, object shape = object());
object getflat() const;
long getrank() const;
@@ -106,7 +109,7 @@ class array : public aux::array_base
}
template <class Type>
object new_(Type const& type_) const
array new_(Type const& type_) const
{
return base::new_(object(type_));
}
@@ -162,43 +165,48 @@ class array : public aux::array_base
return base::factory();
}
template <class Buffer>
object factory(Buffer const& buffer)
template <class Sequence>
object factory(Sequence const& sequence)
{
return base::factory(object(buffer));
return base::factory(object(sequence));
}
template <class Buffer, class Type>
template <class Sequence, class Typecode>
object factory(
Buffer const& buffer
, Type const& type_)
Sequence const& sequence
, Typecode const& typecode_
, bool copy = true
, bool savespace = false
)
{
return base::factory(object(buffer), object(type_));
return base::factory(object(sequence), object(typecode_), copy, savespace);
}
template <class Buffer, class Type, class Shape>
template <class Sequence, class Typecode, class Type>
object factory(
Buffer const& buffer
, Type const& type_
, Shape const& shape
, bool copy = true
, bool savespace = false)
Sequence const& sequence
, Typecode const& typecode_
, bool copy
, bool savespace
, Type const& type
)
{
return base::factory(object(buffer), object(type_), object(shape), copy, savespace);
return base::factory(object(sequence), object(typecode_), copy, savespace, object(type));
}
template <class Buffer, class Type, class Shape>
template <class Sequence, class Typecode, class Type, class Shape>
object factory(
Buffer const& buffer
, Type const& type_
, Shape const& shape
, bool copy
, bool savespace
, char typecode)
Sequence const& sequence
, Typecode const& typecode_
, bool copy
, bool savespace
, Type const& type
, Shape const& shape
)
{
return base::factory(object(buffer), object(type_), object(shape), copy, savespace, object(typecode));
return base::factory(object(sequence), object(typecode_), copy, savespace, object(type), object(shape));
}
# define BOOST_PYTHON_ENUM_AS_OBJECT(z, n, x) object(BOOST_PP_CAT(x,n))
# define BOOST_PP_LOCAL_MACRO(n) \
template <BOOST_PP_ENUM_PARAMS_Z(1, n, class T)> \
@@ -210,6 +218,7 @@ class array : public aux::array_base
# undef BOOST_PYTHON_AS_OBJECT
static BOOST_PYTHON_DECL void set_module_and_type(char const* package_name = 0, char const* type_attribute_name = 0);
static BOOST_PYTHON_DECL std::string get_module_name();
public: // implementation detail -- for internal use only
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(array, base);