5#ifndef __eigenpy_tensor_eigen_from_python_hpp__ 6#define __eigenpy_tensor_eigen_from_python_hpp__ 8#include "eigenpy/fwd.hpp" 9#include "eigenpy/eigen-allocator.hpp" 10#include "eigenpy/numpy-type.hpp" 11#include "eigenpy/scalar-conversion.hpp" 15template <
typename TensorType>
17 static PyTypeObject
const *get_pytype() {
18 PyTypeObject
const *py_type = eigenpy::getPyArrayType();
29template <
typename Scalar,
int Rank,
int Options,
typename IndexType>
30struct expected_pytype_for_arg<Eigen::Tensor<Scalar, Rank, Options, IndexType>>
32 Eigen::Tensor<Scalar, Rank, Options, IndexType>> {};
34template <
typename Scalar,
int Rank,
int Options,
typename IndexType>
35struct rvalue_from_python_data<
36 Eigen::Tensor<Scalar, Rank, Options, IndexType> const &>
38 Eigen::Tensor<Scalar, Rank, Options, IndexType> const &> {
39 typedef Eigen::Tensor<Scalar, Rank, Options, IndexType> T;
40 EIGENPY_RVALUE_FROM_PYTHON_DATA_INIT(T
const &)
43template <
typename Derived>
44struct rvalue_from_python_data<Eigen::TensorBase<Derived> const &>
46 EIGENPY_RVALUE_FROM_PYTHON_DATA_INIT(Derived
const &)
56template <
typename TensorType>
57struct referent_storage<Eigen::TensorRef<TensorType> &> {
58 typedef Eigen::TensorRef<TensorType> RefType;
59 typedef ::eigenpy::details::referent_storage_eigen_ref<RefType> StorageType;
60 typedef typename ::eigenpy::aligned_storage<
61 referent_size<StorageType &>::value>::type type;
64template <
typename TensorType>
65struct referent_storage<const Eigen::TensorRef<const TensorType> &> {
66 typedef Eigen::TensorRef<const TensorType> RefType;
67 typedef ::eigenpy::details::referent_storage_eigen_ref<RefType> StorageType;
68 typedef typename ::eigenpy::aligned_storage<
69 referent_size<StorageType &>::value>::type type;
77template <
typename TensorType>
79 typedef typename TensorType::Scalar Scalar;
86 bp::converter::rvalue_from_python_stage1_data *memory);
88 static void registration();
91template <
typename TensorType>
95 if (!call_PyArray_Check(
reinterpret_cast<PyObject *
>(pyObj)))
return 0;
97 typedef typename Eigen::internal::traits<TensorType>::Index Index;
98 static const Index NumIndices = TensorType::NumIndices;
100 PyArrayObject *pyArray =
reinterpret_cast<PyArrayObject *
>(pyObj);
102 if (!np_type_is_convertible_into_scalar<Scalar>(
103 EIGENPY_GET_PY_ARRAY_TYPE(pyArray)))
106 if (!(PyArray_NDIM(pyArray) == NumIndices || NumIndices == Eigen::Dynamic))
109#ifdef NPY_1_8_API_VERSION 110 if (!(PyArray_FLAGS(pyArray)))
112 if (!(PyArray_FLAGS(pyArray) & NPY_ALIGNED))
121template <
typename TensorType>
123 PyObject *pyObj, bp::converter::rvalue_from_python_stage1_data *memory) {
124 eigen_from_py_construct<TensorType>(pyObj, memory);
127template <
typename TensorType>
129 Eigen::TensorBase<TensorType>>::registration() {
130 bp::converter::registry::push_back(
133#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
140template <
typename TensorType>
142 static void registration() {
143 EigenFromPy<TensorType>::registration();
146 typedef Eigen::TensorBase<TensorType> TensorBase;
147 EigenFromPy<TensorBase>::registration();
150 typedef Eigen::TensorRef<TensorType> RefType;
151 EigenFromPy<RefType>::registration();
154 typedef const Eigen::TensorRef<const TensorType> ConstRefType;
155 EigenFromPy<ConstRefType>::registration();
159template <
typename TensorType>
162 typedef Eigen::TensorBase<TensorType> Base;
164 static void registration() {
165 bp::converter::registry::push_back(
168#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
176template <
typename TensorType>
178 typedef Eigen::TensorRef<TensorType> RefType;
179 typedef typename TensorType::Scalar Scalar;
183 if (!call_PyArray_Check(pyObj))
return 0;
184 PyArrayObject *pyArray =
reinterpret_cast<PyArrayObject *
>(pyObj);
185 if (!PyArray_ISWRITEABLE(pyArray))
return 0;
189 static void registration() {
190 bp::converter::registry::push_back(
192 &eigen_from_py_construct<RefType>, bp::type_id<RefType>()
193#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
201template <
typename TensorType>
203 typedef const Eigen::TensorRef<const TensorType> ConstRefType;
204 typedef typename TensorType::Scalar Scalar;
211 static void registration() {
212 bp::converter::registry::push_back(
214 &eigen_from_py_construct<ConstRefType>, bp::type_id<ConstRefType>()
215#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
static void * convertible(PyObject *pyObj)
Determine if pyObj can be converted into a MatType object.
static void * convertible(PyObject *pyObj)
Determine if pyObj can be converted into a MatType object.
static void construct(PyObject *pyObj, bp::converter::rvalue_from_python_stage1_data *memory)
Allocate memory and copy pyObj in the new storage.
static void * convertible(PyObject *pyObj)
Determine if pyObj can be converted into a MatType object.
static void construct(PyObject *pyObj, bp::converter::rvalue_from_python_stage1_data *memory)
Allocate memory and copy pyObj in the new storage.
static void * convertible(PyObject *pyObj)
Determine if pyObj can be converted into a MatType object.