tensor.h
Go to the documentation of this file.
1 /*
2  pybind11/eigen/tensor.h: Transparent conversion for Eigen tensors
3 
4  All rights reserved. Use of this source code is governed by a
5  BSD-style license that can be found in the LICENSE file.
6 */
7 
8 #pragma once
9 
10 #include <pybind11/numpy.h>
11 
12 #include "common.h"
13 
14 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
15 static_assert(__GNUC__ > 5, "Eigen Tensor support in pybind11 requires GCC > 5.0");
16 #endif
17 
18 // Disable warnings for Eigen
19 PYBIND11_WARNING_PUSH
22 #if defined(__MINGW32__)
23 PYBIND11_WARNING_DISABLE_GCC("-Wmaybe-uninitialized")
24 #endif
25 
26 #include <unsupported/Eigen/CXX11/Tensor>
27 
29 
30 static_assert(EIGEN_VERSION_AT_LEAST(3, 3, 0),
31  "Eigen Tensor support in pybind11 requires Eigen >= 3.3.0");
32 
34 
36 
38 
39 inline bool is_tensor_aligned(const void *data) {
40  return (reinterpret_cast<std::size_t>(data) % EIGEN_DEFAULT_ALIGN_BYTES) == 0;
41 }
42 
43 template <typename T>
45  static_assert((static_cast<int>(T::Layout) == static_cast<int>(Eigen::RowMajor))
46  || (static_cast<int>(T::Layout) == static_cast<int>(Eigen::ColMajor)),
47  "Layout must be row or column major");
48  return (static_cast<int>(T::Layout) == static_cast<int>(Eigen::RowMajor)) ? array::c_style
50 }
51 
52 template <typename T>
54 
55 template <typename Scalar_, int NumIndices_, int Options_, typename IndexType>
56 struct eigen_tensor_helper<Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType>> {
58  using ValidType = void;
59 
61  return f.dimensions();
62  }
63 
64  static constexpr bool
66  return true;
67  }
68 
69  template <typename T>
70  struct helper {};
71 
72  template <size_t... Is>
73  struct helper<index_sequence<Is...>> {
74  static constexpr auto value = ::pybind11::detail::concat(const_name(((void) Is, "?"))...);
75  };
76 
77  static constexpr auto dimensions_descriptor
78  = helper<decltype(make_index_sequence<Type::NumIndices>())>::value;
79 
80  template <typename... Args>
81  static Type *alloc(Args &&...args) {
82  return new Type(std::forward<Args>(args)...);
83  }
84 
85  static void free(Type *tensor) { delete tensor; }
86 };
87 
88 template <typename Scalar_, typename std::ptrdiff_t... Indices, int Options_, typename IndexType>
90  Eigen::TensorFixedSize<Scalar_, Eigen::Sizes<Indices...>, Options_, IndexType>> {
91  using Type = Eigen::TensorFixedSize<Scalar_, Eigen::Sizes<Indices...>, Options_, IndexType>;
92  using ValidType = void;
93 
95  get_shape(const Type & /*f*/) {
96  return get_shape();
97  }
98 
101  }
102 
103  static bool
105  return get_shape() == shape;
106  }
107 
108  static constexpr auto dimensions_descriptor
109  = ::pybind11::detail::concat(const_name<Indices>()...);
110 
111  template <typename... Args>
112  static Type *alloc(Args &&...args) {
114  return ::new (allocator.allocate(1)) Type(std::forward<Args>(args)...);
115  }
116 
117  static void free(Type *tensor) {
119  tensor->~Type();
120  allocator.deallocate(tensor, 1);
121  }
122 };
123 
124 template <typename Type, bool ShowDetails, bool NeedsWriteable = false>
126  static constexpr auto details
127  = const_name<NeedsWriteable>(", flags.writeable", "")
128  + const_name<static_cast<int>(Type::Layout) == static_cast<int>(Eigen::RowMajor)>(
129  ", flags.c_contiguous", ", flags.f_contiguous");
130  static constexpr auto value
132  + const_name("[") + eigen_tensor_helper<remove_cv_t<Type>>::dimensions_descriptor
133  + const_name("]") + const_name<ShowDetails>(details, const_name("")) + const_name("]");
134 };
135 
136 // When EIGEN_AVOID_STL_ARRAY is defined, Eigen::DSizes<T, 0> does not have the begin() member
137 // function. Falling back to a simple loop works around this issue.
138 //
139 // We need to disable the type-limits warning for the inner loop when size = 0.
140 
141 PYBIND11_WARNING_PUSH
142 PYBIND11_WARNING_DISABLE_GCC("-Wtype-limits")
143 
144 template <typename T, int size>
145 std::vector<T> convert_dsizes_to_vector(const Eigen::DSizes<T, size> &arr) {
146  std::vector<T> result(size);
147 
148  for (size_t i = 0; i < size; i++) {
149  result[i] = arr[i];
150  }
151 
152  return result;
153 }
154 
155 template <typename T, int size>
158  const T *shape = arr.shape();
159  for (size_t i = 0; i < size; i++) {
160  result[i] = shape[i];
161  }
162 
163  return result;
164 }
165 
167 
168 template <typename Type>
169 struct type_caster<Type, typename eigen_tensor_helper<Type>::ValidType> {
173  static constexpr auto temp_name = get_tensor_descriptor<Type, false>::value;
174  PYBIND11_TYPE_CASTER(Type, temp_name);
175 
176  bool load(handle src, bool convert) {
177  if (!convert) {
178  if (!isinstance<array>(src)) {
179  return false;
180  }
181  array temp = array::ensure(src);
182  if (!temp) {
183  return false;
184  }
185 
186  if (!temp.dtype().is(dtype::of<typename Type::Scalar>())) {
187  return false;
188  }
189  }
190 
192  reinterpret_borrow<object>(src));
193 
194  if (arr.ndim() != Type::NumIndices) {
195  return false;
196  }
197  auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(arr);
198 
199  if (!Helper::is_correct_shape(shape)) {
200  return false;
201  }
202 
203 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
204  auto data_pointer = arr.data();
205 #else
206  // Handle Eigen bug
207  auto data_pointer = const_cast<typename Type::Scalar *>(arr.data());
208 #endif
209 
210  if (is_tensor_aligned(arr.data())) {
212  } else {
213  value = Eigen::TensorMap<const Type>(data_pointer, shape);
214  }
215 
216  return true;
217  }
218 
219  static handle cast(Type &&src, return_value_policy policy, handle parent) {
220  if (policy == return_value_policy::reference
222  pybind11_fail("Cannot use a reference return value policy for an rvalue");
223  }
224  return cast_impl(&src, return_value_policy::move, parent);
225  }
226 
227  static handle cast(const Type &&src, return_value_policy policy, handle parent) {
228  if (policy == return_value_policy::reference
230  pybind11_fail("Cannot use a reference return value policy for an rvalue");
231  }
232  return cast_impl(&src, return_value_policy::move, parent);
233  }
234 
235  static handle cast(Type &src, return_value_policy policy, handle parent) {
236  if (policy == return_value_policy::automatic
238  policy = return_value_policy::copy;
239  }
240  return cast_impl(&src, policy, parent);
241  }
242 
243  static handle cast(const Type &src, return_value_policy policy, handle parent) {
244  if (policy == return_value_policy::automatic
246  policy = return_value_policy::copy;
247  }
248  return cast(&src, policy, parent);
249  }
250 
251  static handle cast(Type *src, return_value_policy policy, handle parent) {
252  if (policy == return_value_policy::automatic) {
254  } else if (policy == return_value_policy::automatic_reference) {
256  }
257  return cast_impl(src, policy, parent);
258  }
259 
260  static handle cast(const Type *src, return_value_policy policy, handle parent) {
261  if (policy == return_value_policy::automatic) {
263  } else if (policy == return_value_policy::automatic_reference) {
265  }
266  return cast_impl(src, policy, parent);
267  }
268 
269  template <typename C>
270  static handle cast_impl(C *src, return_value_policy policy, handle parent) {
271  object parent_object;
272  bool writeable = false;
273  switch (policy) {
276  pybind11_fail("Cannot move from a constant reference");
277  }
278 
279  src = Helper::alloc(std::move(*src));
280 
281  parent_object
282  = capsule(src, [](void *ptr) { Helper::free(reinterpret_cast<Type *>(ptr)); });
283  writeable = true;
284  break;
285 
288  // This cast is ugly, and might be UB in some cases, but we don't have an
289  // alternative here as we must free that memory
290  Helper::free(const_cast<Type *>(src));
291  pybind11_fail("Cannot take ownership of a const reference");
292  }
293 
294  parent_object
295  = capsule(src, [](void *ptr) { Helper::free(reinterpret_cast<Type *>(ptr)); });
296  writeable = true;
297  break;
298 
300  writeable = true;
301  break;
302 
304  parent_object = none();
305  writeable = !std::is_const<C>::value;
306  break;
307 
309  // Default should do the right thing
310  if (!parent) {
311  pybind11_fail("Cannot use reference internal when there is no parent");
312  }
313  parent_object = reinterpret_borrow<object>(parent);
314  writeable = !std::is_const<C>::value;
315  break;
316 
317  default:
318  pybind11_fail("pybind11 bug in eigen.h, please file a bug report");
319  }
320 
322  convert_dsizes_to_vector(Helper::get_shape(*src)), src->data(), parent_object);
323 
324  if (!writeable) {
326  }
327 
328  return result.release();
329  }
330 };
331 
332 template <typename StoragePointerType,
333  bool needs_writeable,
335 StoragePointerType get_array_data_for_type(array &arr) {
336 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
337  return reinterpret_cast<StoragePointerType>(arr.data());
338 #else
339  // Handle Eigen bug
340  return reinterpret_cast<StoragePointerType>(const_cast<void *>(arr.data()));
341 #endif
342 }
343 
344 template <typename StoragePointerType,
345  bool needs_writeable,
347 StoragePointerType get_array_data_for_type(array &arr) {
348  return reinterpret_cast<StoragePointerType>(arr.mutable_data());
349 }
350 
351 template <typename T, typename = void>
353 
354 template <typename MapType>
355 struct get_storage_pointer_type<MapType, void_t<typename MapType::StoragePointerType>> {
356  using SPT = typename MapType::StoragePointerType;
357 };
358 
359 template <typename MapType>
360 struct get_storage_pointer_type<MapType, void_t<typename MapType::PointerArgType>> {
361  using SPT = typename MapType::PointerArgType;
362 };
363 
364 template <typename Type, int Options>
365 struct type_caster<Eigen::TensorMap<Type, Options>,
366  typename eigen_tensor_helper<remove_cv_t<Type>>::ValidType> {
371 
372  bool load(handle src, bool /*convert*/) {
373  // Note that we have a lot more checks here as we want to make sure to avoid copies
374  if (!isinstance<array>(src)) {
375  return false;
376  }
377  auto arr = reinterpret_borrow<array>(src);
378  if ((arr.flags() & compute_array_flag_from_tensor<Type>()) == 0) {
379  return false;
380  }
381 
382  if (!arr.dtype().is(dtype::of<typename Type::Scalar>())) {
383  return false;
384  }
385 
386  if (arr.ndim() != Type::NumIndices) {
387  return false;
388  }
389 
390  constexpr bool is_aligned = (Options & Eigen::Aligned) != 0;
391 
392  if (is_aligned && !is_tensor_aligned(arr.data())) {
393  return false;
394  }
395 
396  auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(arr);
397 
398  if (!Helper::is_correct_shape(shape)) {
399  return false;
400  }
401 
402  if (needs_writeable && !arr.writeable()) {
403  return false;
404  }
405 
406  auto result = get_array_data_for_type<typename get_storage_pointer_type<MapType>::SPT,
407  needs_writeable>(arr);
408 
409  value.reset(new MapType(std::move(result), std::move(shape)));
410 
411  return true;
412  }
413 
414  static handle cast(MapType &&src, return_value_policy policy, handle parent) {
415  return cast_impl(&src, policy, parent);
416  }
417 
418  static handle cast(const MapType &&src, return_value_policy policy, handle parent) {
419  return cast_impl(&src, policy, parent);
420  }
421 
422  static handle cast(MapType &src, return_value_policy policy, handle parent) {
423  if (policy == return_value_policy::automatic
425  policy = return_value_policy::copy;
426  }
427  return cast_impl(&src, policy, parent);
428  }
429 
430  static handle cast(const MapType &src, return_value_policy policy, handle parent) {
431  if (policy == return_value_policy::automatic
433  policy = return_value_policy::copy;
434  }
435  return cast(&src, policy, parent);
436  }
437 
438  static handle cast(MapType *src, return_value_policy policy, handle parent) {
439  if (policy == return_value_policy::automatic) {
441  } else if (policy == return_value_policy::automatic_reference) {
443  }
444  return cast_impl(src, policy, parent);
445  }
446 
447  static handle cast(const MapType *src, return_value_policy policy, handle parent) {
448  if (policy == return_value_policy::automatic) {
450  } else if (policy == return_value_policy::automatic_reference) {
452  }
453  return cast_impl(src, policy, parent);
454  }
455 
456  template <typename C>
457  static handle cast_impl(C *src, return_value_policy policy, handle parent) {
458  object parent_object;
459  constexpr bool writeable = !std::is_const<C>::value;
460  switch (policy) {
462  parent_object = none();
463  break;
464 
466  // Default should do the right thing
467  if (!parent) {
468  pybind11_fail("Cannot use reference internal when there is no parent");
469  }
470  parent_object = reinterpret_borrow<object>(parent);
471  break;
472 
473  default:
474  // move, take_ownership don't make any sense for a ref/map:
475  pybind11_fail("Invalid return_value_policy for Eigen Map type, must be either "
476  "reference or reference_internal");
477  }
478 
480  convert_dsizes_to_vector(Helper::get_shape(*src)),
481  src->data(),
482  std::move(parent_object));
483 
484  if (!writeable) {
486  }
487 
488  return result.release();
489  }
490 
491 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
492 
493  static constexpr bool needs_writeable = !std::is_const<typename std::remove_pointer<
495 #else
496  // Handle Eigen bug
497  static constexpr bool needs_writeable = !std::is_const<Type>::value;
498 #endif
499 
500 protected:
501  // TODO: Move to std::optional once std::optional has more support
502  std::unique_ptr<MapType> value;
503 
504 public:
506  explicit operator MapType *() { return value.get(); }
507  explicit operator MapType &() { return *value; }
508  explicit operator MapType &&() && { return std::move(*value); }
509 
510  template <typename T_>
511  using cast_op_type = ::pybind11::detail::movable_cast_op_type<T_>;
512 };
513 
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast
static handle cast(const MapType &&src, return_value_policy policy, handle parent)
Definition: tensor.h:418
Eigen::Tensor
The tensor class.
Definition: Tensor.h:63
return_value_policy::reference_internal
@ reference_internal
npy_api::NPY_ARRAY_WRITEABLE_
@ NPY_ARRAY_WRITEABLE_
Definition: numpy.h:222
eigen_tensor_helper< Eigen::TensorFixedSize< Scalar_, Eigen::Sizes< Indices... >, Options_, IndexType > >::is_correct_shape
static bool is_correct_shape(const Eigen::DSizes< typename Type::Index, Type::NumIndices > &shape)
Definition: tensor.h:104
common.h
return_value_policy::move
@ move
npy_format_descriptor
Definition: numpy.h:65
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
name
Annotation for function names.
Definition: attr.h:51
index_sequence
Index sequences.
Definition: wrap/pybind11/include/pybind11/detail/common.h:704
get_storage_pointer_type< MapType, void_t< typename MapType::PointerArgType > >::SPT
typename MapType::PointerArgType SPT
Definition: tensor.h:361
PYBIND11_WARNING_DISABLE_GCC
#define PYBIND11_WARNING_DISABLE_GCC(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:67
array::f_style
@ f_style
Definition: numpy.h:827
const_name
constexpr descr< N - 1 > const_name(char const (&text)[N])
Definition: descr.h:60
return_value_policy
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Definition: wrap/pybind11/include/pybind11/detail/common.h:518
Eigen::aligned_allocator::deallocate
void deallocate(pointer p, size_type)
Definition: Memory.h:919
void_t
typename void_t_impl< Ts... >::type void_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:746
type_caster_generic::value
void * value
Definition: type_caster_base.h:783
get_tensor_descriptor::value
static constexpr auto value
Definition: tensor.h:131
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast_impl
static handle cast_impl(C *src, return_value_policy policy, handle parent)
Definition: tensor.h:457
PYBIND11_WARNING_POP
PYBIND11_WARNING_PUSH PYBIND11_WARNING_POP
Definition: tensor.h:31
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
capsule
Definition: pytypes.h:1953
type
Definition: pytypes.h:1527
detail
Definition: testSerializationNonlinear.cpp:69
Eigen::RowMajor
@ RowMajor
Definition: Constants.h:321
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
eigen_tensor_helper< Eigen::TensorFixedSize< Scalar_, Eigen::Sizes< Indices... >, Options_, IndexType > >::get_shape
static constexpr Eigen::DSizes< typename Type::Index, Type::NumIndices > get_shape(const Type &)
Definition: tensor.h:95
result
Values result
Definition: OdometryOptimize.cpp:8
Eigen::DSizes
Definition: TensorDimensions.h:263
Eigen::Sizes
Definition: TensorDimensions.h:93
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
eigen_tensor_helper< Eigen::TensorFixedSize< Scalar_, Eigen::Sizes< Indices... >, Options_, IndexType > >::free
static void free(Type *tensor)
Definition: tensor.h:117
array_t
Definition: numpy.h:1159
type_caster_base::cast
static handle cast(const itype &src, return_value_policy policy, handle parent)
Definition: type_caster_base.h:1086
Type
Definition: typing.h:69
return_value_policy::automatic
@ automatic
get_array_data_for_type
StoragePointerType get_array_data_for_type(array &arr)
Definition: tensor.h:335
data
int data[]
Definition: Map_placement_new.cpp:1
Eigen::aligned_allocator
STL compatible allocator to use with types requiring a non standrad alignment.
Definition: Memory.h:878
compute_array_flag_from_tensor
constexpr int compute_array_flag_from_tensor()
Definition: tensor.h:44
handle
Definition: pytypes.h:226
type_caster
Definition: cast.h:38
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast_op_type
::pybind11::detail::movable_cast_op_type< T_ > cast_op_type
Definition: tensor.h:511
return_value_policy::copy
@ copy
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::load
bool load(handle src, bool convert)
Definition: tensor.h:176
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(Type &src, return_value_policy policy, handle parent)
Definition: tensor.h:235
convert_dsizes_to_vector
PYBIND11_WARNING_PUSH std::vector< T > convert_dsizes_to_vector(const Eigen::DSizes< T, size > &arr)
Definition: tensor.h:145
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::load
bool load(handle src, bool)
Definition: tensor.h:372
is_tensor_aligned
bool is_tensor_aligned(const void *data)
Definition: tensor.h:39
Eigen::Architecture::Type
Type
Definition: Constants.h:471
eigen_tensor_helper
Definition: tensor.h:53
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast
static handle cast(const MapType &src, return_value_policy policy, handle parent)
Definition: tensor.h:430
return_value_policy::reference
@ reference
eigen_tensor_helper< Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType > >::free
static void free(Type *tensor)
Definition: tensor.h:85
eigen_tensor_helper< Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType > >::ValidType
void ValidType
Definition: tensor.h:58
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast
static handle cast(MapType *src, return_value_policy policy, handle parent)
Definition: tensor.h:438
Eigen::TensorMap
A tensor expression mapping an existing array of data.
Definition: TensorForwardDeclarations.h:52
numpy.h
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(Type &&src, return_value_policy policy, handle parent)
Definition: tensor.h:219
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast
static handle cast(MapType &&src, return_value_policy policy, handle parent)
Definition: tensor.h:414
get_tensor_descriptor::details
static constexpr auto details
Definition: tensor.h:127
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::value
std::unique_ptr< MapType > value
Definition: tensor.h:502
get_storage_pointer_type< MapType, void_t< typename MapType::StoragePointerType > >::SPT
typename MapType::StoragePointerType SPT
Definition: tensor.h:356
PYBIND11_NAMESPACE
Definition: test_custom_type_casters.cpp:24
Eigen::Triplet
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:162
concat
constexpr descr< 0 > concat()
Definition: descr.h:139
array::c_style
@ c_style
Definition: numpy.h:826
eigen_tensor_helper< Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType > >::alloc
static Type * alloc(Args &&...args)
Definition: tensor.h:81
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast
static handle cast(const MapType *src, return_value_policy policy, handle parent)
Definition: tensor.h:447
pybind11_fail
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
Definition: wrap/pybind11/include/pybind11/detail/common.h:1045
eigen_tensor_helper< Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType > >::get_shape
static Eigen::DSizes< typename Type::Index, Type::NumIndices > get_shape(const Type &f)
Definition: tensor.h:60
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(const Type *src, return_value_policy policy, handle parent)
Definition: tensor.h:260
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:509
get_shape_for_array
Eigen::DSizes< T, size > get_shape_for_array(const array &arr)
Definition: tensor.h:156
PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED
#define PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED
Definition: wrap/pybind11/include/pybind11/eigen/common.h:7
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
PYBIND11_TYPE_CASTER
#define PYBIND11_TYPE_CASTER(type, py_name)
Definition: cast.h:87
return_value_policy::take_ownership
@ take_ownership
array
Definition: numpy.h:821
eigen_tensor_helper< Eigen::TensorFixedSize< Scalar_, Eigen::Sizes< Indices... >, Options_, IndexType > >::alloc
static Type * alloc(Args &&...args)
Definition: tensor.h:112
arr
py::array arr
Definition: test_numpy_array.cpp:77
eigen_tensor_helper< Eigen::TensorFixedSize< Scalar_, Eigen::Sizes< Indices... >, Options_, IndexType > >::ValidType
void ValidType
Definition: tensor.h:92
C
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:50
PYBIND11_WARNING_DISABLE_MSVC
PYBIND11_WARNING_PUSH PYBIND11_WARNING_DISABLE_MSVC(5054) PYBIND11_WARNING_POP static_assert(EIGEN_VERSION_AT_LEAST(3
array::dtype
pybind11::dtype dtype() const
Array descriptor (dtype)
Definition: numpy.h:922
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(Type *src, return_value_policy policy, handle parent)
Definition: tensor.h:251
array::ensure
static array ensure(handle h, int ExtraFlags=0)
Definition: numpy.h:1101
get_tensor_descriptor
Definition: tensor.h:125
std
Definition: BFloat16.h:88
args
Definition: pytypes.h:2212
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(const Type &src, return_value_policy policy, handle parent)
Definition: tensor.h:243
EIGEN_DEFAULT_ALIGN_BYTES
#define EIGEN_DEFAULT_ALIGN_BYTES
Definition: ConfigureVectorization.h:179
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::cast
static handle cast(MapType &src, return_value_policy policy, handle parent)
Definition: tensor.h:422
Eigen::TensorFixedSize
The fixed sized version of the tensor class.
Definition: TensorFixedSize.h:27
PyArray_Proxy::flags
int flags
Definition: numpy.h:128
eigen_tensor_helper< Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType > >::is_correct_shape
static constexpr bool is_correct_shape(const Eigen::DSizes< typename Type::Index, Type::NumIndices > &)
Definition: tensor.h:65
eigen_tensor_helper< Eigen::TensorFixedSize< Scalar_, Eigen::Sizes< Indices... >, Options_, IndexType > >::get_shape
static constexpr Eigen::DSizes< typename Type::Index, Type::NumIndices > get_shape()
Definition: tensor.h:99
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast_impl
static handle cast_impl(C *src, return_value_policy policy, handle parent)
Definition: tensor.h:270
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(const Type &&src, return_value_policy policy, handle parent)
Definition: tensor.h:227
Eigen::ColMajor
@ ColMajor
Definition: Constants.h:319
Eigen::aligned_allocator::allocate
pointer allocate(size_type num, const void *=0)
Definition: Memory.h:913
Indices
std::vector< size_t > Indices
Definition: testPartialPriorFactor.cpp:37
none
Definition: pytypes.h:1788
EIGEN_VERSION_AT_LEAST
#define EIGEN_VERSION_AT_LEAST(x, y, z)
Definition: Macros.h:22
return_value_policy::automatic_reference
@ automatic_reference
gtsam::convert
static BinaryMeasurement< Rot3 > convert(const BetweenFactor< Pose3 >::shared_ptr &f)
Definition: ShonanAveraging.cpp:995
get_storage_pointer_type
Definition: tensor.h:352
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: wrap/pybind11/include/pybind11/detail/common.h:673
MapType
Map< MatrixType > MapType
Definition: Tutorial_Map_using.cpp:2
test_callbacks.value
value
Definition: test_callbacks.py:162
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
array_proxy
PyArray_Proxy * array_proxy(void *ptr)
Definition: numpy.h:387
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Aligned
@ Aligned
Definition: Constants.h:240


gtsam
Author(s):
autogenerated on Thu Apr 10 2025 03:04:28