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 =
concat(const_name<Indices>()...);
109 template <
typename... Args>
122 template <
typename Type,
bool ShowDetails,
bool NeedsWriteable = false>
125 = const_name<NeedsWriteable>(
", flags.writeable",
"")
126 + const_name<static_cast<int>(Type::Layout) ==
static_cast<int>(
Eigen::RowMajor)>(
127 ", flags.c_contiguous",
", flags.f_contiguous");
128 static constexpr
auto value
139 PYBIND11_WARNING_PUSH
142 template <typename
T,
int size>
146 for (
size_t i = 0;
i <
size;
i++) {
153 template <
typename T,
int size>
156 const T *shape =
arr.shape();
157 for (
size_t i = 0;
i <
size;
i++) {
166 template <
typename Type>
176 if (!isinstance<array>(src)) {
184 if (!temp.
dtype().is(dtype::of<typename Type::Scalar>())) {
190 reinterpret_borrow<object>(src));
192 if (
arr.ndim() != Type::NumIndices) {
195 auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(
arr);
197 if (!Helper::is_correct_shape(shape)) {
201 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
202 auto data_pointer =
arr.data();
220 pybind11_fail(
"Cannot use a reference return value policy for an rvalue");
228 pybind11_fail(
"Cannot use a reference return value policy for an rvalue");
238 return cast_impl(&src, policy, parent);
246 return cast(&src, policy, parent);
255 return cast_impl(src, policy, parent);
264 return cast_impl(src, policy, parent);
267 template <
typename C>
269 object parent_object;
270 bool writeable =
false;
277 src = Helper::alloc(std::move(*src));
280 =
capsule(src, [](
void *ptr) { Helper::free(
reinterpret_cast<Type *
>(ptr)); });
288 Helper::free(
const_cast<Type *
>(src));
293 =
capsule(src, [](
void *ptr) { Helper::free(
reinterpret_cast<Type *
>(ptr)); });
302 parent_object =
none();
309 pybind11_fail(
"Cannot use reference internal when there is no parent");
311 parent_object = reinterpret_borrow<object>(parent);
316 pybind11_fail(
"pybind11 bug in eigen.h, please file a bug report");
330 template <
typename StoragePointerType,
331 bool needs_writeable,
334 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
335 return reinterpret_cast<StoragePointerType
>(
arr.data());
338 return reinterpret_cast<StoragePointerType
>(
const_cast<void *
>(
arr.data()));
342 template <
typename StoragePointerType,
343 bool needs_writeable,
346 return reinterpret_cast<StoragePointerType
>(
arr.mutable_data());
349 template <
typename T,
typename =
void>
352 template <
typename MapType>
354 using SPT =
typename MapType::StoragePointerType;
357 template <
typename MapType>
359 using SPT =
typename MapType::PointerArgType;
362 template <
typename Type,
int Options>
372 if (!isinstance<array>(src)) {
375 auto arr = reinterpret_borrow<array>(src);
376 if ((
arr.flags() & compute_array_flag_from_tensor<Type>()) == 0) {
380 if (!
arr.dtype().is(dtype::of<typename Type::Scalar>())) {
384 if (
arr.ndim() != Type::NumIndices) {
394 auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(
arr);
396 if (!Helper::is_correct_shape(shape)) {
400 if (needs_writeable && !
arr.writeable()) {
404 auto result = get_array_data_for_type<typename get_storage_pointer_type<MapType>::SPT,
405 needs_writeable>(
arr);
413 return cast_impl(&src, policy, parent);
417 return cast_impl(&src, policy, parent);
425 return cast_impl(&src, policy, parent);
433 return cast(&src, policy, parent);
442 return cast_impl(src, policy, parent);
451 return cast_impl(src, policy, parent);
454 template <
typename C>
456 object parent_object;
460 parent_object =
none();
466 pybind11_fail(
"Cannot use reference internal when there is no parent");
468 parent_object = reinterpret_borrow<object>(parent);
476 pybind11_fail(
"Invalid return_value_policy for Eigen Map type, must be either "
477 "reference or reference_internal");
483 std::move(parent_object));
492 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
494 static constexpr
bool needs_writeable = !std::is_const<
typename std::remove_pointer<
511 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 Jun 13 2024 03:07:07