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);
616 template <
typename T>
620 "Tensor::Item() only works for Tensor with exactly one "
623 AssertTemplateDtype<T>();
954 bool keepdim =
false)
const;
959 bool keepdim =
false)
const;
993 double atol = 1e-8)
const;
1015 double atol = 1e-8)
const;
1023 template <
typename T>
1025 AssertTemplateDtype<T>();
1063 std::tuple<Tensor, Tensor, Tensor>
LU(
const bool permute_l =
false)
const;
1077 std::tuple<Tensor, Tensor>
LUIpiv()
const;
1112 std::tuple<Tensor, Tensor>
Triul(
const int diagonal = 0)
const;
1120 std::tuple<Tensor, Tensor, Tensor>
SVD()
const;
1142 template <
typename T>
1144 return const_cast<T*
>(
const_cast<const Tensor*
>(
this)->GetDataPtr<T>());
1147 template <
typename T>
1151 "Requested values have type {} but Tensor has type {}. "
1152 "Please use non templated GetDataPtr() with manual "
1173 template <
typename T>
1177 "Requested values have type {} but Tensor has type {}",
1193 void Save(
const std::string& file_name)
const;
1196 static Tensor Load(
const std::string& file_name);
1222 std::unique_ptr<Impl> impl_;
1249 std::unique_ptr<Impl> impl_;
1289 template <
typename T,
size_t D>
1290 static Tensor InitWithInitializerList(
1294 std::vector<T> values =
1295 tensor_init::ToFlatVector<T, D>(shape, nested_list);
1296 return Tensor(values, shape, Dtype::FromType<T>(), device);
1339 :
Tensor(shape, dtype, device) {
1343 "Tensor initialization values' size {} does not match the "
1349 AssertTemplateDtype<bool>();
1353 std::vector<uint8_t> init_vals_uchar(init_vals.size());
1354 std::transform(init_vals.begin(), init_vals.end(), init_vals_uchar.begin(),
1355 [](
bool v) -> uint8_t { return static_cast<uint8_t>(v); });
1358 init_vals_uchar.data(),
1359 init_vals_uchar.size() * dtype.
ByteSize());
1364 AssertTemplateDtype<bool>();
1373 std::transform(values_uchar.begin(), values_uchar.end(), values.begin(),
1374 [](uint8_t v) ->
bool { return static_cast<bool>(v); });
1382 "Tensor::Item only works for Tensor with one element.");
1384 AssertTemplateDtype<bool>();
1388 return static_cast<bool>(value);
1391 template <
typename S>
1394 scalar_t casted_v =
static_cast<scalar_t
>(v);
1401 template <
typename Object>
1408 template <
typename T>
1410 return rhs + scalar_lhs;
1413 template <
typename T>
1418 template <
typename T>
1420 return rhs * scalar_lhs;
1423 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:659
Tensor Clone() const
Copy Tensor to the same device.
Definition: Tensor.h:501
T * GetDataPtr()
Definition: Tensor.h:1143
SizeVector strides_
Definition: Tensor.h:1310
Tensor NonZero() const
Definition: Tensor.cpp:1723
Tensor Neg() const
Element-wise negation of a tensor, returning a new tensor.
Definition: Tensor.cpp:1297
const SizeVector & GetStridesRef() const
Definition: Tensor.h:1136
const T * GetDataPtr() const
Definition: Tensor.h:1148
Tensor Ge_(const Tensor &value)
Definition: Tensor.cpp:1604
int64_t GetShape(int64_t dim) const
Definition: Tensor.h:1130
Tensor LogicalNot() const
Definition: Tensor.cpp:1410
Tensor LogicalXor_(const Tensor &value)
Definition: Tensor.cpp:1507
Tensor operator*=(Scalar value)
Definition: Tensor.h:666
Tensor Exp() const
Element-wise exponential of a tensor, returning a new tensor.
Definition: Tensor.cpp:1308
static Tensor Init(const std::initializer_list< T > &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:284
std::vector< T > ToFlatVector() const
Retrieve all values as an std::vector, for debugging and testing.
Definition: Tensor.h:1024
Tensor Flatten(int64_t start_dim=0, int64_t end_dim=-1) const
Definition: Tensor.cpp:653
std::vector< Tensor > NonZeroNumpy() const
Definition: Tensor.cpp:1714
Tensor LeastSquares(const Tensor &rhs) const
Definition: Tensor.cpp:1885
Tensor operator&&(const Tensor &value) const
Definition: Tensor.h:821
Tensor Ge(const Tensor &value) const
Definition: Tensor.cpp:1586
bool AllClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1842
ConstIterator cend() const
Definition: Tensor.cpp:313
double Det() const
Compute the determinant of a 2D square tensor.
Definition: Tensor.cpp:1060
Tensor All(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1738
Tensor & operator=(const T v) &&
Definition: Tensor.h:204
std::string ScalarPtrToString(const void *ptr) const
Definition: Tensor.cpp:793
Tensor SetItem(const Tensor &value)
Set all items. Equivalent to tensor[:] = value in Python.
Definition: Tensor.cpp:532
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:368
Tensor Cos() const
Element-wise cosine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1286
Tensor operator||(const Tensor &value) const
Definition: Tensor.h:838
Tensor IndexExtract(int64_t dim, int64_t idx) const
Definition: Tensor.cpp:809
Tensor Sin() const
Element-wise sine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1275
Tensor(Tensor &&other)=default
Tensor Floor() const
Element-wise floor value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1379
Tensor Inverse() const
Definition: Tensor.cpp:1929
void Fill(S v)
Fill the whole Tensor with a scalar value, the scalar will be casted to the Tensor's Dtype.
Definition: Tensor.h:1392
Tensor & AssignObject(const Object &v) &&
Definition: Tensor.h:219
Tensor Sum(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1208
Tensor Gt_(const Tensor &value)
Definition: Tensor.cpp:1540
Tensor LogicalAnd(const Tensor &value) const
Definition: Tensor.cpp:1421
static Tensor Ones(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with ones.
Definition: Tensor.cpp:380
Tensor Lt_(const Tensor &value)
Definition: Tensor.cpp:1572
Tensor IsClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1847
Tensor(const Tensor &other)=default
Tensor Le(const Tensor &value) const
Definition: Tensor.cpp:1618
static Tensor Arange(const Scalar start, const Scalar stop, const Scalar step=1, const Dtype dtype=core::Int64, const Device &device=core::Device("CPU:0"))
Create a 1D tensor with evenly spaced values in the given interval.
Definition: Tensor.cpp:404
SizeVector GetShape() const
Definition: Tensor.h:1126
Tensor LogicalOr_(const Tensor &value)
Definition: Tensor.cpp:1474
int64_t GetLength() const
Definition: Tensor.h:1124
Tensor & operator=(const Tensor &other) &
Definition: Tensor.cpp:323
Tensor LogicalOr(const Tensor &value) const
Definition: Tensor.cpp:1455
Iterator end()
Definition: Tensor.cpp:244
Tensor operator+=(Scalar value)
Definition: Tensor.h:640
Tensor Sub(const Tensor &value) const
Substracts a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1101
Tensor AsStrided(const SizeVector &new_shape, const SizeVector &new_strides) const
Create a Tensor view of specified shape and strides. The underlying buffer and data_ptr offsets remai...
Definition: Tensor.cpp:1029
Tensor(void *data_ptr, Dtype dtype, const SizeVector &shape, const SizeVector &strides={}, const Device &device=Device("CPU:0"))
Tensor wrapper constructor from raw host buffer.
Definition: Tensor.h:161
const void * GetDataPtr() const
Definition: Tensor.h:1161
std::tuple< Tensor, Tensor, Tensor > SVD() const
Definition: Tensor.cpp:1937
Tensor Add_(const Tensor &value)
Definition: Tensor.cpp:1085
Tensor ArgMin(const SizeVector &dims) const
Definition: Tensor.cpp:1250
Tensor Tril(const int diagonal=0) const
Returns the lower triangular matrix of the 2D tensor, above the given diagonal index....
Definition: Tensor.cpp:1917
void Save(const std::string &file_name) const
Save tensor to numpy's npy format.
Definition: Tensor.cpp:1824
Tensor Reverse() const
Reverse a Tensor's elements by viewing the tensor as a 1D array.
Definition: Tensor.cpp:433
void * data_ptr_
Definition: Tensor.h:1325
std::string ToString(bool with_suffix=true, const std::string &indent="") const
Definition: Tensor.cpp:748
Tensor Slice(int64_t dim, int64_t start, int64_t stop, int64_t step=1) const
Definition: Tensor.cpp:825
Tensor operator*=(const Tensor &value)
Definition: Tensor.h:665
Tensor Min(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1236
Iterator begin()
Definition: Tensor.cpp:237
Tensor IsFinite() const
Definition: Tensor.cpp:1350
Tensor T() const
Expects input to be <= 2-D Tensor by swapping dimension 0 and 1.
Definition: Tensor.cpp:1047
Tensor AsRvalue()
Definition: Tensor.h:557
Tensor Mean(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1215
Tensor Div(const Tensor &value) const
Divides a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1173
Tensor Lt(const Tensor &value) const
Element-wise less-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1554
Tensor ReinterpretCast(const core::Dtype &dtype) const
Definition: Tensor.cpp:356
Tensor Trunc() const
Element-wise trunc value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1397
Tensor Sub_(const Tensor &value)
Definition: Tensor.cpp:1121
Tensor Sqrt_()
Element-wise square root of a tensor, in-place.
Definition: Tensor.cpp:1270
Tensor Neg_()
Element-wise negation of a tensor, in-place.
Definition: Tensor.cpp:1303
Tensor operator/(const Tensor &value) const
Definition: Tensor.h:671
Tensor Contiguous() const
Definition: Tensor.cpp:740
Tensor ArgMax(const SizeVector &dims) const
Definition: Tensor.cpp:1257
Dtype dtype_
Data type.
Definition: Tensor.h:1328
static Tensor Diag(const Tensor &input)
Create a square matrix with specified diagonal elements in input.
Definition: Tensor.cpp:392
int64_t NumDims() const
Definition: Tensor.h:1171
ConstIterator cbegin() const
Definition: Tensor.cpp:306
Tensor LogicalAnd_(const Tensor &value)
Definition: Tensor.cpp:1440
Tensor operator-() const
Unary minus of a tensor, returning a new tensor.
Definition: Tensor.h:751
Tensor Transpose(int64_t dim0, int64_t dim1) const
Transpose a Tensor by swapping dimension dim0 and dim1.
Definition: Tensor.cpp:1036
Tensor Clip_(Scalar min_val, Scalar max_val)
Definition: Tensor.cpp:1366
Tensor Gt(const Tensor &value) const
Element-wise greater-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1522
DLManagedTensor * ToDLPack() const
Convert the Tensor to DLManagedTensor.
Definition: Tensor.cpp:1776
Tensor(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Constructor for creating a contiguous Tensor.
Definition: Tensor.h:37
std::shared_ptr< Blob > GetBlob() const
Definition: Tensor.h:1167
void CopyFrom(const Tensor &other)
Copy Tensor values to current tensor from the source tensor.
Definition: Tensor.cpp:738
Tensor operator/=(const Tensor &value)
Definition: Tensor.h:678
Tensor operator/(Scalar value) const
Definition: Tensor.h:672
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:689
void FillObject(const Object &v)
Definition: Tensor.h:1402
bool IsContiguous() const
Definition: Tensor.h:1035
Tensor operator<(const Tensor &value) const
Definition: Tensor.h:879
Tensor Abs() const
Element-wise absolute value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1319
Tensor Any(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1757
std::shared_ptr< Blob > blob_
Underlying memory buffer for Tensor.
Definition: Tensor.h:1331
Tensor operator+=(const Tensor &value)
Definition: Tensor.h:639
Tensor Eq_(const Tensor &value)
Definition: Tensor.cpp:1668
Tensor operator-=(Scalar value)
Definition: Tensor.h:653
static Tensor Zeros(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with zeros.
Definition: Tensor.cpp:374
Tensor Le_(const Tensor &value)
Definition: Tensor.cpp:1636
bool AllEqual(const Tensor &other) const
Definition: Tensor.cpp:1832
void * GetDataPtr()
Definition: Tensor.h:1159
Tensor operator+(Scalar value) const
Definition: Tensor.h:633
Tensor Reshape(const SizeVector &dst_shape) const
Definition: Tensor.cpp:639
void AssertTemplateDtype() const
Definition: Tensor.h:1174
static Tensor Init(const std::initializer_list< std::initializer_list< T >> &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:292
void IndexAdd_(int64_t dim, const Tensor &index, const Tensor &src)
Advanced in-place reduction by index.
Definition: Tensor.cpp:959
Tensor Add(const Tensor &value) const
Adds a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1065
ConstIterator begin() const
Definition: Tensor.h:1276
Tensor Prod(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1229
Tensor Cos_()
Element-wise cosine of a tensor, in-place.
Definition: Tensor.cpp:1292
Tensor Triu(const int diagonal=0) const
Returns the upper triangular matrix of the 2D tensor, above the given diagonal index....
Definition: Tensor.cpp:1911
Tensor Div_(const Tensor &value)
Definition: Tensor.cpp:1193
Tensor Sqrt() const
Element-wise square root of a tensor, returns a new tensor.
Definition: Tensor.cpp:1264
SizeVector shape_
SizeVector of the Tensor. shape_[i] is the length of dimension i.
Definition: Tensor.h:1301
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:1360
Device GetDevice() const override
Definition: Tensor.cpp:1403
static Tensor Load(const std::string &file_name)
Load tensor from numpy's npy format.
Definition: Tensor.cpp:1828
bool IsSame(const Tensor &other) const
Definition: Tensor.cpp:1859
std::tuple< Tensor, Tensor, Tensor > LU(const bool permute_l=false) const
Computes LU factorisation of the 2D square tensor, using A = P * L * U; where P is the permutation ma...
Definition: Tensor.cpp:1895
Tensor operator==(const Tensor &value) const
Definition: Tensor.h:911
int64_t GetStride(int64_t dim) const
Definition: Tensor.h:1138
static Tensor Init(const T val, const Device &device=Device("CPU:0"))
Definition: Tensor.h:274
bool IsNonZero() const
Definition: Tensor.cpp:1725
Tensor operator-(Scalar value) const
Definition: Tensor.h:646
Tensor Ne(const Tensor &value) const
Element-wise not-equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1682
Tensor Solve(const Tensor &rhs) const
Definition: Tensor.cpp:1875
Tensor Matmul(const Tensor &rhs) const
Definition: Tensor.cpp:1866
Tensor operator>=(const Tensor &value) const
Definition: Tensor.h:890
T Item() const
Definition: Tensor.h:617
std::tuple< Tensor, Tensor > Triul(const int diagonal=0) const
Returns the tuple of upper and lower triangular matrix of the 2D tensor, above and below the given di...
Definition: Tensor.cpp:1923
Tensor Mul_(const Tensor &value)
Definition: Tensor.cpp:1157
Tensor Exp_()
Element-wise base-e exponential of a tensor, in-place.
Definition: Tensor.cpp:1314
Tensor operator/=(Scalar value)
Definition: Tensor.h:679
Tensor Sin_()
Element-wise sine of a tensor, in-place.
Definition: Tensor.cpp:1281
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create an identity matrix of size n x n.
Definition: Tensor.cpp:386
static Tensor Init(const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h: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:632
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:1169
Tensor GetItem(const TensorKey &tk) const
Definition: Tensor.cpp:441
Tensor operator*(const Tensor &value) const
Definition: Tensor.h:658
Tensor operator[](int64_t i) const
Extract the i-th Tensor along the first axis, returning a new view.
Definition: Tensor.cpp:807
static Tensor FromDLPack(const DLManagedTensor *dlmt)
Convert DLManagedTensor to Tensor.
Definition: Tensor.cpp:1780
Tensor Abs_()
Element-wise absolute value of a tensor, in-place.
Definition: Tensor.cpp:1325
Tensor operator!=(const Tensor &value) const
Definition: Tensor.h:921
const SizeVector & GetShapeRef() const
Definition: Tensor.h:1128
Tensor operator-(const Tensor &value) const
Definition: Tensor.h:645
Tensor IsInf() const
Definition: Tensor.cpp:1340
Tensor Broadcast(const SizeVector &dst_shape) const
Broadcast Tensor to a new broadcastable shape.
Definition: Tensor.cpp:596
Tensor(std::vector< T > &&vec, const SizeVector &shape={})
Take ownership of data in std::vector<T>
Definition: Tensor.h:116
Dtype GetDtype() const
Definition: Tensor.h:1163
Tensor Mul(const Tensor &value) const
Multiplies a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1137
Tensor operator<=(const Tensor &value) const
Definition: Tensor.h:901
ConstIterator end() const
Definition: Tensor.h:1282
Tensor operator-=(const Tensor &value)
Definition: Tensor.h:652
Tensor Permute(const SizeVector &dims) const
Permute (dimension shuffle) the Tensor, returns a view.
Definition: Tensor.cpp:996
void IndexSet(const std::vector< Tensor > &index_tensors, const Tensor &src_tensor)
Advanced indexing getter.
Definition: Tensor.cpp:904
Tensor Expand(const SizeVector &dst_shape) const
Definition: Tensor.cpp:606
Tensor Ne_(const Tensor &value)
Definition: Tensor.cpp:1700
SizeVector GetStrides() const
Definition: Tensor.h:1134
Tensor IsNan() const
Definition: Tensor.cpp:1330
Tensor LogicalXor(const Tensor &value) const
Definition: Tensor.cpp:1488
std::tuple< Tensor, Tensor > LUIpiv() const
Computes LU factorisation of the 2D square tensor, using A = P * L * U; where P is the permutation ma...
Definition: Tensor.cpp:1903
Tensor operator>(const Tensor &value) const
Definition: Tensor.h:869
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:590
Tensor Eq(const Tensor &value) const
Element-wise equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1650
Tensor LogicalNot_()
Definition: Tensor.cpp:1416
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:707
Tensor Ceil() const
Element-wise ceil value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1385
Tensor IndexGet(const std::vector< Tensor > &index_tensors) const
Advanced indexing getter. This will always allocate a new Tensor.
Definition: Tensor.cpp:873
Tensor Round() const
Element-wise round value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1391
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1243
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
Definition: TensorKey.h:26
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:1409
const Dtype Int64
Definition: Dtype.cpp:47
Tensor operator/(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1424
const Dtype Undefined
Definition: Dtype.cpp:41
Tensor operator-(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1414
Tensor operator*(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1419
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:1226
ConstIterator & operator++()
Definition: Tensor.cpp:284
ConstIterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:259
~ConstIterator()
Definition: Tensor.cpp:273
pointer operator->() const
Definition: Tensor.cpp:279
const Tensor value_type
Definition: Tensor.h:1229
reference operator*() const
Definition: Tensor.cpp:275
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1227
std::ptrdiff_t difference_type
Definition: Tensor.h:1228
bool operator!=(const ConstIterator &other) const
Definition: Tensor.cpp:301
bool operator==(const ConstIterator &other) const
Definition: Tensor.cpp:295
Iterator for Tensor.
Definition: Tensor.h:1199
Iterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:192
std::ptrdiff_t difference_type
Definition: Tensor.h:1201
Iterator & operator++()
Definition: Tensor.cpp:217
bool operator==(const Iterator &other) const
Definition: Tensor.cpp:228
pointer operator->() const
Definition: Tensor.cpp:212
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1200
~Iterator()
Definition: Tensor.cpp:206
bool operator!=(const Iterator &other) const
Definition: Tensor.cpp:233
reference operator*() const
Definition: Tensor.cpp:208
Tensor value_type
Definition: Tensor.h:1202