os/ossrv/ossrv_pub/boost_apis/boost/python/numeric.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/numeric.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,241 @@
     1.4 +// Copyright David Abrahams 2002.
     1.5 +// Distributed under the Boost Software License, Version 1.0. (See
     1.6 +// accompanying file LICENSE_1_0.txt or copy at
     1.7 +// http://www.boost.org/LICENSE_1_0.txt)
     1.8 +#ifndef NUMARRAY_DWA2002922_HPP
     1.9 +# define NUMARRAY_DWA2002922_HPP
    1.10 +
    1.11 +# include <boost/python/detail/prefix.hpp>
    1.12 +
    1.13 +# include <boost/python/tuple.hpp>
    1.14 +# include <boost/python/str.hpp>
    1.15 +# include <boost/preprocessor/iteration/local.hpp>
    1.16 +# include <boost/preprocessor/cat.hpp>
    1.17 +# include <boost/preprocessor/repetition/enum.hpp>
    1.18 +# include <boost/preprocessor/repetition/enum_params.hpp>
    1.19 +# include <boost/preprocessor/repetition/enum_binary_params.hpp>
    1.20 +
    1.21 +namespace boost { namespace python { namespace numeric {
    1.22 +
    1.23 +class array;
    1.24 +
    1.25 +namespace aux
    1.26 +{
    1.27 +  struct BOOST_PYTHON_DECL array_base : object
    1.28 +  {
    1.29 +# define BOOST_PP_LOCAL_MACRO(n)                                \
    1.30 +      array_base(BOOST_PP_ENUM_PARAMS_Z(1, n, object const& x));
    1.31 +# define BOOST_PP_LOCAL_LIMITS (1, 7)
    1.32 +# include BOOST_PP_LOCAL_ITERATE()
    1.33 +
    1.34 +      object argmax(long axis=-1);
    1.35 +      object argmin(long axis=-1);
    1.36 +      object argsort(long axis=-1);
    1.37 +      object astype(object const& type = object());
    1.38 +      void byteswap();
    1.39 +      object copy() const;
    1.40 +      object diagonal(long offset = 0, long axis1 = 0, long axis2 = 1) const;
    1.41 +      void info() const;
    1.42 +      bool is_c_array() const;
    1.43 +      bool isbyteswapped() const;
    1.44 +      array new_(object type) const;
    1.45 +      void sort();
    1.46 +      object trace(long offset = 0, long axis1 = 0, long axis2 = 1) const;
    1.47 +      object type() const;
    1.48 +      char typecode() const;
    1.49 +
    1.50 +      object factory(
    1.51 +          object const& sequence = object()
    1.52 +        , object const& typecode = object()
    1.53 +        , bool copy = true
    1.54 +        , bool savespace = false
    1.55 +        , object type = object()
    1.56 +        , object shape = object());
    1.57 +
    1.58 +      object getflat() const;
    1.59 +      long getrank() const;
    1.60 +      object getshape() const;
    1.61 +      bool isaligned() const;
    1.62 +      bool iscontiguous() const;
    1.63 +      long itemsize() const;
    1.64 +      long nelements() const;
    1.65 +      object nonzero() const;
    1.66 +   
    1.67 +      void put(object const& indices, object const& values);
    1.68 +   
    1.69 +      void ravel();
    1.70 +   
    1.71 +      object repeat(object const& repeats, long axis=0);
    1.72 +   
    1.73 +      void resize(object const& shape);
    1.74 +      
    1.75 +      void setflat(object const& flat);
    1.76 +      void setshape(object const& shape);
    1.77 +   
    1.78 +      void swapaxes(long axis1, long axis2);
    1.79 +   
    1.80 +      object take(object const& sequence, long axis = 0) const;
    1.81 +   
    1.82 +      void tofile(object const& file) const;
    1.83 +   
    1.84 +      str tostring() const;
    1.85 +   
    1.86 +      void transpose(object const& axes = object());
    1.87 +   
    1.88 +      object view() const;
    1.89 +
    1.90 +   public: // implementation detail - do not touch.
    1.91 +      BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(array_base, object);
    1.92 +  };
    1.93 +
    1.94 +  struct BOOST_PYTHON_DECL array_object_manager_traits
    1.95 +  {
    1.96 +      static bool check(PyObject* obj);
    1.97 +      static detail::new_non_null_reference adopt(PyObject* obj);
    1.98 +  };
    1.99 +} // namespace aux
   1.100 +
   1.101 +class array : public aux::array_base
   1.102 +{
   1.103 +    typedef aux::array_base base;
   1.104 + public:
   1.105 +
   1.106 +    object astype() { return base::astype(); }
   1.107 +    
   1.108 +    template <class Type>
   1.109 +    object astype(Type const& type_)
   1.110 +    {
   1.111 +        return base::astype(object(type_));
   1.112 +    }
   1.113 +
   1.114 +    template <class Type>
   1.115 +    array new_(Type const& type_) const
   1.116 +    {
   1.117 +        return base::new_(object(type_));
   1.118 +    }
   1.119 +
   1.120 +    template <class Sequence>
   1.121 +    void resize(Sequence const& x)
   1.122 +    {
   1.123 +        base::resize(object(x));
   1.124 +    }
   1.125 +    
   1.126 +# define BOOST_PP_LOCAL_MACRO(n)                                \
   1.127 +      void resize(BOOST_PP_ENUM_PARAMS_Z(1, n, long x))              \
   1.128 +      {                                                         \
   1.129 +          resize(make_tuple(BOOST_PP_ENUM_PARAMS_Z(1, n, x)));       \
   1.130 +      }
   1.131 +# define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY)
   1.132 +# include BOOST_PP_LOCAL_ITERATE()
   1.133 +
   1.134 +    template <class Sequence>
   1.135 +    void setshape(Sequence const& x)
   1.136 +    {
   1.137 +        base::setshape(object(x));
   1.138 +    }
   1.139 +    
   1.140 +# define BOOST_PP_LOCAL_MACRO(n)                                \
   1.141 +    void setshape(BOOST_PP_ENUM_PARAMS_Z(1, n, long x))              \
   1.142 +    {                                                           \
   1.143 +        setshape(make_tuple(BOOST_PP_ENUM_PARAMS_Z(1, n, x)));       \
   1.144 +    }
   1.145 +# define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY)
   1.146 +# include BOOST_PP_LOCAL_ITERATE()
   1.147 +
   1.148 +    template <class Indices, class Values>
   1.149 +    void put(Indices const& indices, Values const& values)
   1.150 +    {
   1.151 +        base::put(object(indices), object(values));
   1.152 +    }
   1.153 +    
   1.154 +    template <class Sequence>
   1.155 +    object take(Sequence const& sequence, long axis = 0)
   1.156 +    {
   1.157 +        return base::take(object(sequence), axis);
   1.158 +    }
   1.159 +
   1.160 +    template <class File>
   1.161 +    void tofile(File const& f) const
   1.162 +    {
   1.163 +        base::tofile(object(f));
   1.164 +    }
   1.165 +
   1.166 +    object factory()
   1.167 +    {
   1.168 +        return base::factory();
   1.169 +    }
   1.170 +    
   1.171 +    template <class Sequence>
   1.172 +    object factory(Sequence const& sequence)
   1.173 +    {
   1.174 +        return base::factory(object(sequence));
   1.175 +    }
   1.176 +    
   1.177 +    template <class Sequence, class Typecode>
   1.178 +    object factory(
   1.179 +        Sequence const& sequence
   1.180 +      , Typecode const& typecode_
   1.181 +      , bool copy = true
   1.182 +      , bool savespace = false
   1.183 +    )
   1.184 +    {
   1.185 +        return base::factory(object(sequence), object(typecode_), copy, savespace);
   1.186 +    }
   1.187 +
   1.188 +    template <class Sequence, class Typecode, class Type>
   1.189 +    object factory(
   1.190 +        Sequence const& sequence
   1.191 +      , Typecode const& typecode_
   1.192 +      , bool copy
   1.193 +      , bool savespace
   1.194 +      , Type const& type
   1.195 +    )
   1.196 +    {
   1.197 +        return base::factory(object(sequence), object(typecode_), copy, savespace, object(type));
   1.198 +    }
   1.199 +    
   1.200 +    template <class Sequence, class Typecode, class Type, class Shape>
   1.201 +    object factory(
   1.202 +        Sequence const& sequence
   1.203 +      , Typecode const& typecode_
   1.204 +      , bool copy
   1.205 +      , bool savespace
   1.206 +      , Type const& type
   1.207 +      , Shape const& shape
   1.208 +    )
   1.209 +    {
   1.210 +        return base::factory(object(sequence), object(typecode_), copy, savespace, object(type), object(shape));
   1.211 +    }
   1.212 +    
   1.213 +# define BOOST_PYTHON_ENUM_AS_OBJECT(z, n, x) object(BOOST_PP_CAT(x,n))
   1.214 +# define BOOST_PP_LOCAL_MACRO(n)                                        \
   1.215 +    template <BOOST_PP_ENUM_PARAMS_Z(1, n, class T)>                    \
   1.216 +    explicit array(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, n, T, const& x))    \
   1.217 +    : base(BOOST_PP_ENUM_1(n, BOOST_PYTHON_ENUM_AS_OBJECT, x))          \
   1.218 +    {}
   1.219 +# define BOOST_PP_LOCAL_LIMITS (1, 7)
   1.220 +# include BOOST_PP_LOCAL_ITERATE()
   1.221 +# undef BOOST_PYTHON_AS_OBJECT
   1.222 +
   1.223 +    static BOOST_PYTHON_DECL void set_module_and_type(char const* package_name = 0, char const* type_attribute_name = 0);
   1.224 +    static BOOST_PYTHON_DECL std::string get_module_name();
   1.225 +
   1.226 + public: // implementation detail -- for internal use only
   1.227 +    BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(array, base);
   1.228 +};
   1.229 +
   1.230 +} // namespace boost::python::numeric
   1.231 +
   1.232 +namespace converter
   1.233 +{
   1.234 +  template <>
   1.235 +  struct object_manager_traits< numeric::array >
   1.236 +      : numeric::aux::array_object_manager_traits
   1.237 +  {
   1.238 +      BOOST_STATIC_CONSTANT(bool, is_specialized = true);
   1.239 +  };
   1.240 +}
   1.241 +
   1.242 +}} // namespace boost::python
   1.243 +
   1.244 +#endif // NUMARRAY_DWA2002922_HPP