ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Tensor.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.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 "cloudViewer/core/Blob.h"
19 #include "cloudViewer/core/Dtype.h"
26 
27 namespace cloudViewer {
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;
1191 
1193  static Tensor FromDLPack(const DLManagedTensor* dlmt,
1194  std::function<void(void*)> deleter = nullptr);
1196  static Tensor FromDLPackVersioned(
1197  const DLManagedTensorVersioned* dlmt,
1198  std::function<void(void*)> deleter = nullptr);
1199 
1201  void Save(const std::string& file_name) const;
1202 
1204  static Tensor Load(const std::string& file_name);
1205 
1207  struct Iterator {
1208  using iterator_category = std::forward_iterator_tag;
1209  using difference_type = std::ptrdiff_t;
1212  using reference = value_type; // Typically Tensor&, but a tensor slice
1213  // creates a new Tensor object with
1214  // shared memory.
1215 
1216  // Iterator must be constructible, copy-constructible, copy-assignable,
1217  // destructible and swappable.
1218  Iterator(pointer tensor, int64_t index);
1219  Iterator(const Iterator&);
1220  ~Iterator();
1221  reference operator*() const;
1222  pointer operator->() const;
1223  Iterator& operator++();
1224  Iterator operator++(int);
1225  bool operator==(const Iterator& other) const;
1226  bool operator!=(const Iterator& other) const;
1227 
1228  private:
1229  struct Impl;
1230  std::unique_ptr<Impl> impl_;
1231  };
1232 
1234  struct ConstIterator {
1235  using iterator_category = std::forward_iterator_tag;
1236  using difference_type = std::ptrdiff_t;
1237  using value_type = const Tensor;
1239  using reference = value_type; // Typically Tensor&, but a tensor slice
1240  // creates a new Tensor object with
1241  // shared memory.
1242 
1243  // ConstIterator must be constructible, copy-constructible,
1244  // copy-assignable, destructible and swappable.
1245  ConstIterator(pointer tensor, int64_t index);
1246  ConstIterator(const ConstIterator&);
1247  ~ConstIterator();
1248  reference operator*() const;
1249  pointer operator->() const;
1252  bool operator==(const ConstIterator& other) const;
1253  bool operator!=(const ConstIterator& other) const;
1254 
1255  private:
1256  struct Impl;
1257  std::unique_ptr<Impl> impl_;
1258  };
1259 
1263  Iterator begin();
1264 
1268  Iterator end();
1269 
1273  ConstIterator cbegin() const;
1274 
1278  ConstIterator cend() const;
1279 
1284  ConstIterator begin() const { return cbegin(); }
1285 
1290  ConstIterator end() const { return cend(); }
1291 
1292 protected:
1293  std::string ScalarPtrToString(const void* ptr) const;
1294 
1295 private:
1297  template <typename T, size_t D>
1298  static Tensor InitWithInitializerList(
1299  const tensor_init::NestedInitializerList<T, D>& nested_list,
1300  const Device& device = Device("CPU:0")) {
1301  SizeVector shape = tensor_init::InferShape(nested_list);
1302  std::vector<T> values =
1303  tensor_init::ToFlatVector<T, D>(shape, nested_list);
1304  return Tensor(values, shape, Dtype::FromType<T>(), device);
1305  }
1306 
1307 protected:
1310 
1319 
1333  void* data_ptr_ = nullptr;
1334 
1337 
1339  std::shared_ptr<Blob> blob_ = nullptr;
1340 };
1341 
1342 template <>
1343 inline Tensor::Tensor(const std::vector<bool>& init_vals,
1344  const SizeVector& shape,
1345  Dtype dtype,
1346  const Device& device)
1347  : Tensor(shape, dtype, device) {
1348  // Check number of elements
1349  if (static_cast<int64_t>(init_vals.size()) != shape_.NumElements()) {
1351  "Tensor initialization values' size {} does not match the "
1352  "shape {}",
1353  init_vals.size(), shape_.NumElements());
1354  }
1355 
1356  // Check data types
1357  AssertTemplateDtype<bool>();
1358 
1359  // std::vector<bool> possibly implements 1-bit-sized boolean storage.
1360  // CloudViewer uses 1-byte-sized boolean storage for easy indexing.
1361  std::vector<uint8_t> init_vals_uchar(init_vals.size());
1362  std::transform(init_vals.begin(), init_vals.end(), init_vals_uchar.begin(),
1363  [](bool v) -> uint8_t { return static_cast<uint8_t>(v); });
1364 
1366  init_vals_uchar.data(),
1367  init_vals_uchar.size() * dtype.ByteSize());
1368 }
1369 
1370 template <>
1371 inline std::vector<bool> Tensor::ToFlatVector() const {
1372  AssertTemplateDtype<bool>();
1373  std::vector<bool> values(NumElements());
1374  std::vector<uint8_t> values_uchar(NumElements());
1375  MemoryManager::MemcpyToHost(values_uchar.data(), Contiguous().GetDataPtr(),
1376  GetDevice(),
1377  GetDtype().ByteSize() * NumElements());
1378 
1379  // std::vector<bool> possibly implements 1-bit-sized boolean storage.
1380  // CloudViewer uses 1-byte-sized boolean storage for easy indexing.
1381  std::transform(values_uchar.begin(), values_uchar.end(), values.begin(),
1382  [](uint8_t v) -> bool { return static_cast<bool>(v); });
1383  return values;
1384 }
1385 
1386 template <>
1387 inline bool Tensor::Item() const {
1388  if (shape_.NumElements() != 1) {
1390  "Tensor::Item only works for Tensor with one element.");
1391  }
1392  AssertTemplateDtype<bool>();
1393  uint8_t value;
1395  sizeof(uint8_t));
1396  return static_cast<bool>(value);
1397 }
1398 
1399 template <typename S>
1400 inline void Tensor::Fill(S v) {
1402  scalar_t casted_v = static_cast<scalar_t>(v);
1403  Tensor tmp(std::vector<scalar_t>({casted_v}), SizeVector({}),
1404  GetDtype(), GetDevice());
1405  AsRvalue() = tmp;
1406  });
1407 }
1408 
1409 template <typename Object>
1410 inline void Tensor::FillObject(const Object& v) {
1411  Tensor tmp(std::vector<Object>({v}), SizeVector({}), GetDtype(),
1412  GetDevice());
1413  AsRvalue() = tmp;
1414 }
1415 
1416 template <typename T>
1417 inline Tensor operator+(T scalar_lhs, const Tensor& rhs) {
1418  return rhs + scalar_lhs;
1419 }
1420 
1421 template <typename T>
1422 inline Tensor operator-(T scalar_lhs, const Tensor& rhs) {
1423  return Tensor::Full({}, scalar_lhs, rhs.GetDtype(), rhs.GetDevice()) - rhs;
1424 }
1425 
1426 template <typename T>
1427 inline Tensor operator*(T scalar_lhs, const Tensor& rhs) {
1428  return rhs * scalar_lhs;
1429 }
1430 
1431 template <typename T>
1432 inline Tensor operator/(T scalar_lhs, const Tensor& rhs) {
1433  return Tensor::Full({}, scalar_lhs, rhs.GetDtype(), rhs.GetDevice()) / rhs;
1434 }
1435 
1436 inline void AssertNotSYCL(const Tensor& tensor) {
1437  if (tensor.GetDevice().IsSYCL()) {
1438  utility::LogError("Not supported for SYCL device.");
1439  }
1440 }
1441 
1442 } // namespace core
1443 } // namespace cloudViewer
cloudViewer::core::TensorKey::InstantiateDimSize
TensorKey InstantiateDimSize(int64_t dim_size) const
Definition: TensorKey.cpp:177
cloudViewer::utility::optional::value
constexpr T const & value() const &
Definition: Optional.h:465
cloudViewer::core::AdvancedIndexPreprocessor::GetOutputShape
SizeVector GetOutputShape() const
Definition: AdvancedIndexing.h:35
SVD.h
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
cloudViewer::core::Tensor::IndexSet
void IndexSet(const std::vector< Tensor > &index_tensors, const Tensor &src_tensor)
Advanced indexing getter.
Definition: Tensor.cpp:936
cloudViewer::core::Tensor::Ones
static Tensor Ones(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with ones.
Definition: Tensor.cpp:412
cloudViewer::core::Tensor::GetDtype
Dtype GetDtype() const
Definition: Tensor.h:1164
cloudViewer::core::Tensor::Clone
Tensor Clone() const
Copy Tensor to the same device.
Definition: Tensor.h:502
cloudViewer::core::Tensor::Init
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
cloudViewer::core::Tensor::EmptyLike
static Tensor EmptyLike(const Tensor &other)
Definition: Tensor.h:247
ShapeUtil.h
cloudViewer::core::shape_util::ReductionShape
SizeVector ReductionShape(const SizeVector &src_shape, const SizeVector &dims, bool keepdim)
Returns the shape after reduction.
Definition: ShapeUtil.cpp:99
DLDataType
The data type the tensor can hold. The data type is assumed to follow the native endian-ness....
Definition: DLPack.h:226
cloudViewer::core::Tensor::FillObject
void FillObject(const Object &v)
Definition: Tensor.h:1410
cloudViewer::core::UInt16
const Dtype UInt16
Definition: Dtype.cpp:49
kDLBool
@ kDLBool
boolean
Definition: DLPack.h:181
Scalar.h
cloudViewer::core::Tensor::Add
Tensor Add(const Tensor &value) const
Adds a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1097
cloudViewer::core::Tensor::Sqrt
Tensor Sqrt() const
Element-wise square root of a tensor, returns a new tensor.
Definition: Tensor.cpp:1296
cloudViewer::core::Tril
void Tril(const Tensor &A, Tensor &output, const int diagonal)
Definition: Tri.cpp:57
CUDAUtils.h
Common CUDA utilities.
Kernel.h
cloudViewer::core::kernel::BinaryEWOpCode::Div
@ Div
Optional.h
cloudViewer::core::Tensor::operator<
Tensor operator<(const Tensor &value) const
Definition: Tensor.h:880
cloudViewer::core::shape_util::BroadcastedShape
SizeVector BroadcastedShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns the broadcasted shape of two shapes.
Definition: ShapeUtil.cpp:56
cloudViewer::core::kernel::ReductionOpCode::Sum
@ Sum
cloudViewer::core::kernel::UnaryEWOpCode::Ceil
@ Ceil
Device.h
cloudViewer::core::Tensor::GetLength
int64_t GetLength() const
Definition: Tensor.h:1125
Arange.h
cloudViewer::core::kernel::UnaryEWOpCode::IsFinite
@ IsFinite
cloudViewer::core::Tensor::Sin_
Tensor Sin_()
Element-wise sine of a tensor, in-place.
Definition: Tensor.cpp:1313
cloudViewer::core::TensorKey::GetIndexTensor
Tensor GetIndexTensor() const
Definition: TensorKey.cpp:186
AdvancedIndexing.h
cloudViewer::utility::optional::has_value
constexpr bool has_value() const noexcept
Definition: Optional.h:440
cloudViewer::core::Tensor::Diag
static Tensor Diag(const Tensor &input)
Create a square matrix with specified diagonal elements in input.
Definition: Tensor.cpp:424
cloudViewer::core::Int16
const Dtype Int16
Definition: Dtype.cpp:45
cloudViewer::core::Tensor::GetShape
SizeVector GetShape() const
Definition: Tensor.h:1127
DLManagedTensorVersioned::flags
uint64_t flags
Additional bitmask flags information about the tensor.
Definition: DLPack.h:398
cloudViewer::core::Tensor::Mean
Tensor Mean(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1247
cloudViewer::core::Tensor::operator<=
Tensor operator<=(const Tensor &value) const
Definition: Tensor.h:902
cloudViewer::core::TensorKey::IndexTensor
static TensorKey IndexTensor(const Tensor &index_tensor)
Definition: TensorKey.cpp:144
cloudViewer::core::Tensor::Ceil
Tensor Ceil() const
Element-wise ceil value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1417
kDLCPU
@ kDLCPU
CPU device.
Definition: DLPack.h:95
cloudViewer::core::Tensor::SVD
std::tuple< Tensor, Tensor, Tensor > SVD() const
Definition: Tensor.cpp:1990
core::Tensor
cloudViewer::core::Tensor::Neg_
Tensor Neg_()
Element-wise negation of a tensor, in-place.
Definition: Tensor.cpp:1335
cloudViewer::core::Tensor::Tensor
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
cloudViewer::core::Tensor::IndexExtract
Tensor IndexExtract(int64_t dim, int64_t idx) const
Definition: Tensor.cpp:841
copy
bool copy
Definition: VtkUtils.cpp:74
cloudViewer::core::Tensor::operator-
Tensor operator-(Scalar value) const
Definition: Tensor.h:647
cloudViewer::core::AdvancedIndexPreprocessor::GetTensor
Tensor GetTensor() const
Definition: AdvancedIndexing.h:29
cloudViewer::core::Tensor::ReinterpretCast
Tensor ReinterpretCast(const core::Dtype &dtype) const
Definition: Tensor.cpp:388
cloudViewer::core::Tensor::operator-
Tensor operator-() const
Unary minus of a tensor, returning a new tensor.
Definition: Tensor.h:752
cloudViewer::core::Tensor::Fill
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:1400
format
filament::Texture::InternalFormat format
Definition: FilamentResourceManager.cpp:181
cloudViewer::core::UInt32
const Dtype UInt32
Definition: Dtype.cpp:50
cloudViewer::core::Tensor::IsSame
bool IsSame(const Tensor &other) const
Definition: Tensor.cpp:1912
cloudViewer::core::IsDevice::IsCUDA
bool IsCUDA() const
Definition: Device.h:99
cloudViewer::core::Tensor::operator-
Tensor operator-(const Tensor &value) const
Definition: Tensor.h:646
cloudViewer::core::Tensor::Reshape
Tensor Reshape(const SizeVector &dst_shape) const
Definition: Tensor.cpp:671
kDLFloat
@ kDLFloat
IEEE floating point.
Definition: DLPack.h:166
cloudViewer::core::Tensor::Save
void Save(const std::string &file_name) const
Save tensor to numpy's npy format.
Definition: Tensor.cpp:1877
TensorInit.h
cloudViewer::core::kernel::IndexAdd_
void IndexAdd_(int64_t dim, const Tensor &index, const Tensor &src, Tensor &dst)
Definition: IndexReduction.cpp:16
core::Tensor::ConstIterator::Impl::tensor_slice_
Tensor tensor_slice_
Definition: Tensor.cpp:286
cloudViewer::core::AssertNotSYCL
void AssertNotSYCL(const Tensor &tensor)
Definition: Tensor.h:1436
AssertTensorDevice
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:45
cloudViewer::core::Tensor::Contiguous
Tensor Contiguous() const
Definition: Tensor.cpp:772
cloudViewer::core::Tensor::Init
static Tensor Init(const std::initializer_list< std::initializer_list< T >> &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:293
cloudViewer::core::Tensor::ConstIterator::operator++
ConstIterator & operator++()
Definition: Tensor.cpp:316
cloudViewer::core::kernel::Reduction
void Reduction(const Tensor &src, Tensor &dst, const SizeVector &dims, bool keepdim, ReductionOpCode op_code)
Definition: Reduction.cpp:16
cloudViewer::core::kernel::UnaryEWOpCode::Sin
@ Sin
cloudViewer::core::Dtype::ByteSize
int64_t ByteSize() const
Definition: Dtype.h:59
cloudViewer::core::Tensor::Reverse
Tensor Reverse() const
Reverse a Tensor's elements by viewing the tensor as a 1D array.
Definition: Tensor.cpp:465
cloudViewer::core::Tensor::Det
double Det() const
Compute the determinant of a 2D square tensor.
Definition: Tensor.cpp:1092
cloudViewer::core::Tensor::IsContiguous
bool IsContiguous() const
Definition: Tensor.h:1036
cloudViewer::core::kernel::BinaryEWOpCode::LogicalXor
@ LogicalXor
DLPACK_MINOR_VERSION
#define DLPACK_MINOR_VERSION
The current minor version of dlpack.
Definition: DLPack.h:40
cloudViewer::core::Tensor::operator*
Tensor operator*(Scalar value) const
Definition: Tensor.h:660
cloudViewer::core::Open3DDLManagedTensor
CloudViewer DLPack Tensor manager.
Definition: Tensor.cpp:133
cloudViewer::core::Tensor::ScalarPtrToString
std::string ScalarPtrToString(const void *ptr) const
Definition: Tensor.cpp:825
cloudViewer::core::Tensor::Mul
Tensor Mul(const Tensor &value) const
Multiplies a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1169
cloudViewer::core::Tensor::operator+=
Tensor operator+=(const Tensor &value)
Definition: Tensor.h:640
cloudViewer::core::Tensor::Tensor
Tensor(const SizeVector &shape, const SizeVector &strides, void *data_ptr, Dtype dtype, const std::shared_ptr< Blob > &blob)
Definition: Tensor.h:95
Inverse.h
cloudViewer::core::TensorKey::GetStart
int64_t GetStart() const
Definition: TensorKey.cpp:156
cloudViewer::core::Tensor::operator+
Tensor operator+(const Tensor &value) const
Definition: Tensor.h:633
cloudViewer::core::operator*
Tensor operator*(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1427
cloudViewer::core::Tensor::ConstIterator::operator==
bool operator==(const ConstIterator &other) const
Definition: Tensor.cpp:327
cloudViewer::core::Device::DeviceType::CPU
@ CPU
core::Tensor::Iterator::Impl::tensor_slice_
Tensor tensor_slice_
Definition: Tensor.cpp:219
cloudViewer::core::Tensor::Slice
Tensor Slice(int64_t dim, int64_t start, int64_t stop, int64_t step=1) const
Definition: Tensor.cpp:857
cloudViewer::core::shape_util::Restride
std::pair< bool, SizeVector > Restride(const SizeVector &old_shape, const SizeVector &old_strides, const SizeVector &new_shape)
Definition: ShapeUtil.cpp:225
cloudViewer::core::Tensor::Permute
Tensor Permute(const SizeVector &dims) const
Permute (dimension shuffle) the Tensor, returns a view.
Definition: Tensor.cpp:1028
cloudViewer::core::TensorKey::GetStop
int64_t GetStop() const
Definition: TensorKey.cpp:163
cloudViewer::core::Tensor::cbegin
ConstIterator cbegin() const
Definition: Tensor.cpp:338
cloudViewer::core::AdvancedIndexPreprocessor::GetIndexTensors
std::vector< Tensor > GetIndexTensors() const
Definition: AdvancedIndexing.h:31
DLTensor::byte_offset
uint64_t byte_offset
The offset in bytes to the beginning pointer to data.
Definition: DLPack.h:302
cloudViewer::core::Tensor::ConstIterator::operator*
reference operator*() const
Definition: Tensor.cpp:307
cloudViewer::core::Tensor::Iterator::operator++
Iterator & operator++()
Definition: Tensor.cpp:249
DLPack.h
cloudViewer::core::Tensor::GetDataPtr
const T * GetDataPtr() const
Definition: Tensor.h:1149
cloudViewer::core::Tensor
Definition: Tensor.h:32
cloudViewer::core::Tensor::View
Tensor View(const SizeVector &dst_shape) const
Definition: Tensor.cpp:721
cloudViewer::core::Tensor::GetItem
Tensor GetItem(const TensorKey &tk) const
Definition: Tensor.cpp:473
cloudViewer::core::Tensor::Ne_
Tensor Ne_(const Tensor &value)
Definition: Tensor.cpp:1732
cloudViewer::core::Tensor::AsStrided
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:1061
NumpyIO.h
cloudViewer::core::Tensor::Tensor
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
cloudViewer::core::kernel::IndexGet
void IndexGet(const Tensor &src, Tensor &dst, const std::vector< Tensor > &index_tensors, const SizeVector &indexed_shape, const SizeVector &indexed_strides)
Definition: IndexGetSet.cpp:22
cloudViewer::core::Tensor::LogicalNot
Tensor LogicalNot() const
Definition: Tensor.cpp:1442
cloudViewer::core::Tensor::Iterator::Iterator
Iterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:224
cloudViewer::core::Tensor::ConstIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1235
cloudViewer::core::shape_util::WrapDim
int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive)
Wrap around negative dim.
Definition: ShapeUtil.cpp:131
cloudViewer::core::Tensor::operator>=
Tensor operator>=(const Tensor &value) const
Definition: Tensor.h:891
cloudViewer::core::Tensor::operator!=
Tensor operator!=(const Tensor &value) const
Definition: Tensor.h:922
cloudViewer::core::DLDataTypeToDtype
static Dtype DLDataTypeToDtype(const DLDataType &dltype)
Definition: Tensor.cpp:60
cloudViewer::core::Tensor::GetBlob
std::shared_ptr< Blob > GetBlob() const
Definition: Tensor.h:1168
cloudViewer::core::kernel::ReductionOpCode::All
@ All
cloudViewer::core::kernel::BinaryEWOpCode::Gt
@ Gt
core::Tensor::Iterator::Impl::tensor_
Tensor * tensor_
Definition: Tensor.cpp:217
cloudViewer::core::Tensor::operator*
Tensor operator*(const Tensor &value) const
Definition: Tensor.h:659
cloudViewer::core::Tensor::operator/
Tensor operator/(const Tensor &value) const
Definition: Tensor.h:672
cloudViewer::core::Tensor::Tensor
Tensor(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Constructor for creating a contiguous Tensor.
Definition: Tensor.h:37
DLTensor::ndim
int32_t ndim
Number of dimensions.
Definition: DLPack.h:278
cloudViewer::core::Solve
void Solve(const Tensor &A, const Tensor &B, Tensor &X)
Solve AX = B with LU decomposition. A is a square matrix.
Definition: Solve.cpp:22
cloudViewer::core::Tensor::LogicalNot_
Tensor LogicalNot_()
Definition: Tensor.cpp:1448
cloudViewer::core::Dtype
Definition: Dtype.h:21
cloudViewer::core::Tensor::ConstIterator::~ConstIterator
~ConstIterator()
Definition: Tensor.cpp:305
cloudViewer::core::Tensor::Any
Tensor Any(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1789
cloudViewer::core::kernel::UnaryEWOpCode::Exp
@ Exp
DLManagedTensor
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
Definition: DLPack.h:319
cloudViewer::core::AdvancedIndexPreprocessor::GetIndexedShape
SizeVector GetIndexedShape() const
Definition: AdvancedIndexing.h:37
core::Tensor::ConstIterator::Impl
Definition: Tensor.cpp:283
cloudViewer::core::Device::ToString
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
Definition: Device.cpp:89
cloudViewer::core::Tensor::end
ConstIterator end() const
Definition: Tensor.h:1290
cloudViewer::core::kernel::IndexSet
void IndexSet(const Tensor &src, Tensor &dst, const std::vector< Tensor > &index_tensors, const SizeVector &indexed_shape, const SizeVector &indexed_strides)
Definition: IndexGetSet.cpp:52
result
core::Tensor result
Definition: VtkUtils.cpp:76
cloudViewer::core::Tensor::Max
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1275
Solve.h
cloudViewer::core::Tensor::Add_
Tensor Add_(const Tensor &value)
Definition: Tensor.cpp:1117
cloudViewer::core::Tensor::NumDims
int64_t NumDims() const
Definition: Tensor.h:1172
cloudViewer::core::Tensor::FromDLPack
static Tensor FromDLPack(const DLManagedTensor *dlmt, std::function< void(void *)> deleter=nullptr)
Convert DLManagedTensor to Tensor (DLPack v0.x).
Definition: Tensor.cpp:1868
cloudViewer::core::Tensor::Iterator::value_type
Tensor value_type
Definition: Tensor.h:1210
cloudViewer::core::kernel::Copy
void Copy(const Tensor &src, Tensor &dst)
Definition: UnaryEW.cpp:66
cloudViewer::core::Tensor::Iterator::operator!=
bool operator!=(const Iterator &other) const
Definition: Tensor.cpp:265
cloudViewer::core::shape_util::Iota
SizeVector Iota(int64_t n)
Returns a SizeVector of {0, 1, ..., n - 1}, similar to std::iota.
Definition: ShapeUtil.cpp:205
cloudViewer::core::kernel::UnaryEWOpCode::Floor
@ Floor
cloudViewer::core::Tensor::Sub_
Tensor Sub_(const Tensor &value)
Definition: Tensor.cpp:1153
cloudViewer::core::Tensor::Eye
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create an identity matrix of size n x n.
Definition: Tensor.cpp:418
cloudViewer::core::TensorKey::TensorKeyMode::IndexTensor
@ IndexTensor
cloudViewer::core::Device::DeviceType::SYCL
@ SYCL
cloudViewer::core::kernel::UnaryEWOpCode::Round
@ Round
cloudViewer::core::kernel::NonZero
Tensor NonZero(const Tensor &src)
Definition: NonZero.cpp:19
SizeVector.h
cloudViewer::core::Tensor::Arange
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:436
cloudViewer::core::None
constexpr utility::nullopt_t None
Definition: TensorKey.h:20
cloudViewer::core::Tensor::Lt_
Tensor Lt_(const Tensor &value)
Definition: Tensor.cpp:1604
cloudViewer::core::Tensor::Expand
Tensor Expand(const SizeVector &dst_shape) const
Definition: Tensor.cpp:638
cloudViewer::core::Device::IsSYCL
bool IsSYCL() const
Returns true iff device type is SYCL GPU.
Definition: Device.h:52
cloudViewer::core::Triul
void Triul(const Tensor &A, Tensor &upper, Tensor &lower, const int diagonal)
Definition: Tri.cpp:79
cloudViewer::core::Tensor::AsRvalue
const Tensor AsRvalue() const
Convert to constant rvalue.
Definition: Tensor.h:561
Blob.h
cloudViewer::core::Tensor::Iterator
Iterator for Tensor.
Definition: Tensor.h:1207
cloudViewer::core::Tensor::ArgMax
Tensor ArgMax(const SizeVector &dims) const
Definition: Tensor.cpp:1289
cloudViewer::core::Tensor::Cos_
Tensor Cos_()
Element-wise cosine of a tensor, in-place.
Definition: Tensor.cpp:1324
cloudViewer::core::LU
void LU(const Tensor &A, Tensor &permutation, Tensor &lower, Tensor &upper, const bool permute_l)
Definition: LU.cpp:126
cloudViewer::core::Tensor::Zeros
static Tensor Zeros(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with zeros.
Definition: Tensor.cpp:406
cloudViewer::core::Tensor::Sub
Tensor Sub(const Tensor &value) const
Substracts a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1133
DLManagedTensorVersioned
A versioned and managed C Tensor object, manage memory of DLTensor.
Definition: DLPack.h:366
e
const double * e
Definition: essential_matrix_poly.h:10
cloudViewer::core::shape_util::InferShape
SizeVector InferShape(SizeVector shape, int64_t num_elements)
Definition: ShapeUtil.cpp:150
cloudViewer::core::SizeVector::ToString
std::string ToString() const
Definition: SizeVector.cpp:132
cloudViewer::core::Int32
const Dtype Int32
Definition: Dtype.cpp:46
cloudViewer::core::Tensor::Exp_
Tensor Exp_()
Element-wise base-e exponential of a tensor, in-place.
Definition: Tensor.cpp:1346
cloudViewer::core::Tensor::LeastSquares
Tensor LeastSquares(const Tensor &rhs) const
Definition: Tensor.cpp:1938
cloudViewer::core::Tensor::operator==
Tensor operator==(const Tensor &value) const
Definition: Tensor.h:912
cloudViewer::core::UInt64
const Dtype UInt64
Definition: Dtype.cpp:51
cloudViewer::core::Tensor::operator[]
Tensor operator[](int64_t i) const
Extract the i-th Tensor along the first axis, returning a new view.
Definition: Tensor.cpp:839
cloudViewer::core::SizeVector::GetLength
int64_t GetLength() const
Definition: SizeVector.cpp:124
cloudViewer::core::kernel::ReductionOpCode::Any
@ Any
Dispatch.h
cloudViewer::core::Tensor::Inverse
Tensor Inverse() const
Definition: Tensor.cpp:1982
cloudViewer::core::Tensor::SetItem
Tensor SetItem(const Tensor &value)
Set all items. Equivalent to tensor[:] = value in Python.
Definition: Tensor.cpp:564
cloudViewer::core::Tensor::AllClose
bool AllClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1895
cloudViewer::core::Tensor::Iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1208
cloudViewer::core::Tensor::T
Tensor T() const
Expects input to be <= 2-D Tensor by swapping dimension 0 and 1.
Definition: Tensor.cpp:1079
cloudViewer::core::Tensor::LU
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:1948
cloudViewer::core::Tensor::Le_
Tensor Le_(const Tensor &value)
Definition: Tensor.cpp:1668
cloudViewer::core::Tensor::Tensor
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
cloudViewer::core::Device
Definition: Device.h:18
Tri.h
cloudViewer::core::Tensor::GetShapeRef
const SizeVector & GetShapeRef() const
Definition: Tensor.h:1129
cloudViewer::core::TensorKey::TensorKeyMode::Index
@ Index
cloudViewer::core::operator+
Tensor operator+(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1417
cloudViewer::core::Tensor::strides_
SizeVector strides_
Definition: Tensor.h:1318
cloudViewer::core::kernel::ReductionOpCode::Max
@ Max
DLDataType::code
uint8_t code
Type code of base types. We keep it uint8_t instead of DLDataTypeCode for minimal memory footprint,...
Definition: DLPack.h:232
cloudViewer::core::Tensor::IsNan
Tensor IsNan() const
Definition: Tensor.cpp:1362
LU.h
cloudViewer::core::Tensor::Triul
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:1976
cloudViewer::core::Tensor::cend
ConstIterator cend() const
Definition: Tensor.cpp:345
TensorCheck.h
cloudViewer::core::Tensor::Iterator::~Iterator
~Iterator()
Definition: Tensor.cpp:238
cloudViewer::core::Tensor::IndexGet
Tensor IndexGet(const std::vector< Tensor > &index_tensors) const
Advanced indexing getter. This will always allocate a new Tensor.
Definition: Tensor.cpp:905
cloudViewer::core::AdvancedIndexPreprocessor
This class is based on PyTorch's aten/src/ATen/native/Indexing.cpp.
Definition: AdvancedIndexing.h:21
cloudViewer::core::Tensor::Exp
Tensor Exp() const
Element-wise exponential of a tensor, returning a new tensor.
Definition: Tensor.cpp:1340
cloudViewer::core::kernel::Arange
Tensor Arange(const Tensor &start, const Tensor &stop, const Tensor &step)
Definition: Arange.cpp:17
cloudViewer::core::kernel::ReductionOpCode::Prod
@ Prod
cloudViewer::core::UInt8
const Dtype UInt8
Definition: Dtype.cpp:48
DLTensor::strides
int64_t * strides
strides of the tensor (in number of elements, not bytes), can not be NULL if ndim !...
Definition: DLPack.h:300
cloudViewer::t::io::WriteNpy
void WriteNpy(const std::string &file_name, const core::Tensor &tensor)
Definition: NumpyIO.cpp:671
core
cloudViewer::core::Bool
const Dtype Bool
Definition: Dtype.cpp:52
cloudViewer::core::Dtype::ToString
std::string ToString() const
Definition: Dtype.h:65
cloudViewer::core::Tensor::ConstIterator::difference_type
std::ptrdiff_t difference_type
Definition: Tensor.h:1236
cloudViewer::core::Tensor::blob_
std::shared_ptr< Blob > blob_
Underlying memory buffer for Tensor.
Definition: Tensor.h:1339
cloudViewer::core::Tensor::GetDataPtr
void * GetDataPtr()
Definition: Tensor.h:1160
cloudViewer::core::Tensor::AllEqual
bool AllEqual(const Tensor &other) const
Definition: Tensor.cpp:1885
cloudViewer::core::Tensor::operator*=
Tensor operator*=(Scalar value)
Definition: Tensor.h:667
cloudViewer::core::Tensor::Matmul
Tensor Matmul(const Tensor &rhs) const
Definition: Tensor.cpp:1919
cloudViewer::core::Float64
const Dtype Float64
Definition: Dtype.cpp:43
DLDataType::bits
uint8_t bits
Number of bits, common choices are 8, 16, 32.
Definition: DLPack.h:236
cloudViewer::core::Tensor::begin
ConstIterator begin() const
Definition: Tensor.h:1284
cloudViewer::core::Tensor::operator&&
Tensor operator&&(const Tensor &value) const
Definition: Tensor.h:822
cloudViewer::core::Append
Tensor Append(const Tensor &self, const Tensor &other, const utility::optional< int64_t > &axis)
Appends the two tensors, along the given axis into a new tensor. Both the tensors must have same data...
Definition: TensorFunction.cpp:118
cloudViewer::core::Inverse
void Inverse(const Tensor &A, Tensor &output)
Computes A^{-1} with LU factorization, where A is a N x N square matrix.
Definition: Inverse.cpp:18
cloudViewer::core::Tensor::Iterator::difference_type
std::ptrdiff_t difference_type
Definition: Tensor.h:1209
cloudViewer::core::Tensor::ConstIterator::operator!=
bool operator!=(const ConstIterator &other) const
Definition: Tensor.cpp:333
cloudViewer::core::Tensor::GetDevice
Device GetDevice() const override
Definition: Tensor.cpp:1435
cloudViewer::core::Tensor::Flatten
Tensor Flatten(int64_t start_dim=0, int64_t end_dim=-1) const
Definition: Tensor.cpp:685
cloudViewer::core::Scalar::To
T To() const
To<T>() does not check for scalar type and overflows.
Definition: Scalar.h:128
cloudViewer::core::Tensor::ToDLPackVersioned
DLManagedTensorVersioned * ToDLPackVersioned() const
Convert the Tensor to DLManagedTensorVersioned (DLPack v1.x).
Definition: Tensor.cpp:1811
cloudViewer::core::Tensor::CopyFrom
void CopyFrom(const Tensor &other)
Copy Tensor values to current tensor from the source tensor.
Definition: Tensor.cpp:770
cloudViewer::core::Tensor::operator||
Tensor operator||(const Tensor &value) const
Definition: Tensor.h:839
cloudViewer::core::operator/
Tensor operator/(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1432
cloudViewer::core::Tensor::ArgMin
Tensor ArgMin(const SizeVector &dims) const
Definition: Tensor.cpp:1282
cloudViewer::core::AdvancedIndexPreprocessor::GetIndexedStrides
SizeVector GetIndexedStrides() const
Definition: AdvancedIndexing.h:39
cloudViewer::core::LUIpiv
void LUIpiv(const Tensor &A, Tensor &ipiv, Tensor &output)
Definition: LU.cpp:62
DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE,...)
Definition: Dispatch.h:68
cloudViewer::core::TensorKey::GetStep
int64_t GetStep() const
Definition: TensorKey.cpp:170
cloudViewer::core::Tensor::Eq_
Tensor Eq_(const Tensor &value)
Definition: Tensor.cpp:1700
cloudViewer::core::Tensor::Abs_
Tensor Abs_()
Element-wise absolute value of a tensor, in-place.
Definition: Tensor.cpp:1357
cloudViewer::core::Tensor::Div_
Tensor Div_(const Tensor &value)
Definition: Tensor.cpp:1225
cloudViewer::core::Tensor::ConstIterator::value_type
const Tensor value_type
Definition: Tensor.h:1237
cloudViewer::core::kernel::UnaryEWOpCode::LogicalNot
@ LogicalNot
cloudViewer::core::TensorKey::GetIndex
int64_t GetIndex() const
Definition: TensorKey.cpp:148
cloudViewer::core::Tensor::Broadcast
Tensor Broadcast(const SizeVector &dst_shape) const
Broadcast Tensor to a new broadcastable shape.
Definition: Tensor.cpp:628
cloudViewer::core::Float32
const Dtype Float32
Definition: Dtype.cpp:42
cloudViewer::core::SizeVector::NumElements
int64_t NumElements() const
Definition: SizeVector.cpp:108
kDLOneAPI
@ kDLOneAPI
Unified shared memory allocated on a oneAPI non-partititioned device. Call to oneAPI runtime is requi...
Definition: DLPack.h:132
cloudViewer::core::SizeVector
Definition: SizeVector.h:70
cloudViewer::core::Tensor::Tensor
Tensor()
Definition: Tensor.h:34
cloudViewer::core::kernel::BinaryEWOpCode::Sub
@ Sub
cloudViewer::core::Undefined
const Dtype Undefined
Definition: Dtype.cpp:41
DLTensor::dtype
DLDataType dtype
The data type of the pointer.
Definition: DLPack.h:280
IndexReduction.h
kDLCUDA
@ kDLCUDA
CUDA GPU device.
Definition: DLPack.h:97
cloudViewer::core::Tensor::Mul_
Tensor Mul_(const Tensor &value)
Definition: Tensor.cpp:1189
cloudViewer::core::Open3DDLManagedTensor::getDLPackDevice
static DLDevice getDLPackDevice(const Tensor &o3d_tensor)
Definition: Tensor.cpp:187
cloudViewer::core::Tensor::IndexAdd_
void IndexAdd_(int64_t dim, const Tensor &index, const Tensor &src)
Advanced in-place reduction by index.
Definition: Tensor.cpp:991
cloudViewer::core::Device::GetID
int GetID() const
Returns the device index (within the same device type).
Definition: Device.h:61
cloudViewer::core::Tensor::AssignObject
Tensor & AssignObject(const Object &v) &&
Definition: Tensor.h:220
cloudViewer::core::Tensor::Load
static Tensor Load(const std::string &file_name)
Load tensor from numpy's npy format.
Definition: Tensor.cpp:1881
cloudViewer::core::kernel::BinaryEWOpCode::Ge
@ Ge
cloudViewer::core::kernel::UnaryEWOpCode::Abs
@ Abs
cloudViewer::core::Tensor::ConstIterator::ConstIterator
ConstIterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:291
cloudViewer::core::Tensor::Init
static Tensor Init(const std::initializer_list< T > &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:285
cloudViewer::core::Open3DDLManagedTensor::Create
static DLMT * Create(const Tensor &o3d_tensor)
Definition: Tensor.cpp:181
cloudViewer::core::Tensor::operator+=
Tensor operator+=(Scalar value)
Definition: Tensor.h:641
cloudViewer::core::Matmul
void Matmul(const Tensor &A, const Tensor &B, Tensor &output)
Computes matrix multiplication C = AB.
Definition: Matmul.cpp:17
cloudViewer::utility::optional< int64_t >
cloudViewer::core::kernel::BinaryEWOpCode::Eq
@ Eq
LogError
#define LogError(...)
Definition: Logging.h:60
DISPATCH_DTYPE_TO_TEMPLATE
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:31
cloudViewer::core::TensorKey::TensorKeyMode::Slice
@ Slice
cloudViewer::core::Tensor::NonZeroNumpy
std::vector< Tensor > NonZeroNumpy() const
Definition: Tensor.cpp:1746
cloudViewer::core::Tensor::operator*=
Tensor operator*=(const Tensor &value)
Definition: Tensor.h:666
cloudViewer::core::tensor_init::InferShape
SizeVector InferShape(const L &list)
Definition: TensorInit.h:82
cloudViewer::core::Tensor::Lt
Tensor Lt(const Tensor &value) const
Element-wise less-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1586
cloudViewer::core::TensorKey::Slice
static TensorKey Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Definition: TensorKey.cpp:138
cloudViewer::core::kernel::BinaryEWOpCode::Ne
@ Ne
core::Tensor::ConstIterator::Impl::index_
int64_t index_
Definition: Tensor.cpp:285
cloudViewer::core::shape_util::CanBeBrocastedToShape
bool CanBeBrocastedToShape(const SizeVector &src_shape, const SizeVector &dst_shape)
Returns true if src_shape can be brocasted to dst_shape.
Definition: ShapeUtil.cpp:90
cloudViewer::core::Tensor::end
Iterator end()
Definition: Tensor.cpp:276
cloudViewer::core::Blob
Definition: Blob.h:38
cloudViewer::core::kernel::BinaryEWOpCode::Mul
@ Mul
cloudViewer::core::Tensor::operator/
Tensor operator/(Scalar value) const
Definition: Tensor.h:673
DLTensor::device
DLDevice device
The device of the tensor.
Definition: DLPack.h:276
cloudViewer::core::operator-
Tensor operator-(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1422
cloudViewer::core::kernel::UnaryEWOpCode::Sqrt
@ Sqrt
cloudViewer::core::Tensor::ToDLPack
DLManagedTensor * ToDLPack() const
Convert the Tensor to DLManagedTensor (DLPack v0.x).
Definition: Tensor.cpp:1808
cloudViewer::core::Tensor::Item
T Item() const
Definition: Tensor.h:618
cloudViewer::core::Tensor::Tensor
Tensor(std::vector< T > &&vec, const SizeVector &shape={})
Take ownership of data in std::vector<T>
Definition: Tensor.h:117
cloudViewer::core::Tensor::operator+
Tensor operator+(Scalar value) const
Definition: Tensor.h:634
DLDeviceType
DLDeviceType
The device type in DLDevice.
Definition: DLPack.h:92
cloudViewer::core::Tensor::AssertTemplateDtype
void AssertTemplateDtype() const
Definition: Tensor.h:1175
cloudViewer::core::Tensor::Round
Tensor Round() const
Element-wise round value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1423
cloudViewer::core::Tensor::GetStrides
SizeVector GetStrides() const
Definition: Tensor.h:1135
cloudViewer::core::Scalar::AssertSameScalarType
void AssertSameScalarType(Scalar other, const std::string &error_msg) const
Definition: Scalar.h:140
cloudViewer::core::kernel::BinaryEWOpCode::Add
@ Add
AssertTensorDtype
#define AssertTensorDtype(tensor,...)
Definition: TensorCheck.h:21
cloudViewer::core::TensorKey
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
Definition: TensorKey.h:26
DLManagedTensorVersioned::version
DLPackVersion version
The API and ABI version of the current managed Tensor.
Definition: DLPack.h:370
cloudViewer::core::Tensor::operator-=
Tensor operator-=(Scalar value)
Definition: Tensor.h:654
std
Definition: Eigen.h:85
cloudViewer::core::Tensor::operator=
Tensor & operator=(const T v) &&
Definition: Tensor.h:205
cloudViewer::core::Triu
void Triu(const Tensor &A, Tensor &output, const int diagonal)
Definition: Tri.cpp:35
DLTensor::data
void * data
The data pointer points to the allocated data. This will be CUDA device pointer or cl_mem handle in O...
Definition: DLPack.h:274
cloudViewer::core::Tensor::ToString
std::string ToString(bool with_suffix=true, const std::string &indent="") const
Definition: Tensor.cpp:780
cloudViewer::core::kernel::UnaryEWOpCode::Neg
@ Neg
DLPACK_MAJOR_VERSION
#define DLPACK_MAJOR_VERSION
The current major version of dlpack.
Definition: DLPack.h:37
cloudViewer::core::Tensor::GetDataPtr
const void * GetDataPtr() const
Definition: Tensor.h:1162
cloudViewer::core::tensor_init::NestedInitializerList
typename NestedInitializerImpl< T, D >::type NestedInitializerList
Definition: TensorInit.h:36
cloudViewer::core::Tensor::Empty
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:400
cloudViewer::core::Scalar
Definition: Scalar.h:24
cloudViewer::core::TensorKey::GetMode
TensorKeyMode GetMode() const
Returns TensorKey mode.
Definition: TensorKey.cpp:130
cloudViewer::core::Tensor::Sin
Tensor Sin() const
Element-wise sine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1307
cloudViewer::core::Tensor::NumElements
int64_t NumElements() const
Definition: Tensor.h:1170
cloudViewer::core::Tensor::Sqrt_
Tensor Sqrt_()
Element-wise square root of a tensor, in-place.
Definition: Tensor.cpp:1302
cloudViewer::core::Tensor::Init
static Tensor Init(const T val, const Device &device=Device("CPU:0"))
Definition: Tensor.h:275
cloudViewer::utility::nullopt
constexpr nullopt_t nullopt
Definition: Optional.h:136
Tensor.h
kDLUInt
@ kDLUInt
unsigned integer
Definition: DLPack.h:164
cloudViewer::core::Tensor::Min
Tensor Min(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1268
cloudViewer::core::Int8
const Dtype Int8
Definition: Dtype.cpp:44
cloudViewer::core::Tensor::Ne
Tensor Ne(const Tensor &value) const
Element-wise not-equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1714
cloudViewer::core::Scalar::Equal
bool Equal(T value) const
Definition: Scalar.h:172
cloudViewer::core::shape_util::DefaultStrides
SizeVector DefaultStrides(const SizeVector &shape)
Compute default strides for a shape when a tensor is contiguous.
Definition: ShapeUtil.cpp:214
cloudViewer::core::Tensor::shape_
SizeVector shape_
SizeVector of the Tensor. shape_[i] is the length of dimension i.
Definition: Tensor.h:1309
cloudViewer::core::kernel::ReductionOpCode::ArgMin
@ ArgMin
cloudViewer::core::Tensor::Transpose
Tensor Transpose(int64_t dim0, int64_t dim1) const
Transpose a Tensor by swapping dimension dim0 and dim1.
Definition: Tensor.cpp:1068
cloudViewer::core::Tensor::Iterator::operator*
reference operator*() const
Definition: Tensor.cpp:240
cloudViewer::core::kernel::UnaryEWOpCode::Trunc
@ Trunc
LogWarning
#define LogWarning(...)
Definition: Logging.h:72
cloudViewer::core::Tensor::NonZero
Tensor NonZero() const
Definition: Tensor.cpp:1755
cloudViewer::core::Tensor::IsFinite
Tensor IsFinite() const
Definition: Tensor.cpp:1382
cloudViewer::core::Tensor::Sum
Tensor Sum(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1240
kDLInt
@ kDLInt
signed integer
Definition: DLPack.h:162
DLPackVersion::major
uint32_t major
DLPack major version.
Definition: DLPack.h:81
cloudViewer::core::Tensor::dtype_
Dtype dtype_
Data type.
Definition: Tensor.h:1336
cloudViewer::core::Tensor::Ge
Tensor Ge(const Tensor &value) const
Definition: Tensor.cpp:1618
cloudViewer::core::Tensor::Full
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
cloudViewer::core::IsDevice::IsSYCL
bool IsSYCL() const
Definition: Device.h:103
cloudViewer::core::Dtype::IsObject
bool IsObject() const
Definition: Dtype.h:63
cloudViewer::core::Tensor::AsRvalue
Tensor AsRvalue()
Definition: Tensor.h:558
cloudViewer::core::Tensor::LogicalXor_
Tensor LogicalXor_(const Tensor &value)
Definition: Tensor.cpp:1539
cloudViewer::core::Tensor::ConstIterator::operator->
pointer operator->() const
Definition: Tensor.cpp:311
cloudViewer::core::Tensor::data_ptr_
void * data_ptr_
Definition: Tensor.h:1333
cloudViewer::core::Tensor::Gt
Tensor Gt(const Tensor &value) const
Element-wise greater-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1554
cloudViewer::core::Tensor::begin
Iterator begin()
Definition: Tensor.cpp:269
cloudViewer::core::Tensor::operator-=
Tensor operator-=(const Tensor &value)
Definition: Tensor.h:653
Matmul.h
cloudViewer::core::Tensor::Triu
Tensor Triu(const int diagonal=0) const
Returns the upper triangular matrix of the 2D tensor, above the given diagonal index....
Definition: Tensor.cpp:1964
cloudViewer::core::Tensor::operator=
Tensor & operator=(const Tensor &other) &
Definition: Tensor.cpp:355
cloudViewer::core::Open3DDLManagedTensor::Deleter
static void Deleter(DLMT *arg)
Definition: Tensor.cpp:208
LeastSquares.h
DLDataTypeCode
DLDataTypeCode
The type code options DLDataType.
Definition: DLPack.h:160
cloudViewer::core::kernel::BinaryEW
void BinaryEW(const Tensor &lhs, const Tensor &rhs, Tensor &dst, BinaryEWOpCode op_code)
Definition: BinaryEW.cpp:30
cloudViewer::core::DtypeToDLDataTypeCode
static DLDataTypeCode DtypeToDLDataTypeCode(const Dtype &dtype)
Definition: Tensor.cpp:44
cloudViewer::core::Det
double Det(const Tensor &A)
Definition: Det.cpp:16
cloudViewer::core::IsDevice
Definition: Device.h:88
cloudViewer::core::Tensor::Eq
Tensor Eq(const Tensor &value) const
Element-wise equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1682
cloudViewer::core::Tensor::LogicalAnd_
Tensor LogicalAnd_(const Tensor &value)
Definition: Tensor.cpp:1472
cloudViewer::core::Tensor::GetStride
int64_t GetStride(int64_t dim) const
Definition: Tensor.h:1139
cloudViewer::core::kernel::BinaryEWOpCode::Le
@ Le
cloudViewer::core::Tensor::Trunc
Tensor Trunc() const
Element-wise trunc value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1429
cloudViewer::core::Device::DeviceType::CUDA
@ CUDA
DLDataType::lanes
uint16_t lanes
Number of lanes in the type, used for vector types.
Definition: DLPack.h:238
cloudViewer::core::Tensor::All
Tensor All(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1770
cloudViewer::core::Tensor::Abs
Tensor Abs() const
Element-wise absolute value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1351
DLTensor
Plain C Tensor object, does not manage memory.
Definition: DLPack.h:244
cloudViewer::core::kernel::UnaryEWOpCode::Cos
@ Cos
cloudViewer::core::Tensor::Append
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:622
cloudViewer::core::Tensor::operator/=
Tensor operator/=(Scalar value)
Definition: Tensor.h:680
cloudViewer::core::Tensor::Tril
Tensor Tril(const int diagonal=0) const
Returns the lower triangular matrix of the 2D tensor, above the given diagonal index....
Definition: Tensor.cpp:1970
cloudViewer::core::Tensor::Solve
Tensor Solve(const Tensor &rhs) const
Definition: Tensor.cpp:1928
core::Tensor::Iterator::Impl
Definition: Tensor.cpp:216
cloudViewer::core::Tensor::GetStridesRef
const SizeVector & GetStridesRef() const
Definition: Tensor.h:1137
AssertTensorShape
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:61
cloudViewer::core::MemoryManager::MemcpyToHost
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:86
cloudViewer::core::Device::GetType
DeviceType GetType() const
Returns type of the device, e.g. DeviceType::CPU, DeviceType::CUDA.
Definition: Device.h:58
cloudViewer::core::Tensor::LogicalXor
Tensor LogicalXor(const Tensor &value) const
Definition: Tensor.cpp:1520
core::Tensor::ConstIterator::Impl::tensor_
const Tensor * tensor_
Definition: Tensor.cpp:284
cloudViewer::core::Tensor::FromDLPackVersioned
static Tensor FromDLPackVersioned(const DLManagedTensorVersioned *dlmt, std::function< void(void *)> deleter=nullptr)
Convert DLManagedTensorVersioned to Tensor (DLPack v1.x).
Definition: Tensor.cpp:1872
cloudViewer::core::kernel::ReductionOpCode::ArgMax
@ ArgMax
cloudViewer::core::MemoryManager::MemcpyFromHost
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:78
cloudViewer::core::Tensor::Cos
Tensor Cos() const
Element-wise cosine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1318
cloudViewer::core::Tensor::Iterator::operator==
bool operator==(const Iterator &other) const
Definition: Tensor.cpp:260
cloudViewer::core::LeastSquares
void LeastSquares(const Tensor &A, const Tensor &B, Tensor &X)
Solve AX = B with QR decomposition. A is a full-rank m x n matrix (m >= n).
Definition: LeastSquares.cpp:17
TensorKey.h
cloudViewer::core::Tensor::LogicalOr_
Tensor LogicalOr_(const Tensor &value)
Definition: Tensor.cpp:1506
cloudViewer::core::Tensor::LogicalAnd
Tensor LogicalAnd(const Tensor &value) const
Definition: Tensor.cpp:1453
cloudViewer::core::Tensor::ConstIterator
Const iterator for Tensor.
Definition: Tensor.h:1234
AssertTensorDtypes
#define AssertTensorDtypes(tensor,...)
Definition: TensorCheck.h:33
cloudViewer::core::Tensor::ToFlatVector
std::vector< T > ToFlatVector() const
Retrieve all values as an std::vector, for debugging and testing.
Definition: Tensor.h:1025
core::Tensor::Iterator::Impl::index_
int64_t index_
Definition: Tensor.cpp:218
DLTensor::shape
int64_t * shape
The shape of the tensor.
Definition: DLPack.h:286
DLPackVersion::minor
uint32_t minor
DLPack minor version.
Definition: DLPack.h:83
DLDevice
A Device for Tensor and operator.
Definition: DLPack.h:146
cloudViewer::core::Tensor::Div
Tensor Div(const Tensor &value) const
Divides a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1205
cloudViewer::core::Tensor::Clip_
Tensor Clip_(Scalar min_val, Scalar max_val)
Definition: Tensor.cpp:1398
cloudViewer::core::Tensor::operator>
Tensor operator>(const Tensor &value) const
Definition: Tensor.h:870
cloudViewer::core::kernel::UnaryEW
void UnaryEW(const Tensor &src, Tensor &dst, UnaryEWOpCode op_code)
Definition: UnaryEW.cpp:19
cloudViewer::core::Tensor::Iterator::operator->
pointer operator->() const
Definition: Tensor.cpp:244
cloudViewer::core::Int64
const Dtype Int64
Definition: Dtype.cpp:47
type
char type
Definition: FileIOFactory.cpp:131
Det.h
cloudViewer::core::kernel::BinaryEWOpCode::LogicalOr
@ LogicalOr
cloudViewer::core::Tensor::IsNonZero
bool IsNonZero() const
Definition: Tensor.cpp:1757
cloudViewer::core::Tensor::LUIpiv
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:1956
cloudViewer::core::Tensor::Gt_
Tensor Gt_(const Tensor &value)
Definition: Tensor.cpp:1572
cloudViewer::t::io::ReadNpy
core::Tensor ReadNpy(const std::string &file_name)
Definition: NumpyIO.cpp:662
cloudViewer::core::Tensor::Neg
Tensor Neg() const
Element-wise negation of a tensor, returning a new tensor.
Definition: Tensor.cpp:1329
Dtype.h
cloudViewer::core::Tensor::To
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:739
cloudViewer::core::Tensor::GetShape
int64_t GetShape(int64_t dim) const
Definition: Tensor.h:1131
cloudViewer::core::kernel::UnaryEWOpCode::IsNan
@ IsNan
cloudViewer::core::Tensor::IsClose
Tensor IsClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1900
cloudViewer::core::Tensor::Le
Tensor Le(const Tensor &value) const
Definition: Tensor.cpp:1650
cloudViewer::core::Tensor::operator/=
Tensor operator/=(const Tensor &value)
Definition: Tensor.h:679
cloudViewer::core::Tensor::Prod
Tensor Prod(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1261
cloudViewer::core::Tensor::Ge_
Tensor Ge_(const Tensor &value)
Definition: Tensor.cpp:1636
cloudViewer::core::Tensor::LogicalOr
Tensor LogicalOr(const Tensor &value) const
Definition: Tensor.cpp:1487
cloudViewer::core::Tensor::Clip
Tensor Clip(Scalar min_val, Scalar max_val) const
Definition: Tensor.cpp:1392
cloudViewer::core::Tensor::IsInf
Tensor IsInf() const
Definition: Tensor.cpp:1372
cloudViewer::core::Tensor::GetDataPtr
T * GetDataPtr()
Definition: Tensor.h:1144
cloudViewer::core::SVD
void SVD(const Tensor &A, Tensor &U, Tensor &S, Tensor &VT)
Definition: SVD.cpp:17
cloudViewer::core::kernel::ReductionOpCode::Min
@ Min
cloudViewer::core::kernel::BinaryEWOpCode::Lt
@ Lt
cloudViewer::core::kernel::BinaryEWOpCode::LogicalAnd
@ LogicalAnd
cloudViewer::core::Tensor::Floor
Tensor Floor() const
Element-wise floor value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1411
cloudViewer::core::kernel::UnaryEWOpCode::IsInf
@ IsInf
TensorFunction.h