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 "../numpy.h"
11 #include "common.h"
12 
13 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
14 static_assert(__GNUC__ > 5, "Eigen Tensor support in pybind11 requires GCC > 5.0");
15 #endif
16 
17 // Disable warnings for Eigen
18 PYBIND11_WARNING_PUSH
21 #if defined(__MINGW32__)
22 PYBIND11_WARNING_DISABLE_GCC("-Wmaybe-uninitialized")
23 #endif
24 
25 #include <unsupported/Eigen/CXX11/Tensor>
26 
28 
29 static_assert(EIGEN_VERSION_AT_LEAST(3, 3, 0),
30  "Eigen Tensor support in pybind11 requires Eigen >= 3.3.0");
31 
33 
35 
37 
38 inline bool is_tensor_aligned(const void *data) {
39  return (reinterpret_cast<std::size_t>(data) % EIGEN_DEFAULT_ALIGN_BYTES) == 0;
40 }
41 
42 template <typename T>
44  static_assert((static_cast<int>(T::Layout) == static_cast<int>(Eigen::RowMajor))
45  || (static_cast<int>(T::Layout) == static_cast<int>(Eigen::ColMajor)),
46  "Layout must be row or column major");
47  return (static_cast<int>(T::Layout) == static_cast<int>(Eigen::RowMajor)) ? array::c_style
49 }
50 
51 template <typename T>
53 
54 template <typename Scalar_, int NumIndices_, int Options_, typename IndexType>
55 struct eigen_tensor_helper<Eigen::Tensor<Scalar_, NumIndices_, Options_, IndexType>> {
57  using ValidType = void;
58 
60  return f.dimensions();
61  }
62 
63  static constexpr bool
65  return true;
66  }
67 
68  template <typename T>
69  struct helper {};
70 
71  template <size_t... Is>
72  struct helper<index_sequence<Is...>> {
73  static constexpr auto value = concat(const_name(((void) Is, "?"))...);
74  };
75 
76  static constexpr auto dimensions_descriptor
77  = helper<decltype(make_index_sequence<Type::NumIndices>())>::value;
78 
79  template <typename... Args>
80  static Type *alloc(Args &&...args) {
81  return new Type(std::forward<Args>(args)...);
82  }
83 
84  static void free(Type *tensor) { delete tensor; }
85 };
86 
87 template <typename Scalar_, typename std::ptrdiff_t... Indices, int Options_, typename IndexType>
89  Eigen::TensorFixedSize<Scalar_, Eigen::Sizes<Indices...>, Options_, IndexType>> {
90  using Type = Eigen::TensorFixedSize<Scalar_, Eigen::Sizes<Indices...>, Options_, IndexType>;
91  using ValidType = void;
92 
94  get_shape(const Type & /*f*/) {
95  return get_shape();
96  }
97 
100  }
101 
102  static bool
104  return get_shape() == shape;
105  }
106 
107  static constexpr auto dimensions_descriptor = concat(const_name<Indices>()...);
108 
109  template <typename... Args>
110  static Type *alloc(Args &&...args) {
112  return ::new (allocator.allocate(1)) Type(std::forward<Args>(args)...);
113  }
114 
115  static void free(Type *tensor) {
117  tensor->~Type();
118  allocator.deallocate(tensor, 1);
119  }
120 };
121 
122 template <typename Type, bool ShowDetails, bool NeedsWriteable = false>
124  static constexpr auto details
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
130  + const_name("[") + eigen_tensor_helper<remove_cv_t<Type>>::dimensions_descriptor
131  + const_name("]") + const_name<ShowDetails>(details, const_name("")) + const_name("]");
132 };
133 
134 // When EIGEN_AVOID_STL_ARRAY is defined, Eigen::DSizes<T, 0> does not have the begin() member
135 // function. Falling back to a simple loop works around this issue.
136 //
137 // We need to disable the type-limits warning for the inner loop when size = 0.
138 
139 PYBIND11_WARNING_PUSH
140 PYBIND11_WARNING_DISABLE_GCC("-Wtype-limits")
141 
142 template <typename T, int size>
143 std::vector<T> convert_dsizes_to_vector(const Eigen::DSizes<T, size> &arr) {
144  std::vector<T> result(size);
145 
146  for (size_t i = 0; i < size; i++) {
147  result[i] = arr[i];
148  }
149 
150  return result;
151 }
152 
153 template <typename T, int size>
156  const T *shape = arr.shape();
157  for (size_t i = 0; i < size; i++) {
158  result[i] = shape[i];
159  }
160 
161  return result;
162 }
163 
165 
166 template <typename Type>
167 struct type_caster<Type, typename eigen_tensor_helper<Type>::ValidType> {
171  static constexpr auto temp_name = get_tensor_descriptor<Type, false>::value;
172  PYBIND11_TYPE_CASTER(Type, temp_name);
173 
174  bool load(handle src, bool convert) {
175  if (!convert) {
176  if (!isinstance<array>(src)) {
177  return false;
178  }
179  array temp = array::ensure(src);
180  if (!temp) {
181  return false;
182  }
183 
184  if (!temp.dtype().is(dtype::of<typename Type::Scalar>())) {
185  return false;
186  }
187  }
188 
190  reinterpret_borrow<object>(src));
191 
192  if (arr.ndim() != Type::NumIndices) {
193  return false;
194  }
195  auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(arr);
196 
197  if (!Helper::is_correct_shape(shape)) {
198  return false;
199  }
200 
201 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
202  auto data_pointer = arr.data();
203 #else
204  // Handle Eigen bug
205  auto data_pointer = const_cast<typename Type::Scalar *>(arr.data());
206 #endif
207 
208  if (is_tensor_aligned(arr.data())) {
210  } else {
211  value = Eigen::TensorMap<const Type>(data_pointer, shape);
212  }
213 
214  return true;
215  }
216 
217  static handle cast(Type &&src, return_value_policy policy, handle parent) {
218  if (policy == return_value_policy::reference
220  pybind11_fail("Cannot use a reference return value policy for an rvalue");
221  }
222  return cast_impl(&src, return_value_policy::move, parent);
223  }
224 
225  static handle cast(const Type &&src, return_value_policy policy, handle parent) {
226  if (policy == return_value_policy::reference
228  pybind11_fail("Cannot use a reference return value policy for an rvalue");
229  }
230  return cast_impl(&src, return_value_policy::move, parent);
231  }
232 
233  static handle cast(Type &src, return_value_policy policy, handle parent) {
234  if (policy == return_value_policy::automatic
236  policy = return_value_policy::copy;
237  }
238  return cast_impl(&src, policy, parent);
239  }
240 
241  static handle cast(const Type &src, return_value_policy policy, handle parent) {
242  if (policy == return_value_policy::automatic
244  policy = return_value_policy::copy;
245  }
246  return cast(&src, policy, parent);
247  }
248 
249  static handle cast(Type *src, return_value_policy policy, handle parent) {
250  if (policy == return_value_policy::automatic) {
252  } else if (policy == return_value_policy::automatic_reference) {
254  }
255  return cast_impl(src, policy, parent);
256  }
257 
258  static handle cast(const Type *src, return_value_policy policy, handle parent) {
259  if (policy == return_value_policy::automatic) {
261  } else if (policy == return_value_policy::automatic_reference) {
263  }
264  return cast_impl(src, policy, parent);
265  }
266 
267  template <typename C>
268  static handle cast_impl(C *src, return_value_policy policy, handle parent) {
269  object parent_object;
270  bool writeable = false;
271  switch (policy) {
274  pybind11_fail("Cannot move from a constant reference");
275  }
276 
277  src = Helper::alloc(std::move(*src));
278 
279  parent_object
280  = capsule(src, [](void *ptr) { Helper::free(reinterpret_cast<Type *>(ptr)); });
281  writeable = true;
282  break;
283 
286  // This cast is ugly, and might be UB in some cases, but we don't have an
287  // alternative here as we must free that memory
288  Helper::free(const_cast<Type *>(src));
289  pybind11_fail("Cannot take ownership of a const reference");
290  }
291 
292  parent_object
293  = capsule(src, [](void *ptr) { Helper::free(reinterpret_cast<Type *>(ptr)); });
294  writeable = true;
295  break;
296 
298  writeable = true;
299  break;
300 
302  parent_object = none();
303  writeable = !std::is_const<C>::value;
304  break;
305 
307  // Default should do the right thing
308  if (!parent) {
309  pybind11_fail("Cannot use reference internal when there is no parent");
310  }
311  parent_object = reinterpret_borrow<object>(parent);
312  writeable = !std::is_const<C>::value;
313  break;
314 
315  default:
316  pybind11_fail("pybind11 bug in eigen.h, please file a bug report");
317  }
318 
320  convert_dsizes_to_vector(Helper::get_shape(*src)), src->data(), parent_object);
321 
322  if (!writeable) {
324  }
325 
326  return result.release();
327  }
328 };
329 
330 template <typename StoragePointerType,
331  bool needs_writeable,
333 StoragePointerType get_array_data_for_type(array &arr) {
334 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
335  return reinterpret_cast<StoragePointerType>(arr.data());
336 #else
337  // Handle Eigen bug
338  return reinterpret_cast<StoragePointerType>(const_cast<void *>(arr.data()));
339 #endif
340 }
341 
342 template <typename StoragePointerType,
343  bool needs_writeable,
345 StoragePointerType get_array_data_for_type(array &arr) {
346  return reinterpret_cast<StoragePointerType>(arr.mutable_data());
347 }
348 
349 template <typename T, typename = void>
351 
352 template <typename MapType>
353 struct get_storage_pointer_type<MapType, void_t<typename MapType::StoragePointerType>> {
354  using SPT = typename MapType::StoragePointerType;
355 };
356 
357 template <typename MapType>
358 struct get_storage_pointer_type<MapType, void_t<typename MapType::PointerArgType>> {
359  using SPT = typename MapType::PointerArgType;
360 };
361 
362 template <typename Type, int Options>
363 struct type_caster<Eigen::TensorMap<Type, Options>,
364  typename eigen_tensor_helper<remove_cv_t<Type>>::ValidType> {
369 
370  bool load(handle src, bool /*convert*/) {
371  // Note that we have a lot more checks here as we want to make sure to avoid copies
372  if (!isinstance<array>(src)) {
373  return false;
374  }
375  auto arr = reinterpret_borrow<array>(src);
376  if ((arr.flags() & compute_array_flag_from_tensor<Type>()) == 0) {
377  return false;
378  }
379 
380  if (!arr.dtype().is(dtype::of<typename Type::Scalar>())) {
381  return false;
382  }
383 
384  if (arr.ndim() != Type::NumIndices) {
385  return false;
386  }
387 
388  constexpr bool is_aligned = (Options & Eigen::Aligned) != 0;
389 
390  if (is_aligned && !is_tensor_aligned(arr.data())) {
391  return false;
392  }
393 
394  auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(arr);
395 
396  if (!Helper::is_correct_shape(shape)) {
397  return false;
398  }
399 
400  if (needs_writeable && !arr.writeable()) {
401  return false;
402  }
403 
404  auto result = get_array_data_for_type<typename get_storage_pointer_type<MapType>::SPT,
405  needs_writeable>(arr);
406 
407  value.reset(new MapType(std::move(result), std::move(shape)));
408 
409  return true;
410  }
411 
412  static handle cast(MapType &&src, return_value_policy policy, handle parent) {
413  return cast_impl(&src, policy, parent);
414  }
415 
416  static handle cast(const MapType &&src, return_value_policy policy, handle parent) {
417  return cast_impl(&src, policy, parent);
418  }
419 
420  static handle cast(MapType &src, return_value_policy policy, handle parent) {
421  if (policy == return_value_policy::automatic
423  policy = return_value_policy::copy;
424  }
425  return cast_impl(&src, policy, parent);
426  }
427 
428  static handle cast(const MapType &src, return_value_policy policy, handle parent) {
429  if (policy == return_value_policy::automatic
431  policy = return_value_policy::copy;
432  }
433  return cast(&src, policy, parent);
434  }
435 
436  static handle cast(MapType *src, return_value_policy policy, handle parent) {
437  if (policy == return_value_policy::automatic) {
439  } else if (policy == return_value_policy::automatic_reference) {
441  }
442  return cast_impl(src, policy, parent);
443  }
444 
445  static handle cast(const MapType *src, return_value_policy policy, handle parent) {
446  if (policy == return_value_policy::automatic) {
448  } else if (policy == return_value_policy::automatic_reference) {
450  }
451  return cast_impl(src, policy, parent);
452  }
453 
454  template <typename C>
455  static handle cast_impl(C *src, return_value_policy policy, handle parent) {
456  object parent_object;
457  constexpr bool writeable = !std::is_const<C>::value;
458  switch (policy) {
460  parent_object = none();
461  break;
462 
464  // Default should do the right thing
465  if (!parent) {
466  pybind11_fail("Cannot use reference internal when there is no parent");
467  }
468  parent_object = reinterpret_borrow<object>(parent);
469  break;
470 
472  delete src;
473  // fallthrough
474  default:
475  // move, take_ownership don't make any sense for a ref/map:
476  pybind11_fail("Invalid return_value_policy for Eigen Map type, must be either "
477  "reference or reference_internal");
478  }
479 
481  convert_dsizes_to_vector(Helper::get_shape(*src)),
482  src->data(),
483  std::move(parent_object));
484 
485  if (!writeable) {
487  }
488 
489  return result.release();
490  }
491 
492 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
493 
494  static constexpr bool needs_writeable = !std::is_const<typename std::remove_pointer<
496 #else
497  // Handle Eigen bug
498  static constexpr bool needs_writeable = !std::is_const<Type>::value;
499 #endif
500 
501 protected:
502  // TODO: Move to std::optional once std::optional has more support
503  std::unique_ptr<MapType> value;
504 
505 public:
507  explicit operator MapType *() { return value.get(); }
508  explicit operator MapType &() { return *value; }
509  explicit operator MapType &&() && { return std::move(*value); }
510 
511  template <typename T_>
512  using cast_op_type = ::pybind11::detail::movable_cast_op_type<T_>;
513 };
514 
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:416
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:148
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:103
common.h
return_value_policy::move
@ move
npy_format_descriptor
Definition: numpy.h:51
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:671
get_storage_pointer_type< MapType, void_t< typename MapType::PointerArgType > >::SPT
typename MapType::PointerArgType SPT
Definition: tensor.h:359
PYBIND11_WARNING_DISABLE_GCC
#define PYBIND11_WARNING_DISABLE_GCC(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:67
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:485
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:713
type_caster_generic::value
void * value
Definition: type_caster_base.h:795
get_tensor_descriptor::value
static constexpr auto value
Definition: tensor.h:129
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:455
PYBIND11_WARNING_POP
PYBIND11_WARNING_PUSH PYBIND11_WARNING_POP
Definition: tensor.h:30
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
capsule
Definition: pytypes.h:1909
type
Definition: pytypes.h:1491
detail
Definition: testSerializationNonlinear.cpp:70
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:94
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:115
array_t
Definition: numpy.h:1020
type_caster_base::cast
static handle cast(const itype &src, return_value_policy policy, handle parent)
Definition: type_caster_base.h:1072
return_value_policy::automatic
@ automatic
get_array_data_for_type
StoragePointerType get_array_data_for_type(array &arr)
Definition: tensor.h:333
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:43
handle
Definition: pytypes.h:217
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:512
return_value_policy::copy
@ copy
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::load
bool load(handle src, bool convert)
Definition: tensor.h:174
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(Type &src, return_value_policy policy, handle parent)
Definition: tensor.h:233
convert_dsizes_to_vector
PYBIND11_WARNING_PUSH std::vector< T > convert_dsizes_to_vector(const Eigen::DSizes< T, size > &arr)
Definition: tensor.h:143
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::load
bool load(handle src, bool)
Definition: tensor.h:370
is_tensor_aligned
bool is_tensor_aligned(const void *data)
Definition: tensor.h:38
Eigen::Architecture::Type
Type
Definition: Constants.h:471
eigen_tensor_helper
Definition: tensor.h:52
array::f_style
@ f_style
Definition: numpy.h:690
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:428
return_value_policy::reference
@ reference
eigen_tensor_helper< Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType > >::free
static void free(Type *tensor)
Definition: tensor.h:84
eigen_tensor_helper< Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType > >::ValidType
void ValidType
Definition: tensor.h:57
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:436
Eigen::TensorMap
A tensor expression mapping an existing array of data.
Definition: TensorForwardDeclarations.h:52
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(Type &&src, return_value_policy policy, handle parent)
Definition: tensor.h:217
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:412
get_tensor_descriptor::details
static constexpr auto details
Definition: tensor.h:125
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::value
std::unique_ptr< MapType > value
Definition: tensor.h:503
get_storage_pointer_type< MapType, void_t< typename MapType::StoragePointerType > >::SPT
typename MapType::StoragePointerType SPT
Definition: tensor.h:354
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
eigen_tensor_helper< Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType > >::alloc
static Type * alloc(Args &&...args)
Definition: tensor.h:80
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:445
pybind11_fail
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
Definition: wrap/pybind11/include/pybind11/detail/common.h:1013
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:59
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:258
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:476
get_shape_for_array
Eigen::DSizes< T, size > get_shape_for_array(const array &arr)
Definition: tensor.h:154
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:85
return_value_policy::take_ownership
@ take_ownership
array
Definition: numpy.h:684
eigen_tensor_helper< Eigen::TensorFixedSize< Scalar_, Eigen::Sizes< Indices... >, Options_, IndexType > >::alloc
static Type * alloc(Args &&...args)
Definition: tensor.h:110
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:91
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:781
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(Type *src, return_value_policy policy, handle parent)
Definition: tensor.h:249
array::ensure
static array ensure(handle h, int ExtraFlags=0)
Definition: numpy.h:962
get_tensor_descriptor
Definition: tensor.h:123
std
Definition: BFloat16.h:88
array::c_style
@ c_style
Definition: numpy.h:689
args
Definition: pytypes.h:2163
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:241
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:420
Eigen::TensorFixedSize
The fixed sized version of the tensor class.
Definition: TensorFixedSize.h:27
PyArray_Proxy::flags
int flags
Definition: numpy.h:76
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:64
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:98
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:268
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:225
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:1744
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:998
get_storage_pointer_type
Definition: tensor.h:350
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:640
MapType
Map< MatrixType > MapType
Definition: Tutorial_Map_using.cpp:2
test_callbacks.value
value
Definition: test_callbacks.py:158
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
array_proxy
PyArray_Proxy * array_proxy(void *ptr)
Definition: numpy.h:299
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Aligned
@ Aligned
Definition: Constants.h:240


gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:07:07