sl@0: // Copyright David Abrahams 2002. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef NUMARRAY_DWA2002922_HPP sl@0: # define NUMARRAY_DWA2002922_HPP sl@0: sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: namespace boost { namespace python { namespace numeric { sl@0: sl@0: class array; sl@0: sl@0: namespace aux sl@0: { sl@0: struct BOOST_PYTHON_DECL array_base : object sl@0: { sl@0: # define BOOST_PP_LOCAL_MACRO(n) \ sl@0: array_base(BOOST_PP_ENUM_PARAMS_Z(1, n, object const& x)); sl@0: # define BOOST_PP_LOCAL_LIMITS (1, 7) sl@0: # include BOOST_PP_LOCAL_ITERATE() sl@0: sl@0: object argmax(long axis=-1); sl@0: object argmin(long axis=-1); sl@0: object argsort(long axis=-1); sl@0: object astype(object const& type = object()); sl@0: void byteswap(); sl@0: object copy() const; sl@0: object diagonal(long offset = 0, long axis1 = 0, long axis2 = 1) const; sl@0: void info() const; sl@0: bool is_c_array() const; sl@0: bool isbyteswapped() const; sl@0: array new_(object type) const; sl@0: void sort(); sl@0: object trace(long offset = 0, long axis1 = 0, long axis2 = 1) const; sl@0: object type() const; sl@0: char typecode() const; sl@0: sl@0: object factory( sl@0: object const& sequence = object() sl@0: , object const& typecode = object() sl@0: , bool copy = true sl@0: , bool savespace = false sl@0: , object type = object() sl@0: , object shape = object()); sl@0: sl@0: object getflat() const; sl@0: long getrank() const; sl@0: object getshape() const; sl@0: bool isaligned() const; sl@0: bool iscontiguous() const; sl@0: long itemsize() const; sl@0: long nelements() const; sl@0: object nonzero() const; sl@0: sl@0: void put(object const& indices, object const& values); sl@0: sl@0: void ravel(); sl@0: sl@0: object repeat(object const& repeats, long axis=0); sl@0: sl@0: void resize(object const& shape); sl@0: sl@0: void setflat(object const& flat); sl@0: void setshape(object const& shape); sl@0: sl@0: void swapaxes(long axis1, long axis2); sl@0: sl@0: object take(object const& sequence, long axis = 0) const; sl@0: sl@0: void tofile(object const& file) const; sl@0: sl@0: str tostring() const; sl@0: sl@0: void transpose(object const& axes = object()); sl@0: sl@0: object view() const; sl@0: sl@0: public: // implementation detail - do not touch. sl@0: BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(array_base, object); sl@0: }; sl@0: sl@0: struct BOOST_PYTHON_DECL array_object_manager_traits sl@0: { sl@0: static bool check(PyObject* obj); sl@0: static detail::new_non_null_reference adopt(PyObject* obj); sl@0: }; sl@0: } // namespace aux sl@0: sl@0: class array : public aux::array_base sl@0: { sl@0: typedef aux::array_base base; sl@0: public: sl@0: sl@0: object astype() { return base::astype(); } sl@0: sl@0: template sl@0: object astype(Type const& type_) sl@0: { sl@0: return base::astype(object(type_)); sl@0: } sl@0: sl@0: template sl@0: array new_(Type const& type_) const sl@0: { sl@0: return base::new_(object(type_)); sl@0: } sl@0: sl@0: template sl@0: void resize(Sequence const& x) sl@0: { sl@0: base::resize(object(x)); sl@0: } sl@0: sl@0: # define BOOST_PP_LOCAL_MACRO(n) \ sl@0: void resize(BOOST_PP_ENUM_PARAMS_Z(1, n, long x)) \ sl@0: { \ sl@0: resize(make_tuple(BOOST_PP_ENUM_PARAMS_Z(1, n, x))); \ sl@0: } sl@0: # define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY) sl@0: # include BOOST_PP_LOCAL_ITERATE() sl@0: sl@0: template sl@0: void setshape(Sequence const& x) sl@0: { sl@0: base::setshape(object(x)); sl@0: } sl@0: sl@0: # define BOOST_PP_LOCAL_MACRO(n) \ sl@0: void setshape(BOOST_PP_ENUM_PARAMS_Z(1, n, long x)) \ sl@0: { \ sl@0: setshape(make_tuple(BOOST_PP_ENUM_PARAMS_Z(1, n, x))); \ sl@0: } sl@0: # define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY) sl@0: # include BOOST_PP_LOCAL_ITERATE() sl@0: sl@0: template sl@0: void put(Indices const& indices, Values const& values) sl@0: { sl@0: base::put(object(indices), object(values)); sl@0: } sl@0: sl@0: template sl@0: object take(Sequence const& sequence, long axis = 0) sl@0: { sl@0: return base::take(object(sequence), axis); sl@0: } sl@0: sl@0: template sl@0: void tofile(File const& f) const sl@0: { sl@0: base::tofile(object(f)); sl@0: } sl@0: sl@0: object factory() sl@0: { sl@0: return base::factory(); sl@0: } sl@0: sl@0: template sl@0: object factory(Sequence const& sequence) sl@0: { sl@0: return base::factory(object(sequence)); sl@0: } sl@0: sl@0: template sl@0: object factory( sl@0: Sequence const& sequence sl@0: , Typecode const& typecode_ sl@0: , bool copy = true sl@0: , bool savespace = false sl@0: ) sl@0: { sl@0: return base::factory(object(sequence), object(typecode_), copy, savespace); sl@0: } sl@0: sl@0: template sl@0: object factory( sl@0: Sequence const& sequence sl@0: , Typecode const& typecode_ sl@0: , bool copy sl@0: , bool savespace sl@0: , Type const& type sl@0: ) sl@0: { sl@0: return base::factory(object(sequence), object(typecode_), copy, savespace, object(type)); sl@0: } sl@0: sl@0: template sl@0: object factory( sl@0: Sequence const& sequence sl@0: , Typecode const& typecode_ sl@0: , bool copy sl@0: , bool savespace sl@0: , Type const& type sl@0: , Shape const& shape sl@0: ) sl@0: { sl@0: return base::factory(object(sequence), object(typecode_), copy, savespace, object(type), object(shape)); sl@0: } sl@0: sl@0: # define BOOST_PYTHON_ENUM_AS_OBJECT(z, n, x) object(BOOST_PP_CAT(x,n)) sl@0: # define BOOST_PP_LOCAL_MACRO(n) \ sl@0: template \ sl@0: explicit array(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, n, T, const& x)) \ sl@0: : base(BOOST_PP_ENUM_1(n, BOOST_PYTHON_ENUM_AS_OBJECT, x)) \ sl@0: {} sl@0: # define BOOST_PP_LOCAL_LIMITS (1, 7) sl@0: # include BOOST_PP_LOCAL_ITERATE() sl@0: # undef BOOST_PYTHON_AS_OBJECT sl@0: sl@0: static BOOST_PYTHON_DECL void set_module_and_type(char const* package_name = 0, char const* type_attribute_name = 0); sl@0: static BOOST_PYTHON_DECL std::string get_module_name(); sl@0: sl@0: public: // implementation detail -- for internal use only sl@0: BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(array, base); sl@0: }; sl@0: sl@0: } // namespace boost::python::numeric sl@0: sl@0: namespace converter sl@0: { sl@0: template <> sl@0: struct object_manager_traits< numeric::array > sl@0: : numeric::aux::array_object_manager_traits sl@0: { sl@0: BOOST_STATIC_CONSTANT(bool, is_specialized = true); sl@0: }; sl@0: } sl@0: sl@0: }} // namespace boost::python sl@0: sl@0: #endif // NUMARRAY_DWA2002922_HPP