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 = ::pybind11::detail::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
108  = ::pybind11::detail::concat(const_name<Indices>()...);
109 
110  template <typename... Args>
111  static Type *alloc(Args &&...args) {
113  return ::new (allocator.allocate(1)) Type(std::forward<Args>(args)...);
114  }
115 
116  static void free(Type *tensor) {
118  tensor->~Type();
119  allocator.deallocate(tensor, 1);
120  }
121 };
122 
123 template <typename Type, bool ShowDetails, bool NeedsWriteable = false>
125  static constexpr auto details
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
131  + const_name("[") + eigen_tensor_helper<remove_cv_t<Type>>::dimensions_descriptor
132  + const_name("]") + const_name<ShowDetails>(details, const_name("")) + const_name("]");
133 };
134 
135 // When EIGEN_AVOID_STL_ARRAY is defined, Eigen::DSizes<T, 0> does not have the begin() member
136 // function. Falling back to a simple loop works around this issue.
137 //
138 // We need to disable the type-limits warning for the inner loop when size = 0.
139 
140 PYBIND11_WARNING_PUSH
141 PYBIND11_WARNING_DISABLE_GCC("-Wtype-limits")
142 
143 template <typename T, int size>
144 std::vector<T> convert_dsizes_to_vector(const Eigen::DSizes<T, size> &arr) {
145  std::vector<T> result(size);
146 
147  for (size_t i = 0; i < size; i++) {
148  result[i] = arr[i];
149  }
150 
151  return result;
152 }
153 
154 template <typename T, int size>
157  const T *shape = arr.shape();
158  for (size_t i = 0; i < size; i++) {
159  result[i] = shape[i];
160  }
161 
162  return result;
163 }
164 
166 
167 template <typename Type>
168 struct type_caster<Type, typename eigen_tensor_helper<Type>::ValidType> {
172  static constexpr auto temp_name = get_tensor_descriptor<Type, false>::value;
173  PYBIND11_TYPE_CASTER(Type, temp_name);
174 
175  bool load(handle src, bool convert) {
176  if (!convert) {
177  if (!isinstance<array>(src)) {
178  return false;
179  }
180  array temp = array::ensure(src);
181  if (!temp) {
182  return false;
183  }
184 
185  if (!temp.dtype().is(dtype::of<typename Type::Scalar>())) {
186  return false;
187  }
188  }
189 
191  reinterpret_borrow<object>(src));
192 
193  if (arr.ndim() != Type::NumIndices) {
194  return false;
195  }
196  auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(arr);
197 
198  if (!Helper::is_correct_shape(shape)) {
199  return false;
200  }
201 
202 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
203  auto data_pointer = arr.data();
204 #else
205  // Handle Eigen bug
206  auto data_pointer = const_cast<typename Type::Scalar *>(arr.data());
207 #endif
208 
209  if (is_tensor_aligned(arr.data())) {
211  } else {
212  value = Eigen::TensorMap<const Type>(data_pointer, shape);
213  }
214 
215  return true;
216  }
217 
218  static handle cast(Type &&src, return_value_policy policy, handle parent) {
219  if (policy == return_value_policy::reference
221  pybind11_fail("Cannot use a reference return value policy for an rvalue");
222  }
223  return cast_impl(&src, return_value_policy::move, parent);
224  }
225 
226  static handle cast(const Type &&src, return_value_policy policy, handle parent) {
227  if (policy == return_value_policy::reference
229  pybind11_fail("Cannot use a reference return value policy for an rvalue");
230  }
231  return cast_impl(&src, return_value_policy::move, parent);
232  }
233 
234  static handle cast(Type &src, return_value_policy policy, handle parent) {
235  if (policy == return_value_policy::automatic
237  policy = return_value_policy::copy;
238  }
239  return cast_impl(&src, policy, parent);
240  }
241 
242  static handle cast(const Type &src, return_value_policy policy, handle parent) {
243  if (policy == return_value_policy::automatic
245  policy = return_value_policy::copy;
246  }
247  return cast(&src, policy, parent);
248  }
249 
250  static handle cast(Type *src, return_value_policy policy, handle parent) {
251  if (policy == return_value_policy::automatic) {
253  } else if (policy == return_value_policy::automatic_reference) {
255  }
256  return cast_impl(src, policy, parent);
257  }
258 
259  static handle cast(const Type *src, return_value_policy policy, handle parent) {
260  if (policy == return_value_policy::automatic) {
262  } else if (policy == return_value_policy::automatic_reference) {
264  }
265  return cast_impl(src, policy, parent);
266  }
267 
268  template <typename C>
269  static handle cast_impl(C *src, return_value_policy policy, handle parent) {
270  object parent_object;
271  bool writeable = false;
272  switch (policy) {
275  pybind11_fail("Cannot move from a constant reference");
276  }
277 
278  src = Helper::alloc(std::move(*src));
279 
280  parent_object
281  = capsule(src, [](void *ptr) { Helper::free(reinterpret_cast<Type *>(ptr)); });
282  writeable = true;
283  break;
284 
287  // This cast is ugly, and might be UB in some cases, but we don't have an
288  // alternative here as we must free that memory
289  Helper::free(const_cast<Type *>(src));
290  pybind11_fail("Cannot take ownership of a const reference");
291  }
292 
293  parent_object
294  = capsule(src, [](void *ptr) { Helper::free(reinterpret_cast<Type *>(ptr)); });
295  writeable = true;
296  break;
297 
299  writeable = true;
300  break;
301 
303  parent_object = none();
304  writeable = !std::is_const<C>::value;
305  break;
306 
308  // Default should do the right thing
309  if (!parent) {
310  pybind11_fail("Cannot use reference internal when there is no parent");
311  }
312  parent_object = reinterpret_borrow<object>(parent);
313  writeable = !std::is_const<C>::value;
314  break;
315 
316  default:
317  pybind11_fail("pybind11 bug in eigen.h, please file a bug report");
318  }
319 
321  convert_dsizes_to_vector(Helper::get_shape(*src)), src->data(), parent_object);
322 
323  if (!writeable) {
325  }
326 
327  return result.release();
328  }
329 };
330 
331 template <typename StoragePointerType,
332  bool needs_writeable,
334 StoragePointerType get_array_data_for_type(array &arr) {
335 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
336  return reinterpret_cast<StoragePointerType>(arr.data());
337 #else
338  // Handle Eigen bug
339  return reinterpret_cast<StoragePointerType>(const_cast<void *>(arr.data()));
340 #endif
341 }
342 
343 template <typename StoragePointerType,
344  bool needs_writeable,
346 StoragePointerType get_array_data_for_type(array &arr) {
347  return reinterpret_cast<StoragePointerType>(arr.mutable_data());
348 }
349 
350 template <typename T, typename = void>
352 
353 template <typename MapType>
354 struct get_storage_pointer_type<MapType, void_t<typename MapType::StoragePointerType>> {
355  using SPT = typename MapType::StoragePointerType;
356 };
357 
358 template <typename MapType>
359 struct get_storage_pointer_type<MapType, void_t<typename MapType::PointerArgType>> {
360  using SPT = typename MapType::PointerArgType;
361 };
362 
363 template <typename Type, int Options>
364 struct type_caster<Eigen::TensorMap<Type, Options>,
365  typename eigen_tensor_helper<remove_cv_t<Type>>::ValidType> {
370 
371  bool load(handle src, bool /*convert*/) {
372  // Note that we have a lot more checks here as we want to make sure to avoid copies
373  if (!isinstance<array>(src)) {
374  return false;
375  }
376  auto arr = reinterpret_borrow<array>(src);
377  if ((arr.flags() & compute_array_flag_from_tensor<Type>()) == 0) {
378  return false;
379  }
380 
381  if (!arr.dtype().is(dtype::of<typename Type::Scalar>())) {
382  return false;
383  }
384 
385  if (arr.ndim() != Type::NumIndices) {
386  return false;
387  }
388 
389  constexpr bool is_aligned = (Options & Eigen::Aligned) != 0;
390 
391  if (is_aligned && !is_tensor_aligned(arr.data())) {
392  return false;
393  }
394 
395  auto shape = get_shape_for_array<typename Type::Index, Type::NumIndices>(arr);
396 
397  if (!Helper::is_correct_shape(shape)) {
398  return false;
399  }
400 
401  if (needs_writeable && !arr.writeable()) {
402  return false;
403  }
404 
405  auto result = get_array_data_for_type<typename get_storage_pointer_type<MapType>::SPT,
406  needs_writeable>(arr);
407 
408  value.reset(new MapType(std::move(result), std::move(shape)));
409 
410  return true;
411  }
412 
413  static handle cast(MapType &&src, return_value_policy policy, handle parent) {
414  return cast_impl(&src, policy, parent);
415  }
416 
417  static handle cast(const MapType &&src, return_value_policy policy, handle parent) {
418  return cast_impl(&src, policy, parent);
419  }
420 
421  static handle cast(MapType &src, return_value_policy policy, handle parent) {
422  if (policy == return_value_policy::automatic
424  policy = return_value_policy::copy;
425  }
426  return cast_impl(&src, policy, parent);
427  }
428 
429  static handle cast(const MapType &src, return_value_policy policy, handle parent) {
430  if (policy == return_value_policy::automatic
432  policy = return_value_policy::copy;
433  }
434  return cast(&src, policy, parent);
435  }
436 
437  static handle cast(MapType *src, return_value_policy policy, handle parent) {
438  if (policy == return_value_policy::automatic) {
440  } else if (policy == return_value_policy::automatic_reference) {
442  }
443  return cast_impl(src, policy, parent);
444  }
445 
446  static handle cast(const MapType *src, return_value_policy policy, handle parent) {
447  if (policy == return_value_policy::automatic) {
449  } else if (policy == return_value_policy::automatic_reference) {
451  }
452  return cast_impl(src, policy, parent);
453  }
454 
455  template <typename C>
456  static handle cast_impl(C *src, return_value_policy policy, handle parent) {
457  object parent_object;
458  constexpr bool writeable = !std::is_const<C>::value;
459  switch (policy) {
461  parent_object = none();
462  break;
463 
465  // Default should do the right thing
466  if (!parent) {
467  pybind11_fail("Cannot use reference internal when there is no parent");
468  }
469  parent_object = reinterpret_borrow<object>(parent);
470  break;
471 
473  delete src;
474  // fallthrough
475  default:
476  // move, take_ownership don't make any sense for a ref/map:
477  pybind11_fail("Invalid return_value_policy for Eigen Map type, must be either "
478  "reference or reference_internal");
479  }
480 
482  convert_dsizes_to_vector(Helper::get_shape(*src)),
483  src->data(),
484  std::move(parent_object));
485 
486  if (!writeable) {
488  }
489 
490  return result.release();
491  }
492 
493 #if EIGEN_VERSION_AT_LEAST(3, 4, 0)
494 
495  static constexpr bool needs_writeable = !std::is_const<typename std::remove_pointer<
497 #else
498  // Handle Eigen bug
499  static constexpr bool needs_writeable = !std::is_const<Type>::value;
500 #endif
501 
502 protected:
503  // TODO: Move to std::optional once std::optional has more support
504  std::unique_ptr<MapType> value;
505 
506 public:
508  explicit operator MapType *() { return value.get(); }
509  explicit operator MapType &() { return *value; }
510  explicit operator MapType &&() && { return std::move(*value); }
511 
512  template <typename T_>
513  using cast_op_type = ::pybind11::detail::movable_cast_op_type<T_>;
514 };
515 
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:417
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:103
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:685
get_storage_pointer_type< MapType, void_t< typename MapType::PointerArgType > >::SPT
typename MapType::PointerArgType SPT
Definition: tensor.h:360
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:499
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:727
type_caster_generic::value
void * value
Definition: type_caster_base.h:828
get_tensor_descriptor::value
static constexpr auto value
Definition: tensor.h:130
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:456
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:1951
type
Definition: pytypes.h:1525
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:116
array_t
Definition: numpy.h:1155
type_caster_base::cast
static handle cast(const itype &src, return_value_policy policy, handle parent)
Definition: type_caster_base.h:1105
Type
Definition: typing.h:67
return_value_policy::automatic
@ automatic
get_array_data_for_type
StoragePointerType get_array_data_for_type(array &arr)
Definition: tensor.h:334
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: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:513
return_value_policy::copy
@ copy
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::load
bool load(handle src, bool convert)
Definition: tensor.h:175
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(Type &src, return_value_policy policy, handle parent)
Definition: tensor.h:234
convert_dsizes_to_vector
PYBIND11_WARNING_PUSH std::vector< T > convert_dsizes_to_vector(const Eigen::DSizes< T, size > &arr)
Definition: tensor.h:144
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::load
bool load(handle src, bool)
Definition: tensor.h:371
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
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:429
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:437
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:218
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:413
get_tensor_descriptor::details
static constexpr auto details
Definition: tensor.h:126
type_caster< Eigen::TensorMap< Type, Options >, typename eigen_tensor_helper< remove_cv_t< Type > >::ValidType >::value
std::unique_ptr< MapType > value
Definition: tensor.h:504
get_storage_pointer_type< MapType, void_t< typename MapType::StoragePointerType > >::SPT
typename MapType::StoragePointerType SPT
Definition: tensor.h:355
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: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:446
pybind11_fail
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
Definition: wrap/pybind11/include/pybind11/detail/common.h:1026
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:259
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
get_shape_for_array
Eigen::DSizes< T, size > get_shape_for_array(const array &arr)
Definition: tensor.h:155
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:111
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:918
type_caster< Type, typename eigen_tensor_helper< Type >::ValidType >::cast
static handle cast(Type *src, return_value_policy policy, handle parent)
Definition: tensor.h:250
array::ensure
static array ensure(handle h, int ExtraFlags=0)
Definition: numpy.h:1097
get_tensor_descriptor
Definition: tensor.h:124
std
Definition: BFloat16.h:88
args
Definition: pytypes.h:2210
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:242
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:421
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: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:269
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:226
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:1786
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:994
get_storage_pointer_type
Definition: tensor.h:351
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:654
MapType
Map< MatrixType > MapType
Definition: Tutorial_Map_using.cpp:2
test_callbacks.value
value
Definition: test_callbacks.py:160
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 Dec 19 2024 04:04:12