14 #include <type_traits>
50 Tensor(
const std::vector<T>& init_vals,
54 :
Tensor(shape, dtype, device) {
58 "Tensor initialization values' size {} does not match the "
64 AssertTemplateDtype<T>();
65 if (!std::is_pod<T>()) {
72 init_vals.size() * dtype.
ByteSize());
81 :
Tensor(shape, dtype, device) {
83 AssertTemplateDtype<T>();
98 const std::shared_ptr<Blob>& blob)
115 template <
typename T>
119 shape_ = {
static_cast<int64_t
>(vec.size())};
125 "Tensor initialization values' size {} does not match the "
130 auto sp_vec = std::make_shared<std::vector<T>>();
132 data_ptr_ =
static_cast<void*
>(sp_vec->data());
138 [sp_vec](
void*) { (
void)sp_vec; });
171 blob_ = std::make_shared<Blob>(device, (
void*)
data_ptr_, [](
void*) {});
203 template <
typename T>
218 template <
typename Object>
222 "Assignment with scalar only works for scalar Tensor of "
225 AssertTemplateDtype<Object>();
233 template <
typename S>
236 template <
typename Object>
251 template <
typename T>
273 template <
typename T>
276 std::vector<T> ele_list{val};
283 template <
typename T>
286 return InitWithInitializerList<T, 1>(in_list, device);
291 template <
typename T>
293 const std::initializer_list<std::initializer_list<T>>& in_list,
295 return InitWithInitializerList<T, 2>(in_list, device);
300 template <
typename T>
302 const std::initializer_list<
303 std::initializer_list<std::initializer_list<T>>>& in_list,
305 return InitWithInitializerList<T, 3>(in_list, device);
478 Tensor Flatten(int64_t start_dim = 0, int64_t end_dim = -1)
const;
526 std::string
ToString(
bool with_suffix =
true,
527 const std::string& indent =
"")
const;
545 int64_t step = 1)
const;
575 void IndexSet(
const std::vector<Tensor>& index_tensors,
576 const Tensor& src_tensor);
606 template <
typename T>
610 "Tensor::Item() only works for Tensor with exactly one "
613 AssertTemplateDtype<T>();
944 bool keepdim =
false)
const;
949 bool keepdim =
false)
const;
983 double atol = 1e-8)
const;
1005 double atol = 1e-8)
const;
1013 template <
typename T>
1015 AssertTemplateDtype<T>();
1053 std::tuple<Tensor, Tensor, Tensor>
LU(
const bool permute_l =
false)
const;
1067 std::tuple<Tensor, Tensor>
LUIpiv()
const;
1102 std::tuple<Tensor, Tensor>
Triul(
const int diagonal = 0)
const;
1110 std::tuple<Tensor, Tensor, Tensor>
SVD()
const;
1132 template <
typename T>
1134 return const_cast<T*
>(
const_cast<const Tensor*
>(
this)->GetDataPtr<T>());
1137 template <
typename T>
1141 "Requested values have type {} but Tensor has type {}. "
1142 "Please use non templated GetDataPtr() with manual "
1163 template <
typename T>
1167 "Requested values have type {} but Tensor has type {}",
1183 void Save(
const std::string& file_name)
const;
1186 static Tensor Load(
const std::string& file_name);
1212 std::unique_ptr<Impl> impl_;
1239 std::unique_ptr<Impl> impl_;
1279 template <
typename T,
size_t D>
1280 static Tensor InitWithInitializerList(
1284 std::vector<T> values =
1285 tensor_init::ToFlatVector<T, D>(shape, nested_list);
1286 return Tensor(values, shape, Dtype::FromType<T>(), device);
1329 :
Tensor(shape, dtype, device) {
1333 "Tensor initialization values' size {} does not match the "
1339 AssertTemplateDtype<bool>();
1343 std::vector<uint8_t> init_vals_uchar(init_vals.size());
1344 std::transform(init_vals.begin(), init_vals.end(), init_vals_uchar.begin(),
1345 [](
bool v) -> uint8_t { return static_cast<uint8_t>(v); });
1348 init_vals_uchar.data(),
1349 init_vals_uchar.size() * dtype.
ByteSize());
1354 AssertTemplateDtype<bool>();
1363 std::transform(values_uchar.begin(), values_uchar.end(), values.begin(),
1364 [](uint8_t v) ->
bool { return static_cast<bool>(v); });
1372 "Tensor::Item only works for Tensor with one element.");
1374 AssertTemplateDtype<bool>();
1378 return static_cast<bool>(value);
1381 template <
typename S>
1384 scalar_t casted_v =
static_cast<scalar_t
>(v);
1391 template <
typename Object>
1398 template <
typename T>
1400 return rhs + scalar_lhs;
1403 template <
typename T>
1408 template <
typename T>
1410 return rhs * scalar_lhs;
1413 template <
typename T>
The common header of DLPack.
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE,...)
Definition: Dispatch.h:67
#define LogError(...)
Definition: Logging.h:48
bool copy
Definition: VtkUtils.cpp:73
std::string ToString() const
Definition: Dtype.h:64
bool IsObject() const
Definition: Dtype.h:62
int64_t ByteSize() const
Definition: Dtype.h:58
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: 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
Tensor operator*(Scalar value) const
Definition: Tensor.h:649
Tensor Clone() const
Copy Tensor to the same device.
Definition: Tensor.h:501
T * GetDataPtr()
Definition: Tensor.h:1133
SizeVector strides_
Definition: Tensor.h:1300
Tensor NonZero() const
Definition: Tensor.cpp:1685
Tensor Neg() const
Element-wise negation of a tensor, returning a new tensor.
Definition: Tensor.cpp:1259
const SizeVector & GetStridesRef() const
Definition: Tensor.h:1126
const T * GetDataPtr() const
Definition: Tensor.h:1138
Tensor Ge_(const Tensor &value)
Definition: Tensor.cpp:1566
int64_t GetShape(int64_t dim) const
Definition: Tensor.h:1120
Tensor LogicalNot() const
Definition: Tensor.cpp:1372
Tensor LogicalXor_(const Tensor &value)
Definition: Tensor.cpp:1469
Tensor operator*=(Scalar value)
Definition: Tensor.h:656
Tensor Exp() const
Element-wise exponential of a tensor, returning a new tensor.
Definition: Tensor.cpp:1270
static Tensor Init(const std::initializer_list< T > &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:284
std::vector< T > ToFlatVector() const
Retrieve all values as an std::vector, for debugging and testing.
Definition: Tensor.h:1014
Tensor Flatten(int64_t start_dim=0, int64_t end_dim=-1) const
Definition: Tensor.cpp:652
std::vector< Tensor > NonZeroNumpy() const
Definition: Tensor.cpp:1676
Tensor LeastSquares(const Tensor &rhs) const
Definition: Tensor.cpp:1847
Tensor operator&&(const Tensor &value) const
Definition: Tensor.h:811
Tensor Ge(const Tensor &value) const
Definition: Tensor.cpp:1548
bool AllClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1804
ConstIterator cend() const
Definition: Tensor.cpp:312
double Det() const
Compute the determinant of a 2D square tensor.
Definition: Tensor.cpp:1022
Tensor All(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1700
Tensor & operator=(const T v) &&
Definition: Tensor.h:204
std::string ScalarPtrToString(const void *ptr) const
Definition: Tensor.cpp:792
Tensor SetItem(const Tensor &value)
Set all items. Equivalent to tensor[:] = value in Python.
Definition: Tensor.cpp:531
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:367
Tensor Cos() const
Element-wise cosine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1248
Tensor operator||(const Tensor &value) const
Definition: Tensor.h:828
Tensor IndexExtract(int64_t dim, int64_t idx) const
Definition: Tensor.cpp:808
Tensor Sin() const
Element-wise sine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1237
Tensor(Tensor &&other)=default
Tensor Floor() const
Element-wise floor value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1341
Tensor Inverse() const
Definition: Tensor.cpp:1891
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:1382
Tensor & AssignObject(const Object &v) &&
Definition: Tensor.h:219
Tensor Sum(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1170
Tensor Gt_(const Tensor &value)
Definition: Tensor.cpp:1502
Tensor LogicalAnd(const Tensor &value) const
Definition: Tensor.cpp:1383
static Tensor Ones(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with ones.
Definition: Tensor.cpp:379
Tensor Lt_(const Tensor &value)
Definition: Tensor.cpp:1534
Tensor IsClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1809
Tensor(const Tensor &other)=default
Tensor Le(const Tensor &value) const
Definition: Tensor.cpp:1580
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:403
SizeVector GetShape() const
Definition: Tensor.h:1116
Tensor LogicalOr_(const Tensor &value)
Definition: Tensor.cpp:1436
int64_t GetLength() const
Definition: Tensor.h:1114
Tensor & operator=(const Tensor &other) &
Definition: Tensor.cpp:322
Tensor LogicalOr(const Tensor &value) const
Definition: Tensor.cpp:1417
Iterator end()
Definition: Tensor.cpp:243
Tensor operator+=(Scalar value)
Definition: Tensor.h:630
Tensor Sub(const Tensor &value) const
Substracts a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1063
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:991
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:161
const void * GetDataPtr() const
Definition: Tensor.h:1151
std::tuple< Tensor, Tensor, Tensor > SVD() const
Definition: Tensor.cpp:1899
Tensor Add_(const Tensor &value)
Definition: Tensor.cpp:1047
Tensor ArgMin(const SizeVector &dims) const
Definition: Tensor.cpp:1212
Tensor Tril(const int diagonal=0) const
Returns the lower triangular matrix of the 2D tensor, above the given diagonal index....
Definition: Tensor.cpp:1879
void Save(const std::string &file_name) const
Save tensor to numpy's npy format.
Definition: Tensor.cpp:1786
Tensor Reverse() const
Reverse a Tensor's elements by viewing the tensor as a 1D array.
Definition: Tensor.cpp:432
void * data_ptr_
Definition: Tensor.h:1315
std::string ToString(bool with_suffix=true, const std::string &indent="") const
Definition: Tensor.cpp:747
Tensor Slice(int64_t dim, int64_t start, int64_t stop, int64_t step=1) const
Definition: Tensor.cpp:824
Tensor operator*=(const Tensor &value)
Definition: Tensor.h:655
Tensor Min(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1198
Iterator begin()
Definition: Tensor.cpp:236
Tensor IsFinite() const
Definition: Tensor.cpp:1312
Tensor T() const
Expects input to be <= 2-D Tensor by swapping dimension 0 and 1.
Definition: Tensor.cpp:1009
Tensor AsRvalue()
Definition: Tensor.h:557
Tensor Mean(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1177
Tensor Div(const Tensor &value) const
Divides a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1135
Tensor Lt(const Tensor &value) const
Element-wise less-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1516
Tensor ReinterpretCast(const core::Dtype &dtype) const
Definition: Tensor.cpp:355
Tensor Trunc() const
Element-wise trunc value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1359
Tensor Sub_(const Tensor &value)
Definition: Tensor.cpp:1083
Tensor Sqrt_()
Element-wise square root of a tensor, in-place.
Definition: Tensor.cpp:1232
Tensor Neg_()
Element-wise negation of a tensor, in-place.
Definition: Tensor.cpp:1265
Tensor operator/(const Tensor &value) const
Definition: Tensor.h:661
Tensor Contiguous() const
Definition: Tensor.cpp:739
Tensor ArgMax(const SizeVector &dims) const
Definition: Tensor.cpp:1219
Dtype dtype_
Data type.
Definition: Tensor.h:1318
static Tensor Diag(const Tensor &input)
Create a square matrix with specified diagonal elements in input.
Definition: Tensor.cpp:391
int64_t NumDims() const
Definition: Tensor.h:1161
ConstIterator cbegin() const
Definition: Tensor.cpp:305
Tensor LogicalAnd_(const Tensor &value)
Definition: Tensor.cpp:1402
Tensor operator-() const
Unary minus of a tensor, returning a new tensor.
Definition: Tensor.h:741
Tensor Transpose(int64_t dim0, int64_t dim1) const
Transpose a Tensor by swapping dimension dim0 and dim1.
Definition: Tensor.cpp:998
Tensor Clip_(Scalar min_val, Scalar max_val)
Definition: Tensor.cpp:1328
Tensor Gt(const Tensor &value) const
Element-wise greater-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1484
DLManagedTensor * ToDLPack() const
Convert the Tensor to DLManagedTensor.
Definition: Tensor.cpp:1738
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:1157
void CopyFrom(const Tensor &other)
Copy Tensor values to current tensor from the source tensor.
Definition: Tensor.cpp:737
Tensor operator/=(const Tensor &value)
Definition: Tensor.h:668
Tensor operator/(Scalar value) const
Definition: Tensor.h:662
static Tensor EmptyLike(const Tensor &other)
Definition: Tensor.h:246
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:252
Tensor View(const SizeVector &dst_shape) const
Definition: Tensor.cpp:688
void FillObject(const Object &v)
Definition: Tensor.h:1392
bool IsContiguous() const
Definition: Tensor.h:1025
Tensor operator<(const Tensor &value) const
Definition: Tensor.h:869
Tensor Abs() const
Element-wise absolute value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1281
Tensor Any(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1719
std::shared_ptr< Blob > blob_
Underlying memory buffer for Tensor.
Definition: Tensor.h:1321
Tensor operator+=(const Tensor &value)
Definition: Tensor.h:629
Tensor Eq_(const Tensor &value)
Definition: Tensor.cpp:1630
Tensor operator-=(Scalar value)
Definition: Tensor.h:643
static Tensor Zeros(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with zeros.
Definition: Tensor.cpp:373
Tensor Le_(const Tensor &value)
Definition: Tensor.cpp:1598
bool AllEqual(const Tensor &other) const
Definition: Tensor.cpp:1794
void * GetDataPtr()
Definition: Tensor.h:1149
Tensor operator+(Scalar value) const
Definition: Tensor.h:623
Tensor Reshape(const SizeVector &dst_shape) const
Definition: Tensor.cpp:638
void AssertTemplateDtype() const
Definition: Tensor.h:1164
static Tensor Init(const std::initializer_list< std::initializer_list< T >> &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:292
Tensor Add(const Tensor &value) const
Adds a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1027
ConstIterator begin() const
Definition: Tensor.h:1266
Tensor Prod(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1191
Tensor Cos_()
Element-wise cosine of a tensor, in-place.
Definition: Tensor.cpp:1254
Tensor Triu(const int diagonal=0) const
Returns the upper triangular matrix of the 2D tensor, above the given diagonal index....
Definition: Tensor.cpp:1873
Tensor Div_(const Tensor &value)
Definition: Tensor.cpp:1155
Tensor Sqrt() const
Element-wise square root of a tensor, returns a new tensor.
Definition: Tensor.cpp:1226
SizeVector shape_
SizeVector of the Tensor. shape_[i] is the length of dimension i.
Definition: Tensor.h:1291
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:77
Tensor()
Definition: Tensor.h:34
Tensor Clip(Scalar min_val, Scalar max_val) const
Definition: Tensor.cpp:1322
Device GetDevice() const override
Definition: Tensor.cpp:1365
static Tensor Load(const std::string &file_name)
Load tensor from numpy's npy format.
Definition: Tensor.cpp:1790
bool IsSame(const Tensor &other) const
Definition: Tensor.cpp:1821
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:1857
Tensor operator==(const Tensor &value) const
Definition: Tensor.h:901
int64_t GetStride(int64_t dim) const
Definition: Tensor.h:1128
static Tensor Init(const T val, const Device &device=Device("CPU:0"))
Definition: Tensor.h:274
bool IsNonZero() const
Definition: Tensor.cpp:1687
Tensor operator-(Scalar value) const
Definition: Tensor.h:636
Tensor Ne(const Tensor &value) const
Element-wise not-equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1644
Tensor Solve(const Tensor &rhs) const
Definition: Tensor.cpp:1837
Tensor Matmul(const Tensor &rhs) const
Definition: Tensor.cpp:1828
Tensor operator>=(const Tensor &value) const
Definition: Tensor.h:880
T Item() const
Definition: Tensor.h:607
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:1885
Tensor Mul_(const Tensor &value)
Definition: Tensor.cpp:1119
Tensor Exp_()
Element-wise base-e exponential of a tensor, in-place.
Definition: Tensor.cpp:1276
Tensor operator/=(Scalar value)
Definition: Tensor.h:669
Tensor Sin_()
Element-wise sine of a tensor, in-place.
Definition: Tensor.cpp:1243
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create an identity matrix of size n x n.
Definition: Tensor.cpp:385
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:301
Tensor(const SizeVector &shape, const SizeVector &strides, void *data_ptr, Dtype dtype, const std::shared_ptr< Blob > &blob)
Definition: Tensor.h:94
Tensor operator+(const Tensor &value) const
Definition: Tensor.h:622
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:1159
Tensor GetItem(const TensorKey &tk) const
Definition: Tensor.cpp:440
Tensor operator*(const Tensor &value) const
Definition: Tensor.h:648
Tensor operator[](int64_t i) const
Extract the i-th Tensor along the first axis, returning a new view.
Definition: Tensor.cpp:806
static Tensor FromDLPack(const DLManagedTensor *dlmt)
Convert DLManagedTensor to Tensor.
Definition: Tensor.cpp:1742
Tensor Abs_()
Element-wise absolute value of a tensor, in-place.
Definition: Tensor.cpp:1287
Tensor operator!=(const Tensor &value) const
Definition: Tensor.h:911
const SizeVector & GetShapeRef() const
Definition: Tensor.h:1118
Tensor operator-(const Tensor &value) const
Definition: Tensor.h:635
Tensor IsInf() const
Definition: Tensor.cpp:1302
Tensor Broadcast(const SizeVector &dst_shape) const
Broadcast Tensor to a new broadcastable shape.
Definition: Tensor.cpp:595
Tensor(std::vector< T > &&vec, const SizeVector &shape={})
Take ownership of data in std::vector<T>
Definition: Tensor.h:116
Dtype GetDtype() const
Definition: Tensor.h:1153
Tensor Mul(const Tensor &value) const
Multiplies a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1099
Tensor operator<=(const Tensor &value) const
Definition: Tensor.h:891
ConstIterator end() const
Definition: Tensor.h:1272
Tensor operator-=(const Tensor &value)
Definition: Tensor.h:642
Tensor Permute(const SizeVector &dims) const
Permute (dimension shuffle) the Tensor, returns a view.
Definition: Tensor.cpp:958
void IndexSet(const std::vector< Tensor > &index_tensors, const Tensor &src_tensor)
Advanced indexing getter.
Definition: Tensor.cpp:903
Tensor Expand(const SizeVector &dst_shape) const
Definition: Tensor.cpp:605
Tensor Ne_(const Tensor &value)
Definition: Tensor.cpp:1662
SizeVector GetStrides() const
Definition: Tensor.h:1124
Tensor IsNan() const
Definition: Tensor.cpp:1292
Tensor LogicalXor(const Tensor &value) const
Definition: Tensor.cpp:1450
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:1865
Tensor operator>(const Tensor &value) const
Definition: Tensor.h:859
const Tensor AsRvalue() const
Convert to constant rvalue.
Definition: Tensor.h:560
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:589
Tensor Eq(const Tensor &value) const
Element-wise equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1612
Tensor LogicalNot_()
Definition: Tensor.cpp:1378
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:706
Tensor Ceil() const
Element-wise ceil value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1347
Tensor IndexGet(const std::vector< Tensor > &index_tensors) const
Advanced indexing getter. This will always allocate a new Tensor.
Definition: Tensor.cpp:872
Tensor Round() const
Element-wise round value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1353
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1205
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
Definition: TensorKey.h:26
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:1399
const Dtype Int64
Definition: Dtype.cpp:47
Tensor operator/(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1414
const Dtype Undefined
Definition: Dtype.cpp:41
Tensor operator-(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1404
Tensor operator*(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1409
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
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:1216
ConstIterator & operator++()
Definition: Tensor.cpp:283
ConstIterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:258
~ConstIterator()
Definition: Tensor.cpp:272
pointer operator->() const
Definition: Tensor.cpp:278
const Tensor value_type
Definition: Tensor.h:1219
reference operator*() const
Definition: Tensor.cpp:274
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1217
std::ptrdiff_t difference_type
Definition: Tensor.h:1218
bool operator!=(const ConstIterator &other) const
Definition: Tensor.cpp:300
bool operator==(const ConstIterator &other) const
Definition: Tensor.cpp:294
Iterator for Tensor.
Definition: Tensor.h:1189
Iterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:191
std::ptrdiff_t difference_type
Definition: Tensor.h:1191
Iterator & operator++()
Definition: Tensor.cpp:216
bool operator==(const Iterator &other) const
Definition: Tensor.cpp:227
pointer operator->() const
Definition: Tensor.cpp:211
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1190
~Iterator()
Definition: Tensor.cpp:205
bool operator!=(const Iterator &other) const
Definition: Tensor.cpp:232
reference operator*() const
Definition: Tensor.cpp:207
Tensor value_type
Definition: Tensor.h:1192