numpy-type.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2023 INRIA
3  */
4 
5 #ifndef __eigenpy_numpy_type_hpp__
6 #define __eigenpy_numpy_type_hpp__
7 
8 #include <sstream>
9 #include <stdexcept>
10 #include <typeinfo>
11 
12 #include "eigenpy/fwd.hpp"
13 #include "eigenpy/register.hpp"
15 
16 namespace eigenpy {
17 
18 template <typename Scalar>
19 bool np_type_is_convertible_into_scalar(const int np_type) {
20  if (static_cast<NPY_TYPES>(NumpyEquivalentType<Scalar>::type_code) >=
21  NPY_USERDEF)
22  return np_type == Register::getTypeCode<Scalar>();
23 
24  if (NumpyEquivalentType<Scalar>::type_code == np_type) return true;
25 
26  switch (np_type) {
27  case NPY_INT:
29  case NPY_LONG:
31  case NPY_FLOAT:
33  case NPY_CFLOAT:
35  case NPY_DOUBLE:
37  case NPY_CDOUBLE:
39  case NPY_LONGDOUBLE:
41  case NPY_CLONGDOUBLE:
43  default:
44  return false;
45  }
46 }
47 
48 struct EIGENPY_DLLAPI NumpyType {
49  static NumpyType& getInstance();
50 
51  static bp::object make(PyArrayObject* pyArray, bool copy = false);
52 
53  static bp::object make(PyObject* pyObj, bool copy = false);
54 
55  static void sharedMemory(const bool value);
56 
57  static bool sharedMemory();
58 
59  static bp::object getNumpyType();
60 
61  static const PyTypeObject* getNumpyArrayType();
62 
63  protected:
64  NumpyType();
65 
66  bp::object pyModule;
67 
68  // Numpy types
69  bp::object NumpyArrayObject;
70  PyTypeObject* NumpyArrayType;
71 
73 };
74 } // namespace eigenpy
75 
76 #endif // ifndef __eigenpy_numpy_type_hpp__
ReturnMatrix copy(const Eigen::MatrixBase< Matrix > &mat)
Definition: matrix.cpp:131
bp::object NumpyArrayObject
Definition: numpy-type.hpp:69
bool np_type_is_convertible_into_scalar(const int np_type)
Definition: numpy-type.hpp:19
PyTypeObject * NumpyArrayType
Definition: numpy-type.hpp:70
bp::object pyModule
Definition: numpy-type.hpp:66


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 2 2023 02:10:26