Go to the documentation of this file.
13 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
14 static_assert(__GNUC__ > 5,
"Eigen Tensor support in pybind11 requires GCC > 5.0");
21 #if defined(__MINGW32__)
25 #include <unsupported/Eigen/CXX11/Tensor>
30 "Eigen Tensor support in pybind11 requires Eigen >= 3.3.0");
44 static_assert((
static_cast<int>(T::Layout) ==
static_cast<int>(
Eigen::RowMajor))
46 "Layout must be row or column major");
54 template <
typename Scalar_,
int NumIndices_,
int Options_,
typename IndexType>
60 return f.dimensions();
71 template <
size_t... Is>
76 static constexpr
auto dimensions_descriptor
77 = helper<decltype(make_index_sequence<Type::NumIndices>())>::
value;
79 template <
typename... Args>
81 return new Type(std::forward<Args>(
args)...);
84 static void free(
Type *tensor) {
delete tensor; }
87 template <
typename Scalar_,
typename std::ptrdiff_t...
Indices,
int Options_,
typename IndexType>
89 Eigen::TensorFixedSize<Scalar_, Eigen::Sizes<Indices...>, Options_, IndexType>> {
104 return get_shape() == shape;
107 static constexpr
auto dimensions_descriptor
110 template <
typename... Args>
123 template <
typename Type,
bool ShowDetails,
bool NeedsWriteable = false>
126 = const_name<NeedsWriteable>(
", flags.writeable",
"")
127 + const_name<static_cast<int>(Type::Layout) ==
static_cast<int>(
Eigen::RowMajor)>(
128 ", flags.c_contiguous",
", flags.f_contiguous");
129 static constexpr
auto value
140 PYBIND11_WARNING_PUSH
143 template <typename
T,
int size>
147 for (
size_t i = 0;
i <
size;
i++) {
154 template <
typename T,
int size>
157 const T *shape =
arr.shape();
158 for (
size_t i = 0;
i <
size;
i++) {
167 template <
typename Type>
177 if (!isinstance<array>(src)) {
185 if (!temp.
dtype().is(dtype::of<typename Type::Scalar>())) {
191 reinterpret_borrow<object>(src));
193 if (
arr.ndim() != Type::NumIndices) {
196 auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(
arr);
198 if (!Helper::is_correct_shape(shape)) {
202 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
203 auto data_pointer =
arr.data();
221 pybind11_fail(
"Cannot use a reference return value policy for an rvalue");
229 pybind11_fail(
"Cannot use a reference return value policy for an rvalue");
239 return cast_impl(&src, policy, parent);
247 return cast(&src, policy, parent);
256 return cast_impl(src, policy, parent);
265 return cast_impl(src, policy, parent);
268 template <
typename C>
270 object parent_object;
271 bool writeable =
false;
278 src = Helper::alloc(std::move(*src));
281 =
capsule(src, [](
void *ptr) { Helper::free(
reinterpret_cast<Type *
>(ptr)); });
289 Helper::free(
const_cast<Type *
>(src));
294 =
capsule(src, [](
void *ptr) { Helper::free(
reinterpret_cast<Type *
>(ptr)); });
303 parent_object =
none();
310 pybind11_fail(
"Cannot use reference internal when there is no parent");
312 parent_object = reinterpret_borrow<object>(parent);
317 pybind11_fail(
"pybind11 bug in eigen.h, please file a bug report");
331 template <
typename StoragePointerType,
332 bool needs_writeable,
335 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
336 return reinterpret_cast<StoragePointerType
>(
arr.data());
339 return reinterpret_cast<StoragePointerType
>(
const_cast<void *
>(
arr.data()));
343 template <
typename StoragePointerType,
344 bool needs_writeable,
347 return reinterpret_cast<StoragePointerType
>(
arr.mutable_data());
350 template <
typename T,
typename =
void>
353 template <
typename MapType>
355 using SPT =
typename MapType::StoragePointerType;
358 template <
typename MapType>
360 using SPT =
typename MapType::PointerArgType;
363 template <
typename Type,
int Options>
373 if (!isinstance<array>(src)) {
376 auto arr = reinterpret_borrow<array>(src);
377 if ((
arr.flags() & compute_array_flag_from_tensor<Type>()) == 0) {
381 if (!
arr.dtype().is(dtype::of<typename Type::Scalar>())) {
385 if (
arr.ndim() != Type::NumIndices) {
395 auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(
arr);
397 if (!Helper::is_correct_shape(shape)) {
401 if (needs_writeable && !
arr.writeable()) {
405 auto result = get_array_data_for_type<typename get_storage_pointer_type<MapType>::SPT,
406 needs_writeable>(
arr);
414 return cast_impl(&src, policy, parent);
418 return cast_impl(&src, policy, parent);
426 return cast_impl(&src, policy, parent);
434 return cast(&src, policy, parent);
443 return cast_impl(src, policy, parent);
452 return cast_impl(src, policy, parent);
455 template <
typename C>
457 object parent_object;
461 parent_object =
none();
467 pybind11_fail(
"Cannot use reference internal when there is no parent");
469 parent_object = reinterpret_borrow<object>(parent);
477 pybind11_fail(
"Invalid return_value_policy for Eigen Map type, must be either "
478 "reference or reference_internal");
484 std::move(parent_object));
493 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
495 static constexpr
bool needs_writeable = !std::is_const<
typename std::remove_pointer<
512 template <
typename T_>
static handle cast(const MapType &&src, return_value_policy policy, handle parent)
static bool is_correct_shape(const Eigen::DSizes< typename Type::Index, Type::NumIndices > &shape)
Namespace containing all symbols from the Eigen library.
Annotation for function names.
typename MapType::PointerArgType SPT
#define PYBIND11_WARNING_DISABLE_GCC(name)
constexpr descr< N - 1 > const_name(char const (&text)[N])
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
void deallocate(pointer p, size_type)
typename void_t_impl< Ts... >::type void_t
static constexpr auto value
static handle cast_impl(C *src, return_value_policy policy, handle parent)
PYBIND11_WARNING_PUSH PYBIND11_WARNING_POP
#define PYBIND11_NAMESPACE_END(name)
#define PYBIND11_NAMESPACE_BEGIN(name)
static constexpr Eigen::DSizes< typename Type::Index, Type::NumIndices > get_shape(const Type &)
static void free(Type *tensor)
static handle cast(const itype &src, return_value_policy policy, handle parent)
StoragePointerType get_array_data_for_type(array &arr)
STL compatible allocator to use with types requiring a non standrad alignment.
constexpr int compute_array_flag_from_tensor()
::pybind11::detail::movable_cast_op_type< T_ > cast_op_type
bool load(handle src, bool convert)
static handle cast(Type &src, return_value_policy policy, handle parent)
PYBIND11_WARNING_PUSH std::vector< T > convert_dsizes_to_vector(const Eigen::DSizes< T, size > &arr)
bool load(handle src, bool)
bool is_tensor_aligned(const void *data)
static handle cast(const MapType &src, return_value_policy policy, handle parent)
static void free(Type *tensor)
static handle cast(MapType *src, return_value_policy policy, handle parent)
A tensor expression mapping an existing array of data.
static handle cast(Type &&src, return_value_policy policy, handle parent)
static handle cast(MapType &&src, return_value_policy policy, handle parent)
static constexpr auto details
std::unique_ptr< MapType > value
typename MapType::StoragePointerType SPT
A small structure to hold a non zero as a triplet (i,j,value).
constexpr descr< 0 > concat()
static Type * alloc(Args &&...args)
static handle cast(const MapType *src, return_value_policy policy, handle parent)
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
static Eigen::DSizes< typename Type::Index, Type::NumIndices > get_shape(const Type &f)
static handle cast(const Type *src, return_value_policy policy, handle parent)
Eigen::DSizes< T, size > get_shape_for_array(const array &arr)
#define PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
#define PYBIND11_TYPE_CASTER(type, py_name)
static Type * alloc(Args &&...args)
Matrix< Scalar, Dynamic, Dynamic > C
PYBIND11_WARNING_PUSH PYBIND11_WARNING_DISABLE_MSVC(5054) PYBIND11_WARNING_POP static_assert(EIGEN_VERSION_AT_LEAST(3
pybind11::dtype dtype() const
Array descriptor (dtype)
static handle cast(Type *src, return_value_policy policy, handle parent)
static array ensure(handle h, int ExtraFlags=0)
static handle cast(const Type &src, return_value_policy policy, handle parent)
static handle cast(MapType &src, return_value_policy policy, handle parent)
The fixed sized version of the tensor class.
static constexpr bool is_correct_shape(const Eigen::DSizes< typename Type::Index, Type::NumIndices > &)
static constexpr Eigen::DSizes< typename Type::Index, Type::NumIndices > get_shape()
static handle cast_impl(C *src, return_value_policy policy, handle parent)
static handle cast(const Type &&src, return_value_policy policy, handle parent)
pointer allocate(size_type num, const void *=0)
std::vector< size_t > Indices
#define EIGEN_VERSION_AT_LEAST(x, y, z)
static BinaryMeasurement< Rot3 > convert(const BetweenFactor< Pose3 >::shared_ptr &f)
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Map< MatrixType > MapType
PyArray_Proxy * array_proxy(void *ptr)
gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:04:12