Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.19.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Tensor.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <algorithm>
11 #include <cstddef>
12 #include <memory>
13 #include <string>
14 #include <type_traits>
15 
16 #include "open3d/core/Blob.h"
17 #include "open3d/core/DLPack.h"
18 #include "open3d/core/Device.h"
19 #include "open3d/core/Dtype.h"
20 #include "open3d/core/Scalar.h"
21 #include "open3d/core/ShapeUtil.h"
22 #include "open3d/core/SizeVector.h"
24 #include "open3d/core/TensorInit.h"
25 #include "open3d/core/TensorKey.h"
26 
27 namespace open3d {
28 namespace core {
29 
32 class Tensor : public IsDevice {
33 public:
34  Tensor() {}
35 
37  Tensor(const SizeVector& shape,
38  Dtype dtype,
39  const Device& device = Device("CPU:0"))
40  : shape_(shape),
41  strides_(shape_util::DefaultStrides(shape)),
42  dtype_(dtype),
43  blob_(std::make_shared<Blob>(shape.NumElements() * dtype.ByteSize(),
44  device)) {
45  data_ptr_ = blob_->GetDataPtr();
46  }
47 
49  template <typename T>
50  Tensor(const std::vector<T>& init_vals,
51  const SizeVector& shape,
52  Dtype dtype,
53  const Device& device = Device("CPU:0"))
54  : Tensor(shape, dtype, device) {
55  // Check number of elements
56  if (static_cast<int64_t>(init_vals.size()) != shape_.NumElements()) {
58  "Tensor initialization values' size {} does not match the "
59  "shape {}",
60  init_vals.size(), shape_.NumElements());
61  }
62 
63  // Check data types
64  AssertTemplateDtype<T>();
65  if (!(std::is_standard_layout<T>::value && std::is_trivial<T>::value)) {
67  "Object must be a StandardLayout and TrivialType type.");
68  }
69 
70  // Copy data to blob
72  init_vals.data(),
73  init_vals.size() * dtype.ByteSize());
74  }
75 
77  template <typename T>
78  Tensor(const T* init_vals,
79  const SizeVector& shape,
80  Dtype dtype,
81  const Device& device = Device("CPU:0"))
82  : Tensor(shape, dtype, device) {
83  // Check data types
84  AssertTemplateDtype<T>();
85 
86  // Copy data to blob
88  init_vals,
89  shape_.NumElements() * dtype.ByteSize());
90  }
91 
95  Tensor(const SizeVector& shape,
96  const SizeVector& strides,
97  void* data_ptr,
98  Dtype dtype,
99  const std::shared_ptr<Blob>& blob)
100  : shape_(shape),
101  strides_(strides),
102  data_ptr_(data_ptr),
103  dtype_(dtype),
104  blob_(blob) {}
105 
116  template <typename T>
117  Tensor(std::vector<T>&& vec, const SizeVector& shape = {})
118  : shape_(shape), dtype_(Dtype::FromType<T>()) {
119  if (shape_.empty()) {
120  shape_ = {static_cast<int64_t>(vec.size())};
121  }
122 
123  // Check number of elements.
124  if (static_cast<int64_t>(vec.size()) != shape_.NumElements()) {
126  "Tensor initialization values' size {} does not match the "
127  "shape {}",
128  vec.size(), shape_.NumElements());
129  }
131  auto sp_vec = std::make_shared<std::vector<T>>();
132  sp_vec->swap(vec);
133  data_ptr_ = static_cast<void*>(sp_vec->data());
134 
135  // Create blob that owns the shared pointer to vec. The deleter function
136  // object just stores a shared pointer, ensuring that memory is freed
137  // only when the Tensor is destructed.
138  blob_ = std::make_shared<Blob>(Device("CPU:0"), data_ptr_,
139  [sp_vec](void*) { (void)sp_vec; });
140  }
141 
162  Tensor(void* data_ptr,
163  Dtype dtype,
164  const SizeVector& shape,
165  const SizeVector& strides = {},
166  const Device& device = Device("CPU:0"))
167  : shape_(shape), strides_(strides), data_ptr_(data_ptr), dtype_(dtype) {
168  if (strides_.empty()) {
170  }
171  // Blob with no-op deleter.
172  blob_ = std::make_shared<Blob>(device, (void*)data_ptr_, [](void*) {});
173  }
174 
177  Tensor(const Tensor& other) = default;
178 
181  Tensor(Tensor&& other) = default;
182 
185  Tensor& operator=(const Tensor& other) &;
186 
189  Tensor& operator=(Tensor&& other) &;
190 
193  Tensor& operator=(const Tensor& other) &&;
194 
197  Tensor& operator=(Tensor&& other) &&;
198 
204  template <typename T>
205  Tensor& operator=(const T v) && {
206  this->Fill(v);
207  return *this;
208  }
209 
214  Tensor ReinterpretCast(const core::Dtype& dtype) const;
215 
219  template <typename Object>
220  Tensor& AssignObject(const Object& v) && {
221  if (shape_.size() != 0) {
223  "Assignment with scalar only works for scalar Tensor of "
224  "shape ()");
225  }
226  AssertTemplateDtype<Object>();
228  sizeof(Object));
229  return *this;
230  }
231 
234  template <typename S>
235  void Fill(S v);
236 
237  template <typename Object>
238  void FillObject(const Object& v);
239 
241  static Tensor Empty(const SizeVector& shape,
242  Dtype dtype,
243  const Device& device = Device("CPU:0"));
244 
247  static Tensor EmptyLike(const Tensor& other) {
248  return Tensor::Empty(other.shape_, other.dtype_, other.GetDevice());
249  }
250 
252  template <typename T>
253  static Tensor Full(const SizeVector& shape,
254  T fill_value,
255  Dtype dtype,
256  const Device& device = Device("CPU:0")) {
257  Tensor t = Empty(shape, dtype, device);
258  t.Fill(fill_value);
259  return t;
260  }
261 
263  static Tensor Zeros(const SizeVector& shape,
264  Dtype dtype,
265  const Device& device = Device("CPU:0"));
266 
268  static Tensor Ones(const SizeVector& shape,
269  Dtype dtype,
270  const Device& device = Device("CPU:0"));
271 
274  template <typename T>
275  static Tensor Init(const T val, const Device& device = Device("CPU:0")) {
276  Dtype type = Dtype::FromType<T>();
277  std::vector<T> ele_list{val};
278  SizeVector shape;
279  return Tensor(ele_list, shape, type, device);
280  }
281 
284  template <typename T>
285  static Tensor Init(const std::initializer_list<T>& in_list,
286  const Device& device = Device("CPU:0")) {
287  return InitWithInitializerList<T, 1>(in_list, device);
288  }
289 
292  template <typename T>
293  static Tensor Init(
294  const std::initializer_list<std::initializer_list<T>>& in_list,
295  const Device& device = Device("CPU:0")) {
296  return InitWithInitializerList<T, 2>(in_list, device);
297  }
298 
301  template <typename T>
302  static Tensor Init(
303  const std::initializer_list<
304  std::initializer_list<std::initializer_list<T>>>& in_list,
305  const Device& device = Device("CPU:0")) {
306  return InitWithInitializerList<T, 3>(in_list, device);
307  }
308 
310  static Tensor Eye(int64_t n, Dtype dtype, const Device& device);
311 
313  static Tensor Diag(const Tensor& input);
314 
316  static Tensor Arange(const Scalar start,
317  const Scalar stop,
318  const Scalar step = 1,
319  const Dtype dtype = core::Int64,
320  const Device& device = core::Device("CPU:0"));
321 
323  Tensor Reverse() const;
324 
344  Tensor GetItem(const TensorKey& tk) const;
345 
364  Tensor GetItem(const std::vector<TensorKey>& tks) const;
365 
367  Tensor SetItem(const Tensor& value);
368 
384  Tensor SetItem(const TensorKey& tk, const Tensor& value);
385 
400  Tensor SetItem(const std::vector<TensorKey>& tks, const Tensor& value);
401 
432  Tensor Append(
433  const Tensor& other,
434  const utility::optional<int64_t>& axis = utility::nullopt) const;
435 
437  Tensor Broadcast(const SizeVector& dst_shape) const;
438 
443  Tensor Expand(const SizeVector& dst_shape) const;
444 
457  Tensor Reshape(const SizeVector& dst_shape) const;
458 
479  Tensor Flatten(int64_t start_dim = 0, int64_t end_dim = -1) const;
480 
499  Tensor View(const SizeVector& dst_shape) const;
500 
502  Tensor Clone() const { return To(GetDevice(), /*copy=*/true); }
503 
505  void CopyFrom(const Tensor& other);
506 
511  Tensor To(Dtype dtype, bool copy = false) const;
512 
517  Tensor To(const Device& device, bool copy = false) const;
518 
525  Tensor To(const Device& device, Dtype dtype, bool copy = false) const;
526 
527  std::string ToString(bool with_suffix = true,
528  const std::string& indent = "") const;
529 
531  Tensor operator[](int64_t i) const;
532 
535  Tensor IndexExtract(int64_t dim, int64_t idx) const;
536 
543  Tensor Slice(int64_t dim,
544  int64_t start,
545  int64_t stop,
546  int64_t step = 1) const;
547 
558  Tensor AsRvalue() { return *this; }
559 
561  const Tensor AsRvalue() const { return *this; }
562 
567  Tensor IndexGet(const std::vector<Tensor>& index_tensors) const;
568 
576  void IndexSet(const std::vector<Tensor>& index_tensors,
577  const Tensor& src_tensor);
578 
587  void IndexAdd_(int64_t dim, const Tensor& index, const Tensor& src);
588 
593  Tensor Permute(const SizeVector& dims) const;
594 
597  Tensor AsStrided(const SizeVector& new_shape,
598  const SizeVector& new_strides) const;
599 
604  Tensor Transpose(int64_t dim0, int64_t dim1) const;
605 
609  Tensor T() const;
610 
613  double Det() const;
614 
617  template <typename T>
618  T Item() const {
619  if (shape_.NumElements() != 1) {
621  "Tensor::Item() only works for Tensor with exactly one "
622  "element.");
623  }
624  AssertTemplateDtype<T>();
625  T value;
626  MemoryManager::MemcpyToHost(&value, data_ptr_, GetDevice(), sizeof(T));
627  return value;
628  }
629 
631  Tensor Add(const Tensor& value) const;
632  Tensor Add(Scalar value) const;
633  Tensor operator+(const Tensor& value) const { return Add(value); }
634  Tensor operator+(Scalar value) const { return Add(value); }
635 
638  Tensor Add_(const Tensor& value);
639  Tensor Add_(Scalar value);
640  Tensor operator+=(const Tensor& value) { return Add_(value); }
641  Tensor operator+=(Scalar value) { return Add_(value); }
642 
644  Tensor Sub(const Tensor& value) const;
645  Tensor Sub(Scalar value) const;
646  Tensor operator-(const Tensor& value) const { return Sub(value); }
647  Tensor operator-(Scalar value) const { return Sub(value); }
648 
651  Tensor Sub_(const Tensor& value);
652  Tensor Sub_(Scalar value);
653  Tensor operator-=(const Tensor& value) { return Sub_(value); }
654  Tensor operator-=(Scalar value) { return Sub_(value); }
655 
657  Tensor Mul(const Tensor& value) const;
658  Tensor Mul(Scalar value) const;
659  Tensor operator*(const Tensor& value) const { return Mul(value); }
660  Tensor operator*(Scalar value) const { return Mul(value); }
661 
664  Tensor Mul_(const Tensor& value);
665  Tensor Mul_(Scalar value);
666  Tensor operator*=(const Tensor& value) { return Mul_(value); }
667  Tensor operator*=(Scalar value) { return Mul_(value); }
668 
670  Tensor Div(const Tensor& value) const;
671  Tensor Div(Scalar value) const;
672  Tensor operator/(const Tensor& value) const { return Div(value); }
673  Tensor operator/(Scalar value) const { return Div(value); }
674 
677  Tensor Div_(const Tensor& value);
678  Tensor Div_(Scalar value);
679  Tensor operator/=(const Tensor& value) { return Div_(value); }
680  Tensor operator/=(Scalar value) { return Div_(value); }
681 
685  Tensor Sum(const SizeVector& dims, bool keepdim = false) const;
686 
690  Tensor Mean(const SizeVector& dims, bool keepdim = false) const;
691 
695  Tensor Prod(const SizeVector& dims, bool keepdim = false) const;
696 
700  Tensor Min(const SizeVector& dims, bool keepdim = false) const;
701 
705  Tensor Max(const SizeVector& dims, bool keepdim = false) const;
706 
715  Tensor ArgMin(const SizeVector& dims) const;
716 
725  Tensor ArgMax(const SizeVector& dims) const;
726 
728  Tensor Sqrt() const;
729 
731  Tensor Sqrt_();
732 
734  Tensor Sin() const;
735 
737  Tensor Sin_();
738 
740  Tensor Cos() const;
741 
743  Tensor Cos_();
744 
746  Tensor Neg() const;
747 
749  Tensor Neg_();
750 
752  Tensor operator-() const { return Neg(); }
753 
755  Tensor Exp() const;
756 
758  Tensor Exp_();
759 
761  Tensor Abs() const;
762 
764  Tensor Abs_();
765 
768  Tensor IsNan() const;
769 
772  Tensor IsInf() const;
773 
777  Tensor IsFinite() const;
778 
783  Tensor Clip(Scalar min_val, Scalar max_val) const;
784 
789  Tensor Clip_(Scalar min_val, Scalar max_val);
790 
792  Tensor Floor() const;
793 
795  Tensor Ceil() const;
796 
798  Tensor Round() const;
799 
801  Tensor Trunc() const;
802 
807  Tensor LogicalNot() const;
808 
816 
821  Tensor LogicalAnd(const Tensor& value) const;
822  Tensor operator&&(const Tensor& value) const { return LogicalAnd(value); }
823  Tensor LogicalAnd(Scalar value) const;
824 
831  Tensor LogicalAnd_(const Tensor& value);
832  Tensor LogicalAnd_(Scalar value);
833 
838  Tensor LogicalOr(const Tensor& value) const;
839  Tensor operator||(const Tensor& value) const { return LogicalOr(value); }
840  Tensor LogicalOr(Scalar value) const;
841 
848  Tensor LogicalOr_(const Tensor& value);
849  Tensor LogicalOr_(Scalar value);
850 
856  Tensor LogicalXor(const Tensor& value) const;
857  Tensor LogicalXor(Scalar value) const;
858 
865  Tensor LogicalXor_(const Tensor& value);
866  Tensor LogicalXor_(Scalar value);
867 
869  Tensor Gt(const Tensor& value) const;
870  Tensor operator>(const Tensor& value) const { return Gt(value); }
871  Tensor Gt(Scalar value) const;
872 
875  Tensor Gt_(const Tensor& value);
876  Tensor Gt_(Scalar value);
877 
879  Tensor Lt(const Tensor& value) const;
880  Tensor operator<(const Tensor& value) const { return Lt(value); }
881  Tensor Lt(Scalar value) const;
882 
885  Tensor Lt_(const Tensor& value);
886  Tensor Lt_(Scalar value);
887 
890  Tensor Ge(const Tensor& value) const;
891  Tensor operator>=(const Tensor& value) const { return Ge(value); }
892  Tensor Ge(Scalar value) const;
893 
896  Tensor Ge_(const Tensor& value);
897  Tensor Ge_(Scalar value);
898 
901  Tensor Le(const Tensor& value) const;
902  Tensor operator<=(const Tensor& value) const { return Le(value); }
903  Tensor Le(Scalar value) const;
904 
907  Tensor Le_(const Tensor& value);
908  Tensor Le_(Scalar value);
909 
911  Tensor Eq(const Tensor& value) const;
912  Tensor operator==(const Tensor& value) const { return Eq(value); }
913  Tensor Eq(Scalar value) const;
914 
917  Tensor Eq_(const Tensor& value);
918  Tensor Eq_(Scalar value);
919 
921  Tensor Ne(const Tensor& value) const;
922  Tensor operator!=(const Tensor& value) const { return Ne(value); }
923  Tensor Ne(Scalar value) const;
924 
927  Tensor Ne_(const Tensor& value);
928  Tensor Ne_(Scalar value);
929 
933  std::vector<Tensor> NonZeroNumpy() const;
934 
939  Tensor NonZero() const;
940 
950  bool IsNonZero() const;
951 
955  bool keepdim = false) const;
956 
960  bool keepdim = false) const;
961 
973  bool AllEqual(const Tensor& other) const;
974 
992  bool AllClose(const Tensor& other,
993  double rtol = 1e-5,
994  double atol = 1e-8) const;
995 
1014  Tensor IsClose(const Tensor& other,
1015  double rtol = 1e-5,
1016  double atol = 1e-8) const;
1017 
1021  bool IsSame(const Tensor& other) const;
1022 
1024  template <typename T>
1025  std::vector<T> ToFlatVector() const {
1026  AssertTemplateDtype<T>();
1027  std::vector<T> values(NumElements());
1029  GetDevice(),
1030  GetDtype().ByteSize() * NumElements());
1031  return values;
1032  }
1033 
1036  inline bool IsContiguous() const {
1038  }
1039 
1043  Tensor Contiguous() const;
1044 
1047  Tensor Matmul(const Tensor& rhs) const;
1048 
1051  Tensor Solve(const Tensor& rhs) const;
1052 
1055  Tensor LeastSquares(const Tensor& rhs) const;
1056 
1064  std::tuple<Tensor, Tensor, Tensor> LU(const bool permute_l = false) const;
1065 
1078  std::tuple<Tensor, Tensor> LUIpiv() const;
1079 
1089  Tensor Triu(const int diagonal = 0) const;
1090 
1100  Tensor Tril(const int diagonal = 0) const;
1101 
1113  std::tuple<Tensor, Tensor> Triul(const int diagonal = 0) const;
1114 
1117  Tensor Inverse() const;
1118 
1121  std::tuple<Tensor, Tensor, Tensor> SVD() const;
1122 
1125  inline int64_t GetLength() const { return GetShape().GetLength(); }
1126 
1127  inline SizeVector GetShape() const { return shape_; }
1128 
1129  inline const SizeVector& GetShapeRef() const { return shape_; }
1130 
1131  inline int64_t GetShape(int64_t dim) const {
1132  return shape_[shape_util::WrapDim(dim, NumDims())];
1133  }
1134 
1135  inline SizeVector GetStrides() const { return strides_; }
1136 
1137  inline const SizeVector& GetStridesRef() const { return strides_; }
1138 
1139  inline int64_t GetStride(int64_t dim) const {
1140  return strides_[shape_util::WrapDim(dim, NumDims())];
1141  }
1142 
1143  template <typename T>
1144  inline T* GetDataPtr() {
1145  return const_cast<T*>(const_cast<const Tensor*>(this)->GetDataPtr<T>());
1146  }
1147 
1148  template <typename T>
1149  inline const T* GetDataPtr() const {
1150  if (!dtype_.IsObject() && Dtype::FromType<T>() != dtype_) {
1152  "Requested values have type {} but Tensor has type {}. "
1153  "Please use non templated GetDataPtr() with manual "
1154  "casting.",
1155  Dtype::FromType<T>().ToString(), dtype_.ToString());
1156  }
1157  return static_cast<T*>(data_ptr_);
1158  }
1159 
1160  inline void* GetDataPtr() { return data_ptr_; }
1161 
1162  inline const void* GetDataPtr() const { return data_ptr_; }
1163 
1164  inline Dtype GetDtype() const { return dtype_; }
1165 
1166  Device GetDevice() const override;
1167 
1168  inline std::shared_ptr<Blob> GetBlob() const { return blob_; }
1169 
1170  inline int64_t NumElements() const { return shape_.NumElements(); }
1171 
1172  inline int64_t NumDims() const { return shape_.size(); }
1173 
1174  template <typename T>
1175  void AssertTemplateDtype() const {
1176  if (!dtype_.IsObject() && Dtype::FromType<T>() != dtype_) {
1178  "Requested values have type {} but Tensor has type {}",
1179  Dtype::FromType<T>().ToString(), dtype_.ToString());
1180  }
1181  if (dtype_.ByteSize() != sizeof(T)) {
1182  utility::LogError("Internal error: element size mismatch {} != {}",
1183  dtype_.ByteSize(), sizeof(T));
1184  }
1185  }
1186 
1188  DLManagedTensor* ToDLPack() const;
1189 
1191  static Tensor FromDLPack(const DLManagedTensor* dlmt);
1192 
1194  void Save(const std::string& file_name) const;
1195 
1197  static Tensor Load(const std::string& file_name);
1198 
1200  struct Iterator {
1201  using iterator_category = std::forward_iterator_tag;
1202  using difference_type = std::ptrdiff_t;
1205  using reference = value_type; // Typically Tensor&, but a tensor slice
1206  // creates a new Tensor object with
1207  // shared memory.
1208 
1209  // Iterator must be constructible, copy-constructible, copy-assignable,
1210  // destructible and swappable.
1211  Iterator(pointer tensor, int64_t index);
1212  Iterator(const Iterator&);
1213  ~Iterator();
1214  reference operator*() const;
1215  pointer operator->() const;
1216  Iterator& operator++();
1217  Iterator operator++(int);
1218  bool operator==(const Iterator& other) const;
1219  bool operator!=(const Iterator& other) const;
1220 
1221  private:
1222  struct Impl;
1223  std::unique_ptr<Impl> impl_;
1224  };
1225 
1227  struct ConstIterator {
1228  using iterator_category = std::forward_iterator_tag;
1229  using difference_type = std::ptrdiff_t;
1230  using value_type = const Tensor;
1232  using reference = value_type; // Typically Tensor&, but a tensor slice
1233  // creates a new Tensor object with
1234  // shared memory.
1235 
1236  // ConstIterator must be constructible, copy-constructible,
1237  // copy-assignable, destructible and swappable.
1238  ConstIterator(pointer tensor, int64_t index);
1239  ConstIterator(const ConstIterator&);
1240  ~ConstIterator();
1241  reference operator*() const;
1242  pointer operator->() const;
1245  bool operator==(const ConstIterator& other) const;
1246  bool operator!=(const ConstIterator& other) const;
1247 
1248  private:
1249  struct Impl;
1250  std::unique_ptr<Impl> impl_;
1251  };
1252 
1256  Iterator begin();
1257 
1261  Iterator end();
1262 
1266  ConstIterator cbegin() const;
1267 
1271  ConstIterator cend() const;
1272 
1277  ConstIterator begin() const { return cbegin(); }
1278 
1283  ConstIterator end() const { return cend(); }
1284 
1285 protected:
1286  std::string ScalarPtrToString(const void* ptr) const;
1287 
1288 private:
1290  template <typename T, size_t D>
1291  static Tensor InitWithInitializerList(
1292  const tensor_init::NestedInitializerList<T, D>& nested_list,
1293  const Device& device = Device("CPU:0")) {
1294  SizeVector shape = tensor_init::InferShape(nested_list);
1295  std::vector<T> values =
1296  tensor_init::ToFlatVector<T, D>(shape, nested_list);
1297  return Tensor(values, shape, Dtype::FromType<T>(), device);
1298  }
1299 
1300 protected:
1303 
1312 
1326  void* data_ptr_ = nullptr;
1327 
1330 
1332  std::shared_ptr<Blob> blob_ = nullptr;
1333 };
1334 
1335 template <>
1336 inline Tensor::Tensor(const std::vector<bool>& init_vals,
1337  const SizeVector& shape,
1338  Dtype dtype,
1339  const Device& device)
1340  : Tensor(shape, dtype, device) {
1341  // Check number of elements
1342  if (static_cast<int64_t>(init_vals.size()) != shape_.NumElements()) {
1344  "Tensor initialization values' size {} does not match the "
1345  "shape {}",
1346  init_vals.size(), shape_.NumElements());
1347  }
1348 
1349  // Check data types
1350  AssertTemplateDtype<bool>();
1351 
1352  // std::vector<bool> possibly implements 1-bit-sized boolean storage.
1353  // Open3D uses 1-byte-sized boolean storage for easy indexing.
1354  std::vector<uint8_t> init_vals_uchar(init_vals.size());
1355  std::transform(init_vals.begin(), init_vals.end(), init_vals_uchar.begin(),
1356  [](bool v) -> uint8_t { return static_cast<uint8_t>(v); });
1357 
1359  init_vals_uchar.data(),
1360  init_vals_uchar.size() * dtype.ByteSize());
1361 }
1362 
1363 template <>
1364 inline std::vector<bool> Tensor::ToFlatVector() const {
1365  AssertTemplateDtype<bool>();
1366  std::vector<bool> values(NumElements());
1367  std::vector<uint8_t> values_uchar(NumElements());
1368  MemoryManager::MemcpyToHost(values_uchar.data(), Contiguous().GetDataPtr(),
1369  GetDevice(),
1370  GetDtype().ByteSize() * NumElements());
1371 
1372  // std::vector<bool> possibly implements 1-bit-sized boolean storage.
1373  // Open3D uses 1-byte-sized boolean storage for easy indexing.
1374  std::transform(values_uchar.begin(), values_uchar.end(), values.begin(),
1375  [](uint8_t v) -> bool { return static_cast<bool>(v); });
1376  return values;
1377 }
1378 
1379 template <>
1380 inline bool Tensor::Item() const {
1381  if (shape_.NumElements() != 1) {
1383  "Tensor::Item only works for Tensor with one element.");
1384  }
1385  AssertTemplateDtype<bool>();
1386  uint8_t value;
1388  sizeof(uint8_t));
1389  return static_cast<bool>(value);
1390 }
1391 
1392 template <typename S>
1393 inline void Tensor::Fill(S v) {
1395  scalar_t casted_v = static_cast<scalar_t>(v);
1396  Tensor tmp(std::vector<scalar_t>({casted_v}), SizeVector({}),
1397  GetDtype(), GetDevice());
1398  AsRvalue() = tmp;
1399  });
1400 }
1401 
1402 template <typename Object>
1403 inline void Tensor::FillObject(const Object& v) {
1404  Tensor tmp(std::vector<Object>({v}), SizeVector({}), GetDtype(),
1405  GetDevice());
1406  AsRvalue() = tmp;
1407 }
1408 
1409 template <typename T>
1410 inline Tensor operator+(T scalar_lhs, const Tensor& rhs) {
1411  return rhs + scalar_lhs;
1412 }
1413 
1414 template <typename T>
1415 inline Tensor operator-(T scalar_lhs, const Tensor& rhs) {
1416  return Tensor::Full({}, scalar_lhs, rhs.GetDtype(), rhs.GetDevice()) - rhs;
1417 }
1418 
1419 template <typename T>
1420 inline Tensor operator*(T scalar_lhs, const Tensor& rhs) {
1421  return rhs * scalar_lhs;
1422 }
1423 
1424 template <typename T>
1425 inline Tensor operator/(T scalar_lhs, const Tensor& rhs) {
1426  return Tensor::Full({}, scalar_lhs, rhs.GetDtype(), rhs.GetDevice()) / rhs;
1427 }
1428 
1429 inline void AssertNotSYCL(const Tensor& tensor) {
1430  if (tensor.GetDevice().IsSYCL()) {
1431  utility::LogError("Not supported for SYCL device.");
1432  }
1433 }
1434 
1435 } // namespace core
1436 } // namespace open3d
The common header of DLPack.
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE,...)
Definition: Dispatch.h:67
#define LogError(...)
Definition: Logging.h:51
double t
Definition: SurfaceReconstructionPoisson.cpp:172
bool copy
Definition: VtkUtils.cpp:74
Definition: Blob.h:38
Definition: Device.h:18
bool IsSYCL() const
Returns true iff device type is SYCL GPU.
Definition: Device.h:52
Definition: Dtype.h:20
std::string ToString() const
Definition: Dtype.h:64
bool IsObject() const
Definition: Dtype.h:62
int64_t ByteSize() const
Definition: Dtype.h:58
Definition: Device.h:88
static void MemcpyToHost(void *host_ptr, const void *src_ptr, const Device &src_device, size_t num_bytes)
Same as Memcpy, but with host (CPU:0) as default dst_device.
Definition: MemoryManager.cpp:85
static void MemcpyFromHost(void *dst_ptr, const Device &dst_device, const void *host_ptr, size_t num_bytes)
Same as Memcpy, but with host (CPU:0) as default src_device.
Definition: MemoryManager.cpp:77
Definition: Scalar.h:23
Definition: SizeVector.h:69
int64_t NumElements() const
Definition: SizeVector.cpp:108
int64_t GetLength() const
Definition: SizeVector.cpp:124
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:122
size_t size() const
Definition: SmallVector.h:119
Definition: Tensor.h:32
Tensor operator*(Scalar value) const
Definition: Tensor.h:660
Tensor Clone() const
Copy Tensor to the same device.
Definition: Tensor.h:502
T * GetDataPtr()
Definition: Tensor.h:1144
SizeVector strides_
Definition: Tensor.h:1311
Tensor NonZero() const
Definition: Tensor.cpp:1723
Tensor Neg() const
Element-wise negation of a tensor, returning a new tensor.
Definition: Tensor.cpp:1297
const SizeVector & GetStridesRef() const
Definition: Tensor.h:1137
const T * GetDataPtr() const
Definition: Tensor.h:1149
Tensor Ge_(const Tensor &value)
Definition: Tensor.cpp:1604
int64_t GetShape(int64_t dim) const
Definition: Tensor.h:1131
Tensor LogicalNot() const
Definition: Tensor.cpp:1410
Tensor LogicalXor_(const Tensor &value)
Definition: Tensor.cpp:1507
Tensor operator*=(Scalar value)
Definition: Tensor.h:667
Tensor Exp() const
Element-wise exponential of a tensor, returning a new tensor.
Definition: Tensor.cpp:1308
static Tensor Init(const std::initializer_list< T > &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:285
std::vector< T > ToFlatVector() const
Retrieve all values as an std::vector, for debugging and testing.
Definition: Tensor.h:1025
Tensor Flatten(int64_t start_dim=0, int64_t end_dim=-1) const
Definition: Tensor.cpp:653
std::vector< Tensor > NonZeroNumpy() const
Definition: Tensor.cpp:1714
Tensor LeastSquares(const Tensor &rhs) const
Definition: Tensor.cpp:1885
Tensor operator&&(const Tensor &value) const
Definition: Tensor.h:822
Tensor Ge(const Tensor &value) const
Definition: Tensor.cpp:1586
bool AllClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1842
ConstIterator cend() const
Definition: Tensor.cpp:313
double Det() const
Compute the determinant of a 2D square tensor.
Definition: Tensor.cpp:1060
Tensor All(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1738
Tensor & operator=(const T v) &&
Definition: Tensor.h:205
std::string ScalarPtrToString(const void *ptr) const
Definition: Tensor.cpp:793
Tensor SetItem(const Tensor &value)
Set all items. Equivalent to tensor[:] = value in Python.
Definition: Tensor.cpp:532
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:368
Tensor Cos() const
Element-wise cosine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1286
Tensor operator||(const Tensor &value) const
Definition: Tensor.h:839
Tensor IndexExtract(int64_t dim, int64_t idx) const
Definition: Tensor.cpp:809
Tensor Sin() const
Element-wise sine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1275
Tensor(Tensor &&other)=default
Tensor Floor() const
Element-wise floor value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1379
Tensor Inverse() const
Definition: Tensor.cpp:1929
void Fill(S v)
Fill the whole Tensor with a scalar value, the scalar will be casted to the Tensor's Dtype.
Definition: Tensor.h:1393
Tensor & AssignObject(const Object &v) &&
Definition: Tensor.h:220
Tensor Sum(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1208
Tensor Gt_(const Tensor &value)
Definition: Tensor.cpp:1540
Tensor LogicalAnd(const Tensor &value) const
Definition: Tensor.cpp:1421
static Tensor Ones(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with ones.
Definition: Tensor.cpp:380
Tensor Lt_(const Tensor &value)
Definition: Tensor.cpp:1572
Tensor IsClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1847
Tensor(const Tensor &other)=default
Tensor Le(const Tensor &value) const
Definition: Tensor.cpp:1618
static Tensor Arange(const Scalar start, const Scalar stop, const Scalar step=1, const Dtype dtype=core::Int64, const Device &device=core::Device("CPU:0"))
Create a 1D tensor with evenly spaced values in the given interval.
Definition: Tensor.cpp:404
SizeVector GetShape() const
Definition: Tensor.h:1127
Tensor LogicalOr_(const Tensor &value)
Definition: Tensor.cpp:1474
int64_t GetLength() const
Definition: Tensor.h:1125
Tensor & operator=(const Tensor &other) &
Definition: Tensor.cpp:323
Tensor LogicalOr(const Tensor &value) const
Definition: Tensor.cpp:1455
Iterator end()
Definition: Tensor.cpp:244
Tensor operator+=(Scalar value)
Definition: Tensor.h:641
Tensor Sub(const Tensor &value) const
Substracts a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1101
Tensor AsStrided(const SizeVector &new_shape, const SizeVector &new_strides) const
Create a Tensor view of specified shape and strides. The underlying buffer and data_ptr offsets remai...
Definition: Tensor.cpp:1029
Tensor(void *data_ptr, Dtype dtype, const SizeVector &shape, const SizeVector &strides={}, const Device &device=Device("CPU:0"))
Tensor wrapper constructor from raw host buffer.
Definition: Tensor.h:162
const void * GetDataPtr() const
Definition: Tensor.h:1162
std::tuple< Tensor, Tensor, Tensor > SVD() const
Definition: Tensor.cpp:1937
Tensor Add_(const Tensor &value)
Definition: Tensor.cpp:1085
Tensor ArgMin(const SizeVector &dims) const
Definition: Tensor.cpp:1250
Tensor Tril(const int diagonal=0) const
Returns the lower triangular matrix of the 2D tensor, above the given diagonal index....
Definition: Tensor.cpp:1917
void Save(const std::string &file_name) const
Save tensor to numpy's npy format.
Definition: Tensor.cpp:1824
Tensor Reverse() const
Reverse a Tensor's elements by viewing the tensor as a 1D array.
Definition: Tensor.cpp:433
void * data_ptr_
Definition: Tensor.h:1326
std::string ToString(bool with_suffix=true, const std::string &indent="") const
Definition: Tensor.cpp:748
Tensor Slice(int64_t dim, int64_t start, int64_t stop, int64_t step=1) const
Definition: Tensor.cpp:825
Tensor operator*=(const Tensor &value)
Definition: Tensor.h:666
Tensor Min(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1236
Iterator begin()
Definition: Tensor.cpp:237
Tensor IsFinite() const
Definition: Tensor.cpp:1350
Tensor T() const
Expects input to be <= 2-D Tensor by swapping dimension 0 and 1.
Definition: Tensor.cpp:1047
Tensor AsRvalue()
Definition: Tensor.h:558
Tensor Mean(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1215
Tensor Div(const Tensor &value) const
Divides a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1173
Tensor Lt(const Tensor &value) const
Element-wise less-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1554
Tensor ReinterpretCast(const core::Dtype &dtype) const
Definition: Tensor.cpp:356
Tensor Trunc() const
Element-wise trunc value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1397
Tensor Sub_(const Tensor &value)
Definition: Tensor.cpp:1121
Tensor Sqrt_()
Element-wise square root of a tensor, in-place.
Definition: Tensor.cpp:1270
Tensor Neg_()
Element-wise negation of a tensor, in-place.
Definition: Tensor.cpp:1303
Tensor operator/(const Tensor &value) const
Definition: Tensor.h:672
Tensor Contiguous() const
Definition: Tensor.cpp:740
Tensor ArgMax(const SizeVector &dims) const
Definition: Tensor.cpp:1257
Dtype dtype_
Data type.
Definition: Tensor.h:1329
static Tensor Diag(const Tensor &input)
Create a square matrix with specified diagonal elements in input.
Definition: Tensor.cpp:392
int64_t NumDims() const
Definition: Tensor.h:1172
ConstIterator cbegin() const
Definition: Tensor.cpp:306
Tensor LogicalAnd_(const Tensor &value)
Definition: Tensor.cpp:1440
Tensor operator-() const
Unary minus of a tensor, returning a new tensor.
Definition: Tensor.h:752
Tensor Transpose(int64_t dim0, int64_t dim1) const
Transpose a Tensor by swapping dimension dim0 and dim1.
Definition: Tensor.cpp:1036
Tensor Clip_(Scalar min_val, Scalar max_val)
Definition: Tensor.cpp:1366
Tensor Gt(const Tensor &value) const
Element-wise greater-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1522
DLManagedTensor * ToDLPack() const
Convert the Tensor to DLManagedTensor.
Definition: Tensor.cpp:1776
Tensor(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Constructor for creating a contiguous Tensor.
Definition: Tensor.h:37
std::shared_ptr< Blob > GetBlob() const
Definition: Tensor.h:1168
void CopyFrom(const Tensor &other)
Copy Tensor values to current tensor from the source tensor.
Definition: Tensor.cpp:738
Tensor operator/=(const Tensor &value)
Definition: Tensor.h:679
Tensor operator/(Scalar value) const
Definition: Tensor.h:673
static Tensor EmptyLike(const Tensor &other)
Definition: Tensor.h:247
static Tensor Full(const SizeVector &shape, T fill_value, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with specified value.
Definition: Tensor.h:253
Tensor View(const SizeVector &dst_shape) const
Definition: Tensor.cpp:689
void FillObject(const Object &v)
Definition: Tensor.h:1403
bool IsContiguous() const
Definition: Tensor.h:1036
Tensor operator<(const Tensor &value) const
Definition: Tensor.h:880
Tensor Abs() const
Element-wise absolute value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1319
Tensor Any(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1757
std::shared_ptr< Blob > blob_
Underlying memory buffer for Tensor.
Definition: Tensor.h:1332
Tensor operator+=(const Tensor &value)
Definition: Tensor.h:640
Tensor Eq_(const Tensor &value)
Definition: Tensor.cpp:1668
Tensor operator-=(Scalar value)
Definition: Tensor.h:654
static Tensor Zeros(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with zeros.
Definition: Tensor.cpp:374
Tensor Le_(const Tensor &value)
Definition: Tensor.cpp:1636
bool AllEqual(const Tensor &other) const
Definition: Tensor.cpp:1832
void * GetDataPtr()
Definition: Tensor.h:1160
Tensor operator+(Scalar value) const
Definition: Tensor.h:634
Tensor Reshape(const SizeVector &dst_shape) const
Definition: Tensor.cpp:639
void AssertTemplateDtype() const
Definition: Tensor.h:1175
static Tensor Init(const std::initializer_list< std::initializer_list< T >> &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:293
void IndexAdd_(int64_t dim, const Tensor &index, const Tensor &src)
Advanced in-place reduction by index.
Definition: Tensor.cpp:959
Tensor Add(const Tensor &value) const
Adds a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1065
ConstIterator begin() const
Definition: Tensor.h:1277
Tensor Prod(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1229
Tensor Cos_()
Element-wise cosine of a tensor, in-place.
Definition: Tensor.cpp:1292
Tensor Triu(const int diagonal=0) const
Returns the upper triangular matrix of the 2D tensor, above the given diagonal index....
Definition: Tensor.cpp:1911
Tensor Div_(const Tensor &value)
Definition: Tensor.cpp:1193
Tensor Sqrt() const
Element-wise square root of a tensor, returns a new tensor.
Definition: Tensor.cpp:1264
SizeVector shape_
SizeVector of the Tensor. shape_[i] is the length of dimension i.
Definition: Tensor.h:1302
Tensor(const T *init_vals, const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Constructor from raw host buffer. The memory will be copied.
Definition: Tensor.h:78
Tensor()
Definition: Tensor.h:34
Tensor Clip(Scalar min_val, Scalar max_val) const
Definition: Tensor.cpp:1360
Device GetDevice() const override
Definition: Tensor.cpp:1403
static Tensor Load(const std::string &file_name)
Load tensor from numpy's npy format.
Definition: Tensor.cpp:1828
bool IsSame(const Tensor &other) const
Definition: Tensor.cpp:1859
std::tuple< Tensor, Tensor, Tensor > LU(const bool permute_l=false) const
Computes LU factorisation of the 2D square tensor, using A = P * L * U; where P is the permutation ma...
Definition: Tensor.cpp:1895
Tensor operator==(const Tensor &value) const
Definition: Tensor.h:912
int64_t GetStride(int64_t dim) const
Definition: Tensor.h:1139
static Tensor Init(const T val, const Device &device=Device("CPU:0"))
Definition: Tensor.h:275
bool IsNonZero() const
Definition: Tensor.cpp:1725
Tensor operator-(Scalar value) const
Definition: Tensor.h:647
Tensor Ne(const Tensor &value) const
Element-wise not-equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1682
Tensor Solve(const Tensor &rhs) const
Definition: Tensor.cpp:1875
Tensor Matmul(const Tensor &rhs) const
Definition: Tensor.cpp:1866
Tensor operator>=(const Tensor &value) const
Definition: Tensor.h:891
T Item() const
Definition: Tensor.h:618
std::tuple< Tensor, Tensor > Triul(const int diagonal=0) const
Returns the tuple of upper and lower triangular matrix of the 2D tensor, above and below the given di...
Definition: Tensor.cpp:1923
Tensor Mul_(const Tensor &value)
Definition: Tensor.cpp:1157
Tensor Exp_()
Element-wise base-e exponential of a tensor, in-place.
Definition: Tensor.cpp:1314
Tensor operator/=(Scalar value)
Definition: Tensor.h:680
Tensor Sin_()
Element-wise sine of a tensor, in-place.
Definition: Tensor.cpp:1281
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create an identity matrix of size n x n.
Definition: Tensor.cpp:386
static Tensor Init(const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:302
Tensor(const SizeVector &shape, const SizeVector &strides, void *data_ptr, Dtype dtype, const std::shared_ptr< Blob > &blob)
Definition: Tensor.h:95
Tensor operator+(const Tensor &value) const
Definition: Tensor.h:633
Tensor(const std::vector< T > &init_vals, const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Constructor for creating a contiguous Tensor with initial values.
Definition: Tensor.h:50
int64_t NumElements() const
Definition: Tensor.h:1170
Tensor GetItem(const TensorKey &tk) const
Definition: Tensor.cpp:441
Tensor operator*(const Tensor &value) const
Definition: Tensor.h:659
Tensor operator[](int64_t i) const
Extract the i-th Tensor along the first axis, returning a new view.
Definition: Tensor.cpp:807
static Tensor FromDLPack(const DLManagedTensor *dlmt)
Convert DLManagedTensor to Tensor.
Definition: Tensor.cpp:1780
Tensor Abs_()
Element-wise absolute value of a tensor, in-place.
Definition: Tensor.cpp:1325
Tensor operator!=(const Tensor &value) const
Definition: Tensor.h:922
const SizeVector & GetShapeRef() const
Definition: Tensor.h:1129
Tensor operator-(const Tensor &value) const
Definition: Tensor.h:646
Tensor IsInf() const
Definition: Tensor.cpp:1340
Tensor Broadcast(const SizeVector &dst_shape) const
Broadcast Tensor to a new broadcastable shape.
Definition: Tensor.cpp:596
Tensor(std::vector< T > &&vec, const SizeVector &shape={})
Take ownership of data in std::vector<T>
Definition: Tensor.h:117
Dtype GetDtype() const
Definition: Tensor.h:1164
Tensor Mul(const Tensor &value) const
Multiplies a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1137
Tensor operator<=(const Tensor &value) const
Definition: Tensor.h:902
ConstIterator end() const
Definition: Tensor.h:1283
Tensor operator-=(const Tensor &value)
Definition: Tensor.h:653
Tensor Permute(const SizeVector &dims) const
Permute (dimension shuffle) the Tensor, returns a view.
Definition: Tensor.cpp:996
void IndexSet(const std::vector< Tensor > &index_tensors, const Tensor &src_tensor)
Advanced indexing getter.
Definition: Tensor.cpp:904
Tensor Expand(const SizeVector &dst_shape) const
Definition: Tensor.cpp:606
Tensor Ne_(const Tensor &value)
Definition: Tensor.cpp:1700
SizeVector GetStrides() const
Definition: Tensor.h:1135
Tensor IsNan() const
Definition: Tensor.cpp:1330
Tensor LogicalXor(const Tensor &value) const
Definition: Tensor.cpp:1488
std::tuple< Tensor, Tensor > LUIpiv() const
Computes LU factorisation of the 2D square tensor, using A = P * L * U; where P is the permutation ma...
Definition: Tensor.cpp:1903
Tensor operator>(const Tensor &value) const
Definition: Tensor.h:870
const Tensor AsRvalue() const
Convert to constant rvalue.
Definition: Tensor.h:561
Tensor Append(const Tensor &other, const utility::optional< int64_t > &axis=utility::nullopt) const
Appends the other tensor, along the given axis and returns a copy of the tensor. The other tensors mu...
Definition: Tensor.cpp:590
Tensor Eq(const Tensor &value) const
Element-wise equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1650
Tensor LogicalNot_()
Definition: Tensor.cpp:1416
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:707
Tensor Ceil() const
Element-wise ceil value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1385
Tensor IndexGet(const std::vector< Tensor > &index_tensors) const
Advanced indexing getter. This will always allocate a new Tensor.
Definition: Tensor.cpp:873
Tensor Round() const
Element-wise round value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1391
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1243
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
Definition: TensorKey.h:26
char type
Definition: FilePCD.cpp:41
int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive)
Wrap around negative dim.
Definition: ShapeUtil.cpp:131
SizeVector DefaultStrides(const SizeVector &shape)
Compute default strides for a shape when a tensor is contiguous.
Definition: ShapeUtil.cpp:214
SizeVector InferShape(const L &list)
Definition: TensorInit.h:82
typename NestedInitializerImpl< T, D >::type NestedInitializerList
Definition: TensorInit.h:36
Tensor operator+(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1410
const Dtype Int64
Definition: Dtype.cpp:47
Tensor operator/(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1425
const Dtype Undefined
Definition: Dtype.cpp:41
Tensor operator-(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1415
Tensor operator*(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1420
void AssertNotSYCL(const Tensor &tensor)
Definition: Tensor.h:1429
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:250
constexpr nullopt_t nullopt
Definition: Optional.h:152
Definition: PinholeCameraIntrinsic.cpp:16
Definition: Device.h:111
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
Definition: DLPack.h:174
Const iterator for Tensor.
Definition: Tensor.h:1227
ConstIterator & operator++()
Definition: Tensor.cpp:284
ConstIterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:259
~ConstIterator()
Definition: Tensor.cpp:273
pointer operator->() const
Definition: Tensor.cpp:279
const Tensor value_type
Definition: Tensor.h:1230
reference operator*() const
Definition: Tensor.cpp:275
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1228
std::ptrdiff_t difference_type
Definition: Tensor.h:1229
bool operator!=(const ConstIterator &other) const
Definition: Tensor.cpp:301
bool operator==(const ConstIterator &other) const
Definition: Tensor.cpp:295
Iterator for Tensor.
Definition: Tensor.h:1200
Iterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:192
std::ptrdiff_t difference_type
Definition: Tensor.h:1202
Iterator & operator++()
Definition: Tensor.cpp:217
bool operator==(const Iterator &other) const
Definition: Tensor.cpp:228
pointer operator->() const
Definition: Tensor.cpp:212
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1201
~Iterator()
Definition: Tensor.cpp:206
bool operator!=(const Iterator &other) const
Definition: Tensor.cpp:233
reference operator*() const
Definition: Tensor.cpp:208
Tensor value_type
Definition: Tensor.h:1203