os/ossrv/ossrv_pub/boost_apis/boost/python/numeric.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright David Abrahams 2002.
sl@0
     2
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     3
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     4
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
#ifndef NUMARRAY_DWA2002922_HPP
sl@0
     6
# define NUMARRAY_DWA2002922_HPP
sl@0
     7
sl@0
     8
# include <boost/python/detail/prefix.hpp>
sl@0
     9
sl@0
    10
# include <boost/python/tuple.hpp>
sl@0
    11
# include <boost/python/str.hpp>
sl@0
    12
# include <boost/preprocessor/iteration/local.hpp>
sl@0
    13
# include <boost/preprocessor/cat.hpp>
sl@0
    14
# include <boost/preprocessor/repetition/enum.hpp>
sl@0
    15
# include <boost/preprocessor/repetition/enum_params.hpp>
sl@0
    16
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
sl@0
    17
sl@0
    18
namespace boost { namespace python { namespace numeric {
sl@0
    19
sl@0
    20
class array;
sl@0
    21
sl@0
    22
namespace aux
sl@0
    23
{
sl@0
    24
  struct BOOST_PYTHON_DECL array_base : object
sl@0
    25
  {
sl@0
    26
# define BOOST_PP_LOCAL_MACRO(n)                                \
sl@0
    27
      array_base(BOOST_PP_ENUM_PARAMS_Z(1, n, object const& x));
sl@0
    28
# define BOOST_PP_LOCAL_LIMITS (1, 7)
sl@0
    29
# include BOOST_PP_LOCAL_ITERATE()
sl@0
    30
sl@0
    31
      object argmax(long axis=-1);
sl@0
    32
      object argmin(long axis=-1);
sl@0
    33
      object argsort(long axis=-1);
sl@0
    34
      object astype(object const& type = object());
sl@0
    35
      void byteswap();
sl@0
    36
      object copy() const;
sl@0
    37
      object diagonal(long offset = 0, long axis1 = 0, long axis2 = 1) const;
sl@0
    38
      void info() const;
sl@0
    39
      bool is_c_array() const;
sl@0
    40
      bool isbyteswapped() const;
sl@0
    41
      array new_(object type) const;
sl@0
    42
      void sort();
sl@0
    43
      object trace(long offset = 0, long axis1 = 0, long axis2 = 1) const;
sl@0
    44
      object type() const;
sl@0
    45
      char typecode() const;
sl@0
    46
sl@0
    47
      object factory(
sl@0
    48
          object const& sequence = object()
sl@0
    49
        , object const& typecode = object()
sl@0
    50
        , bool copy = true
sl@0
    51
        , bool savespace = false
sl@0
    52
        , object type = object()
sl@0
    53
        , object shape = object());
sl@0
    54
sl@0
    55
      object getflat() const;
sl@0
    56
      long getrank() const;
sl@0
    57
      object getshape() const;
sl@0
    58
      bool isaligned() const;
sl@0
    59
      bool iscontiguous() const;
sl@0
    60
      long itemsize() const;
sl@0
    61
      long nelements() const;
sl@0
    62
      object nonzero() const;
sl@0
    63
   
sl@0
    64
      void put(object const& indices, object const& values);
sl@0
    65
   
sl@0
    66
      void ravel();
sl@0
    67
   
sl@0
    68
      object repeat(object const& repeats, long axis=0);
sl@0
    69
   
sl@0
    70
      void resize(object const& shape);
sl@0
    71
      
sl@0
    72
      void setflat(object const& flat);
sl@0
    73
      void setshape(object const& shape);
sl@0
    74
   
sl@0
    75
      void swapaxes(long axis1, long axis2);
sl@0
    76
   
sl@0
    77
      object take(object const& sequence, long axis = 0) const;
sl@0
    78
   
sl@0
    79
      void tofile(object const& file) const;
sl@0
    80
   
sl@0
    81
      str tostring() const;
sl@0
    82
   
sl@0
    83
      void transpose(object const& axes = object());
sl@0
    84
   
sl@0
    85
      object view() const;
sl@0
    86
sl@0
    87
   public: // implementation detail - do not touch.
sl@0
    88
      BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(array_base, object);
sl@0
    89
  };
sl@0
    90
sl@0
    91
  struct BOOST_PYTHON_DECL array_object_manager_traits
sl@0
    92
  {
sl@0
    93
      static bool check(PyObject* obj);
sl@0
    94
      static detail::new_non_null_reference adopt(PyObject* obj);
sl@0
    95
  };
sl@0
    96
} // namespace aux
sl@0
    97
sl@0
    98
class array : public aux::array_base
sl@0
    99
{
sl@0
   100
    typedef aux::array_base base;
sl@0
   101
 public:
sl@0
   102
sl@0
   103
    object astype() { return base::astype(); }
sl@0
   104
    
sl@0
   105
    template <class Type>
sl@0
   106
    object astype(Type const& type_)
sl@0
   107
    {
sl@0
   108
        return base::astype(object(type_));
sl@0
   109
    }
sl@0
   110
sl@0
   111
    template <class Type>
sl@0
   112
    array new_(Type const& type_) const
sl@0
   113
    {
sl@0
   114
        return base::new_(object(type_));
sl@0
   115
    }
sl@0
   116
sl@0
   117
    template <class Sequence>
sl@0
   118
    void resize(Sequence const& x)
sl@0
   119
    {
sl@0
   120
        base::resize(object(x));
sl@0
   121
    }
sl@0
   122
    
sl@0
   123
# define BOOST_PP_LOCAL_MACRO(n)                                \
sl@0
   124
      void resize(BOOST_PP_ENUM_PARAMS_Z(1, n, long x))              \
sl@0
   125
      {                                                         \
sl@0
   126
          resize(make_tuple(BOOST_PP_ENUM_PARAMS_Z(1, n, x)));       \
sl@0
   127
      }
sl@0
   128
# define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY)
sl@0
   129
# include BOOST_PP_LOCAL_ITERATE()
sl@0
   130
sl@0
   131
    template <class Sequence>
sl@0
   132
    void setshape(Sequence const& x)
sl@0
   133
    {
sl@0
   134
        base::setshape(object(x));
sl@0
   135
    }
sl@0
   136
    
sl@0
   137
# define BOOST_PP_LOCAL_MACRO(n)                                \
sl@0
   138
    void setshape(BOOST_PP_ENUM_PARAMS_Z(1, n, long x))              \
sl@0
   139
    {                                                           \
sl@0
   140
        setshape(make_tuple(BOOST_PP_ENUM_PARAMS_Z(1, n, x)));       \
sl@0
   141
    }
sl@0
   142
# define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY)
sl@0
   143
# include BOOST_PP_LOCAL_ITERATE()
sl@0
   144
sl@0
   145
    template <class Indices, class Values>
sl@0
   146
    void put(Indices const& indices, Values const& values)
sl@0
   147
    {
sl@0
   148
        base::put(object(indices), object(values));
sl@0
   149
    }
sl@0
   150
    
sl@0
   151
    template <class Sequence>
sl@0
   152
    object take(Sequence const& sequence, long axis = 0)
sl@0
   153
    {
sl@0
   154
        return base::take(object(sequence), axis);
sl@0
   155
    }
sl@0
   156
sl@0
   157
    template <class File>
sl@0
   158
    void tofile(File const& f) const
sl@0
   159
    {
sl@0
   160
        base::tofile(object(f));
sl@0
   161
    }
sl@0
   162
sl@0
   163
    object factory()
sl@0
   164
    {
sl@0
   165
        return base::factory();
sl@0
   166
    }
sl@0
   167
    
sl@0
   168
    template <class Sequence>
sl@0
   169
    object factory(Sequence const& sequence)
sl@0
   170
    {
sl@0
   171
        return base::factory(object(sequence));
sl@0
   172
    }
sl@0
   173
    
sl@0
   174
    template <class Sequence, class Typecode>
sl@0
   175
    object factory(
sl@0
   176
        Sequence const& sequence
sl@0
   177
      , Typecode const& typecode_
sl@0
   178
      , bool copy = true
sl@0
   179
      , bool savespace = false
sl@0
   180
    )
sl@0
   181
    {
sl@0
   182
        return base::factory(object(sequence), object(typecode_), copy, savespace);
sl@0
   183
    }
sl@0
   184
sl@0
   185
    template <class Sequence, class Typecode, class Type>
sl@0
   186
    object factory(
sl@0
   187
        Sequence const& sequence
sl@0
   188
      , Typecode const& typecode_
sl@0
   189
      , bool copy
sl@0
   190
      , bool savespace
sl@0
   191
      , Type const& type
sl@0
   192
    )
sl@0
   193
    {
sl@0
   194
        return base::factory(object(sequence), object(typecode_), copy, savespace, object(type));
sl@0
   195
    }
sl@0
   196
    
sl@0
   197
    template <class Sequence, class Typecode, class Type, class Shape>
sl@0
   198
    object factory(
sl@0
   199
        Sequence const& sequence
sl@0
   200
      , Typecode const& typecode_
sl@0
   201
      , bool copy
sl@0
   202
      , bool savespace
sl@0
   203
      , Type const& type
sl@0
   204
      , Shape const& shape
sl@0
   205
    )
sl@0
   206
    {
sl@0
   207
        return base::factory(object(sequence), object(typecode_), copy, savespace, object(type), object(shape));
sl@0
   208
    }
sl@0
   209
    
sl@0
   210
# define BOOST_PYTHON_ENUM_AS_OBJECT(z, n, x) object(BOOST_PP_CAT(x,n))
sl@0
   211
# define BOOST_PP_LOCAL_MACRO(n)                                        \
sl@0
   212
    template <BOOST_PP_ENUM_PARAMS_Z(1, n, class T)>                    \
sl@0
   213
    explicit array(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, n, T, const& x))    \
sl@0
   214
    : base(BOOST_PP_ENUM_1(n, BOOST_PYTHON_ENUM_AS_OBJECT, x))          \
sl@0
   215
    {}
sl@0
   216
# define BOOST_PP_LOCAL_LIMITS (1, 7)
sl@0
   217
# include BOOST_PP_LOCAL_ITERATE()
sl@0
   218
# undef BOOST_PYTHON_AS_OBJECT
sl@0
   219
sl@0
   220
    static BOOST_PYTHON_DECL void set_module_and_type(char const* package_name = 0, char const* type_attribute_name = 0);
sl@0
   221
    static BOOST_PYTHON_DECL std::string get_module_name();
sl@0
   222
sl@0
   223
 public: // implementation detail -- for internal use only
sl@0
   224
    BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(array, base);
sl@0
   225
};
sl@0
   226
sl@0
   227
} // namespace boost::python::numeric
sl@0
   228
sl@0
   229
namespace converter
sl@0
   230
{
sl@0
   231
  template <>
sl@0
   232
  struct object_manager_traits< numeric::array >
sl@0
   233
      : numeric::aux::array_object_manager_traits
sl@0
   234
  {
sl@0
   235
      BOOST_STATIC_CONSTANT(bool, is_specialized = true);
sl@0
   236
  };
sl@0
   237
}
sl@0
   238
sl@0
   239
}} // namespace boost::python
sl@0
   240
sl@0
   241
#endif // NUMARRAY_DWA2002922_HPP