47 #ifndef _MIRA_TOOLBOXES_PYTHON_EIGENHELPERS_H_ 48 #define _MIRA_TOOLBOXES_PYTHON_EIGENHELPERS_H_ 57 #if BOOST_VERSION >= 106500 58 #define TYPE_WITH_ALIGNMENT boost::python::detail::type_with_alignment 59 #define ALIGNMENT_OF boost::python::detail::alignment_of 61 #define IS_CLASS boost::python::detail::is_class 62 #define IS_UNION boost::python::detail::is_union 64 #define TYPE_WITH_ALIGNMENT type_with_alignment 65 #define ALIGNMENT_OF ::boost::alignment_of 67 #define IS_CLASS is_class 68 #define IS_UNION is_union 73 #if PY_VERSION_HEX >= 0x03090000 74 #define SET_SIZE(DEST, SRC) Py_SET_SIZE(DEST, SRC) 76 #define SET_SIZE(DEST, SRC) Py_SIZE(DEST) = SRC 83 #if BOOST_VERSION >= 107700 84 #define INSTANCE_STORAGE_ADDRESS &instance->storage.bytes 86 #define INSTANCE_STORAGE_ADDRESS &instance->storage 91 #define BOOST_PYTHON_ALIGN(DataType, Name) \ 92 typedef boost::python::objects::value_holder<DataType> Name##Holder; \ 93 namespace boost { namespace python { namespace objects { \ 95 struct instance<Name##Holder> \ 97 typedef Name##Holder Data; \ 100 PyObject* weakrefs; \ 101 instance_holder* objects; \ 102 typedef typename TYPE_WITH_ALIGNMENT< \ 103 ALIGNMENT_OF<Data>::value \ 108 char bytes[sizeof(Data) + 16]; \ 111 template<class Derived> \ 112 struct make_instance_impl<DataType, Name##Holder, Derived> \ 114 typedef DataType T; \ 115 typedef Name##Holder Holder; \ 116 typedef objects::instance<Holder> instance_t; \ 117 template <class Arg> \ 118 static inline PyObject* execute(Arg& x) \ 120 BOOST_MPL_ASSERT((mpl::or_<IS_CLASS<T>, IS_UNION<T> >)); \ 121 PyTypeObject* type = Derived::get_class_object(x); \ 123 return python::detail::none(); \ 124 PyObject* raw_result = type->tp_alloc( \ 125 type, objects::additional_instance_size<Holder>::value); \ 126 if (raw_result != 0) \ 128 python::detail::decref_guard protect(raw_result); \ 129 instance_t* instance = (instance_t*)raw_result; \ 130 Holder* holder = Derived::construct( \ 131 INSTANCE_STORAGE_ADDRESS, (PyObject*)instance, x); \ 132 holder->install(raw_result); \ 133 size_t holder_offset = reinterpret_cast<size_t>(holder) \ 134 - reinterpret_cast<size_t>(INSTANCE_STORAGE_ADDRESS) \ 135 + offsetof(instance_t, storage); \ 136 SET_SIZE(instance, holder_offset); \ 143 struct make_instance<DataType, Name##Holder> \ 144 : make_instance_impl<DataType, Name##Holder, make_instance<DataType,Name##Holder> > \ 146 typedef DataType T; \ 147 typedef Name##Holder Holder; \ 149 static inline PyTypeObject* get_class_object(U&) \ 151 return converter::registered<T>::converters.get_class_object(); \ 153 static inline Holder* construct(void* storage, PyObject* instance, reference_wrapper<T const> x) \ 155 void* aligned_storage = reinterpret_cast<void*>( \ 156 (reinterpret_cast<size_t>(storage) & ~(size_t(15))) + 16); \ 157 Holder* new_holder = new (aligned_storage) Holder(instance, x); \ 182 template<
typename Derived>
185 static std::string
str(
const Derived& m) {
189 static int rows(
const Derived& m) {
194 template<
typename Derived>
197 static typename Derived::Scalar
get(
const Derived& m,
int row,
int col) {
201 static void set(Derived& m,
int row,
int col,
202 typename Derived::Scalar value) {
206 static int cols(
const Derived& m) {
211 template<
typename Derived>
213 static typename Derived::Scalar
get(
const Derived& m,
int row) {
217 static void set(Derived& m,
int row,
218 typename Derived::Scalar value) {
243 static Eigen::VectorXf
Zero(
int rows)
245 return Eigen::VectorXf::Zero(rows);
252 static Eigen::MatrixXf
Zero(
int rows,
int cols)
254 return Eigen::MatrixXf::Zero(rows, cols);
263 static void expose(
const std::string& name)
265 using namespace boost::python;
267 class_<M>(name.c_str(), init<>())
Quaternion< float > Quaternionf
static Eigen::VectorXf Zero(int rows)
Definition: EigenHelpers.h:243
ZeroMatrix serves 2 purposes:
Definition: EigenHelpers.h:232
Definition: EigenHelpers.h:183
Definition: EigenHelpers.h:195
#define MIRA_PYTHONCONNECTOR_NAMED_TYPE_FOOTER(type, name)
static M Zero()
Definition: EigenHelpers.h:234
Definition: EigenHelpers.h:212
std::string toString(const T &value, int precision=-1)
static std::string str(const Derived &m)
Definition: EigenHelpers.h:185
Definition: EigenHelpers.h:261
static void expose(const std::string &name)
Definition: EigenHelpers.h:263
static Eigen::MatrixXf Zero(int rows, int cols)
Definition: EigenHelpers.h:252
static int cols(const Derived &m)
Definition: EigenHelpers.h:206
Python wrapper for MIRA units.
#define BOOST_PYTHON_ALIGN(DataType, Name)
Definition: EigenHelpers.h:91
static int rows(const Derived &m)
Definition: EigenHelpers.h:189