 |
ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
|
Go to the documentation of this file.
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_standard_layout<T>::value && std::is_trivial<T>::value)) {
67 "Object must be a StandardLayout and TrivialType type.");
73 init_vals.size() * dtype.
ByteSize());
82 :
Tensor(shape, dtype, device) {
84 AssertTemplateDtype<T>();
99 const std::shared_ptr<Blob>& blob)
116 template <
typename T>
120 shape_ = {
static_cast<int64_t
>(vec.size())};
126 "Tensor initialization values' size {} does not match the "
131 auto sp_vec = std::make_shared<std::vector<T>>();
133 data_ptr_ =
static_cast<void*
>(sp_vec->data());
139 [sp_vec](
void*) { (void)sp_vec; });
172 blob_ = std::make_shared<Blob>(device, (
void*)
data_ptr_, [](
void*) {});
204 template <
typename T>
219 template <
typename Object>
223 "Assignment with scalar only works for scalar Tensor of "
226 AssertTemplateDtype<Object>();
234 template <
typename S>
237 template <
typename Object>
252 template <
typename T>
274 template <
typename T>
277 std::vector<T> ele_list{val};
284 template <
typename T>
287 return InitWithInitializerList<T, 1>(in_list, device);
292 template <
typename T>
294 const std::initializer_list<std::initializer_list<T>>& in_list,
296 return InitWithInitializerList<T, 2>(in_list, device);
301 template <
typename T>
303 const std::initializer_list<
304 std::initializer_list<std::initializer_list<T>>>& in_list,
306 return InitWithInitializerList<T, 3>(in_list, device);
479 Tensor Flatten(int64_t start_dim = 0, int64_t end_dim = -1)
const;
527 std::string
ToString(
bool with_suffix =
true,
528 const std::string& indent =
"")
const;
546 int64_t step = 1)
const;
576 void IndexSet(
const std::vector<Tensor>& index_tensors,
577 const Tensor& src_tensor);
617 template <
typename T>
621 "Tensor::Item() only works for Tensor with exactly one "
624 AssertTemplateDtype<T>();
955 bool keepdim =
false)
const;
960 bool keepdim =
false)
const;
994 double atol = 1
e-8)
const;
1016 double atol = 1
e-8)
const;
1024 template <
typename T>
1026 AssertTemplateDtype<T>();
1064 std::tuple<Tensor, Tensor, Tensor>
LU(
const bool permute_l =
false)
const;
1078 std::tuple<Tensor, Tensor>
LUIpiv()
const;
1113 std::tuple<Tensor, Tensor>
Triul(
const int diagonal = 0)
const;
1121 std::tuple<Tensor, Tensor, Tensor>
SVD()
const;
1143 template <
typename T>
1145 return const_cast<T*
>(
const_cast<const Tensor*
>(
this)->GetDataPtr<T>());
1148 template <
typename T>
1152 "Requested values have type {} but Tensor has type {}. "
1153 "Please use non templated GetDataPtr() with manual "
1174 template <
typename T>
1178 "Requested values have type {} but Tensor has type {}",
1194 std::function<
void(
void*)> deleter =
nullptr);
1198 std::function<
void(
void*)> deleter =
nullptr);
1201 void Save(
const std::string& file_name)
const;
1204 static Tensor Load(
const std::string& file_name);
1230 std::unique_ptr<Impl> impl_;
1257 std::unique_ptr<Impl> impl_;
1297 template <
typename T,
size_t D>
1298 static Tensor InitWithInitializerList(
1302 std::vector<T> values =
1303 tensor_init::ToFlatVector<T, D>(shape, nested_list);
1304 return Tensor(values, shape, Dtype::FromType<T>(), device);
1347 :
Tensor(shape, dtype, device) {
1351 "Tensor initialization values' size {} does not match the "
1357 AssertTemplateDtype<bool>();
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); });
1366 init_vals_uchar.data(),
1367 init_vals_uchar.size() * dtype.
ByteSize());
1372 AssertTemplateDtype<bool>();
1381 std::transform(values_uchar.begin(), values_uchar.end(), values.begin(),
1382 [](uint8_t v) ->
bool { return static_cast<bool>(v); });
1390 "Tensor::Item only works for Tensor with one element.");
1392 AssertTemplateDtype<bool>();
1396 return static_cast<bool>(value);
1399 template <
typename S>
1402 scalar_t casted_v =
static_cast<scalar_t
>(v);
1409 template <
typename Object>
1416 template <
typename T>
1418 return rhs + scalar_lhs;
1421 template <
typename T>
1426 template <
typename T>
1428 return rhs * scalar_lhs;
1431 template <
typename T>
TensorKey InstantiateDimSize(int64_t dim_size) const
Definition: TensorKey.cpp:177
constexpr T const & value() const &
Definition: Optional.h:465
SizeVector GetOutputShape() const
Definition: AdvancedIndexing.h:35
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
void IndexSet(const std::vector< Tensor > &index_tensors, const Tensor &src_tensor)
Advanced indexing getter.
Definition: Tensor.cpp:936
static Tensor Ones(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with ones.
Definition: Tensor.cpp:412
Dtype GetDtype() const
Definition: Tensor.h:1164
Tensor Clone() const
Copy Tensor to the same device.
Definition: Tensor.h:502
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
static Tensor EmptyLike(const Tensor &other)
Definition: Tensor.h:247
SizeVector ReductionShape(const SizeVector &src_shape, const SizeVector &dims, bool keepdim)
Returns the shape after reduction.
Definition: ShapeUtil.cpp:99
The data type the tensor can hold. The data type is assumed to follow the native endian-ness....
Definition: DLPack.h:226
void FillObject(const Object &v)
Definition: Tensor.h:1410
const Dtype UInt16
Definition: Dtype.cpp:49
@ kDLBool
boolean
Definition: DLPack.h:181
Tensor Add(const Tensor &value) const
Adds a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1097
Tensor Sqrt() const
Element-wise square root of a tensor, returns a new tensor.
Definition: Tensor.cpp:1296
void Tril(const Tensor &A, Tensor &output, const int diagonal)
Definition: Tri.cpp:57
Tensor operator<(const Tensor &value) const
Definition: Tensor.h:880
SizeVector BroadcastedShape(const SizeVector &l_shape, const SizeVector &r_shape)
Returns the broadcasted shape of two shapes.
Definition: ShapeUtil.cpp:56
int64_t GetLength() const
Definition: Tensor.h:1125
Tensor Sin_()
Element-wise sine of a tensor, in-place.
Definition: Tensor.cpp:1313
Tensor GetIndexTensor() const
Definition: TensorKey.cpp:186
constexpr bool has_value() const noexcept
Definition: Optional.h:440
static Tensor Diag(const Tensor &input)
Create a square matrix with specified diagonal elements in input.
Definition: Tensor.cpp:424
const Dtype Int16
Definition: Dtype.cpp:45
SizeVector GetShape() const
Definition: Tensor.h:1127
uint64_t flags
Additional bitmask flags information about the tensor.
Definition: DLPack.h:398
Tensor Mean(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1247
Tensor operator<=(const Tensor &value) const
Definition: Tensor.h:902
static TensorKey IndexTensor(const Tensor &index_tensor)
Definition: TensorKey.cpp:144
Tensor Ceil() const
Element-wise ceil value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1417
@ kDLCPU
CPU device.
Definition: DLPack.h:95
std::tuple< Tensor, Tensor, Tensor > SVD() const
Definition: Tensor.cpp:1990
Tensor Neg_()
Element-wise negation of a tensor, in-place.
Definition: Tensor.cpp:1335
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
Tensor IndexExtract(int64_t dim, int64_t idx) const
Definition: Tensor.cpp:841
bool copy
Definition: VtkUtils.cpp:74
Tensor operator-(Scalar value) const
Definition: Tensor.h:647
Tensor GetTensor() const
Definition: AdvancedIndexing.h:29
Tensor ReinterpretCast(const core::Dtype &dtype) const
Definition: Tensor.cpp:388
Tensor operator-() const
Unary minus of a tensor, returning a new tensor.
Definition: Tensor.h:752
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
filament::Texture::InternalFormat format
Definition: FilamentResourceManager.cpp:181
const Dtype UInt32
Definition: Dtype.cpp:50
bool IsSame(const Tensor &other) const
Definition: Tensor.cpp:1912
bool IsCUDA() const
Definition: Device.h:99
Tensor operator-(const Tensor &value) const
Definition: Tensor.h:646
Tensor Reshape(const SizeVector &dst_shape) const
Definition: Tensor.cpp:671
@ kDLFloat
IEEE floating point.
Definition: DLPack.h:166
void Save(const std::string &file_name) const
Save tensor to numpy's npy format.
Definition: Tensor.cpp:1877
void IndexAdd_(int64_t dim, const Tensor &index, const Tensor &src, Tensor &dst)
Definition: IndexReduction.cpp:16
Tensor tensor_slice_
Definition: Tensor.cpp:286
void AssertNotSYCL(const Tensor &tensor)
Definition: Tensor.h:1436
#define AssertTensorDevice(tensor,...)
Definition: TensorCheck.h:45
Tensor Contiguous() const
Definition: Tensor.cpp:772
static Tensor Init(const std::initializer_list< std::initializer_list< T >> &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:293
ConstIterator & operator++()
Definition: Tensor.cpp:316
void Reduction(const Tensor &src, Tensor &dst, const SizeVector &dims, bool keepdim, ReductionOpCode op_code)
Definition: Reduction.cpp:16
int64_t ByteSize() const
Definition: Dtype.h:59
Tensor Reverse() const
Reverse a Tensor's elements by viewing the tensor as a 1D array.
Definition: Tensor.cpp:465
double Det() const
Compute the determinant of a 2D square tensor.
Definition: Tensor.cpp:1092
bool IsContiguous() const
Definition: Tensor.h:1036
#define DLPACK_MINOR_VERSION
The current minor version of dlpack.
Definition: DLPack.h:40
Tensor operator*(Scalar value) const
Definition: Tensor.h:660
CloudViewer DLPack Tensor manager.
Definition: Tensor.cpp:133
std::string ScalarPtrToString(const void *ptr) const
Definition: Tensor.cpp:825
Tensor Mul(const Tensor &value) const
Multiplies a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1169
Tensor operator+=(const Tensor &value)
Definition: Tensor.h:640
Tensor(const SizeVector &shape, const SizeVector &strides, void *data_ptr, Dtype dtype, const std::shared_ptr< Blob > &blob)
Definition: Tensor.h:95
int64_t GetStart() const
Definition: TensorKey.cpp:156
Tensor operator+(const Tensor &value) const
Definition: Tensor.h:633
Tensor operator*(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1427
bool operator==(const ConstIterator &other) const
Definition: Tensor.cpp:327
Tensor tensor_slice_
Definition: Tensor.cpp:219
Tensor Slice(int64_t dim, int64_t start, int64_t stop, int64_t step=1) const
Definition: Tensor.cpp:857
std::pair< bool, SizeVector > Restride(const SizeVector &old_shape, const SizeVector &old_strides, const SizeVector &new_shape)
Definition: ShapeUtil.cpp:225
Tensor Permute(const SizeVector &dims) const
Permute (dimension shuffle) the Tensor, returns a view.
Definition: Tensor.cpp:1028
int64_t GetStop() const
Definition: TensorKey.cpp:163
ConstIterator cbegin() const
Definition: Tensor.cpp:338
std::vector< Tensor > GetIndexTensors() const
Definition: AdvancedIndexing.h:31
uint64_t byte_offset
The offset in bytes to the beginning pointer to data.
Definition: DLPack.h:302
reference operator*() const
Definition: Tensor.cpp:307
Iterator & operator++()
Definition: Tensor.cpp:249
const T * GetDataPtr() const
Definition: Tensor.h:1149
Tensor View(const SizeVector &dst_shape) const
Definition: Tensor.cpp:721
Tensor GetItem(const TensorKey &tk) const
Definition: Tensor.cpp:473
Tensor Ne_(const Tensor &value)
Definition: Tensor.cpp:1732
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
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
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
Tensor LogicalNot() const
Definition: Tensor.cpp:1442
Iterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:224
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1235
int64_t WrapDim(int64_t dim, int64_t max_dim, bool inclusive)
Wrap around negative dim.
Definition: ShapeUtil.cpp:131
Tensor operator>=(const Tensor &value) const
Definition: Tensor.h:891
Tensor operator!=(const Tensor &value) const
Definition: Tensor.h:922
static Dtype DLDataTypeToDtype(const DLDataType &dltype)
Definition: Tensor.cpp:60
std::shared_ptr< Blob > GetBlob() const
Definition: Tensor.h:1168
Tensor * tensor_
Definition: Tensor.cpp:217
Tensor operator*(const Tensor &value) const
Definition: Tensor.h:659
Tensor operator/(const Tensor &value) const
Definition: Tensor.h:672
Tensor(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Constructor for creating a contiguous Tensor.
Definition: Tensor.h:37
int32_t ndim
Number of dimensions.
Definition: DLPack.h:278
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
Tensor LogicalNot_()
Definition: Tensor.cpp:1448
~ConstIterator()
Definition: Tensor.cpp:305
Tensor Any(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1789
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
Definition: DLPack.h:319
SizeVector GetIndexedShape() const
Definition: AdvancedIndexing.h:37
Definition: Tensor.cpp:283
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
Definition: Device.cpp:89
ConstIterator end() const
Definition: Tensor.h:1290
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
core::Tensor result
Definition: VtkUtils.cpp:76
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1275
Tensor Add_(const Tensor &value)
Definition: Tensor.cpp:1117
int64_t NumDims() const
Definition: Tensor.h:1172
static Tensor FromDLPack(const DLManagedTensor *dlmt, std::function< void(void *)> deleter=nullptr)
Convert DLManagedTensor to Tensor (DLPack v0.x).
Definition: Tensor.cpp:1868
Tensor value_type
Definition: Tensor.h:1210
void Copy(const Tensor &src, Tensor &dst)
Definition: UnaryEW.cpp:66
bool operator!=(const Iterator &other) const
Definition: Tensor.cpp:265
SizeVector Iota(int64_t n)
Returns a SizeVector of {0, 1, ..., n - 1}, similar to std::iota.
Definition: ShapeUtil.cpp:205
Tensor Sub_(const Tensor &value)
Definition: Tensor.cpp:1153
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create an identity matrix of size n x n.
Definition: Tensor.cpp:418
Tensor NonZero(const Tensor &src)
Definition: NonZero.cpp:19
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
constexpr utility::nullopt_t None
Definition: TensorKey.h:20
Tensor Lt_(const Tensor &value)
Definition: Tensor.cpp:1604
Tensor Expand(const SizeVector &dst_shape) const
Definition: Tensor.cpp:638
bool IsSYCL() const
Returns true iff device type is SYCL GPU.
Definition: Device.h:52
void Triul(const Tensor &A, Tensor &upper, Tensor &lower, const int diagonal)
Definition: Tri.cpp:79
const Tensor AsRvalue() const
Convert to constant rvalue.
Definition: Tensor.h:561
Iterator for Tensor.
Definition: Tensor.h:1207
Tensor ArgMax(const SizeVector &dims) const
Definition: Tensor.cpp:1289
Tensor Cos_()
Element-wise cosine of a tensor, in-place.
Definition: Tensor.cpp:1324
void LU(const Tensor &A, Tensor &permutation, Tensor &lower, Tensor &upper, const bool permute_l)
Definition: LU.cpp:126
static Tensor Zeros(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor fill with zeros.
Definition: Tensor.cpp:406
Tensor Sub(const Tensor &value) const
Substracts a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1133
A versioned and managed C Tensor object, manage memory of DLTensor.
Definition: DLPack.h:366
const double * e
Definition: essential_matrix_poly.h:10
SizeVector InferShape(SizeVector shape, int64_t num_elements)
Definition: ShapeUtil.cpp:150
std::string ToString() const
Definition: SizeVector.cpp:132
const Dtype Int32
Definition: Dtype.cpp:46
Tensor Exp_()
Element-wise base-e exponential of a tensor, in-place.
Definition: Tensor.cpp:1346
Tensor LeastSquares(const Tensor &rhs) const
Definition: Tensor.cpp:1938
Tensor operator==(const Tensor &value) const
Definition: Tensor.h:912
const Dtype UInt64
Definition: Dtype.cpp:51
Tensor operator[](int64_t i) const
Extract the i-th Tensor along the first axis, returning a new view.
Definition: Tensor.cpp:839
int64_t GetLength() const
Definition: SizeVector.cpp:124
Tensor Inverse() const
Definition: Tensor.cpp:1982
Tensor SetItem(const Tensor &value)
Set all items. Equivalent to tensor[:] = value in Python.
Definition: Tensor.cpp:564
bool AllClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1895
std::forward_iterator_tag iterator_category
Definition: Tensor.h:1208
Tensor T() const
Expects input to be <= 2-D Tensor by swapping dimension 0 and 1.
Definition: Tensor.cpp:1079
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
Tensor Le_(const Tensor &value)
Definition: Tensor.cpp:1668
Tensor(void *data_ptr, Dtype dtype, const SizeVector &shape, const SizeVector &strides={}, const Device &device=Device("CPU:0"))
Tensor wrapper constructor from raw host buffer.
Definition: Tensor.h:162
const SizeVector & GetShapeRef() const
Definition: Tensor.h:1129
Tensor operator+(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1417
SizeVector strides_
Definition: Tensor.h:1318
uint8_t code
Type code of base types. We keep it uint8_t instead of DLDataTypeCode for minimal memory footprint,...
Definition: DLPack.h:232
Tensor IsNan() const
Definition: Tensor.cpp:1362
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
ConstIterator cend() const
Definition: Tensor.cpp:345
~Iterator()
Definition: Tensor.cpp:238
Tensor IndexGet(const std::vector< Tensor > &index_tensors) const
Advanced indexing getter. This will always allocate a new Tensor.
Definition: Tensor.cpp:905
This class is based on PyTorch's aten/src/ATen/native/Indexing.cpp.
Definition: AdvancedIndexing.h:21
Tensor Exp() const
Element-wise exponential of a tensor, returning a new tensor.
Definition: Tensor.cpp:1340
Tensor Arange(const Tensor &start, const Tensor &stop, const Tensor &step)
Definition: Arange.cpp:17
const Dtype UInt8
Definition: Dtype.cpp:48
int64_t * strides
strides of the tensor (in number of elements, not bytes), can not be NULL if ndim !...
Definition: DLPack.h:300
void WriteNpy(const std::string &file_name, const core::Tensor &tensor)
Definition: NumpyIO.cpp:671
const Dtype Bool
Definition: Dtype.cpp:52
std::string ToString() const
Definition: Dtype.h:65
std::ptrdiff_t difference_type
Definition: Tensor.h:1236
std::shared_ptr< Blob > blob_
Underlying memory buffer for Tensor.
Definition: Tensor.h:1339
void * GetDataPtr()
Definition: Tensor.h:1160
bool AllEqual(const Tensor &other) const
Definition: Tensor.cpp:1885
Tensor operator*=(Scalar value)
Definition: Tensor.h:667
Tensor Matmul(const Tensor &rhs) const
Definition: Tensor.cpp:1919
const Dtype Float64
Definition: Dtype.cpp:43
uint8_t bits
Number of bits, common choices are 8, 16, 32.
Definition: DLPack.h:236
ConstIterator begin() const
Definition: Tensor.h:1284
Tensor operator&&(const Tensor &value) const
Definition: Tensor.h:822
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
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
std::ptrdiff_t difference_type
Definition: Tensor.h:1209
bool operator!=(const ConstIterator &other) const
Definition: Tensor.cpp:333
Device GetDevice() const override
Definition: Tensor.cpp:1435
Tensor Flatten(int64_t start_dim=0, int64_t end_dim=-1) const
Definition: Tensor.cpp:685
T To() const
To<T>() does not check for scalar type and overflows.
Definition: Scalar.h:128
DLManagedTensorVersioned * ToDLPackVersioned() const
Convert the Tensor to DLManagedTensorVersioned (DLPack v1.x).
Definition: Tensor.cpp:1811
void CopyFrom(const Tensor &other)
Copy Tensor values to current tensor from the source tensor.
Definition: Tensor.cpp:770
Tensor operator||(const Tensor &value) const
Definition: Tensor.h:839
Tensor operator/(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1432
Tensor ArgMin(const SizeVector &dims) const
Definition: Tensor.cpp:1282
SizeVector GetIndexedStrides() const
Definition: AdvancedIndexing.h:39
void LUIpiv(const Tensor &A, Tensor &ipiv, Tensor &output)
Definition: LU.cpp:62
#define DISPATCH_DTYPE_TO_TEMPLATE_WITH_BOOL(DTYPE,...)
Definition: Dispatch.h:68
int64_t GetStep() const
Definition: TensorKey.cpp:170
Tensor Eq_(const Tensor &value)
Definition: Tensor.cpp:1700
Tensor Abs_()
Element-wise absolute value of a tensor, in-place.
Definition: Tensor.cpp:1357
Tensor Div_(const Tensor &value)
Definition: Tensor.cpp:1225
const Tensor value_type
Definition: Tensor.h:1237
int64_t GetIndex() const
Definition: TensorKey.cpp:148
Tensor Broadcast(const SizeVector &dst_shape) const
Broadcast Tensor to a new broadcastable shape.
Definition: Tensor.cpp:628
const Dtype Float32
Definition: Dtype.cpp:42
int64_t NumElements() const
Definition: SizeVector.cpp:108
@ kDLOneAPI
Unified shared memory allocated on a oneAPI non-partititioned device. Call to oneAPI runtime is requi...
Definition: DLPack.h:132
Definition: SizeVector.h:70
Tensor()
Definition: Tensor.h:34
const Dtype Undefined
Definition: Dtype.cpp:41
DLDataType dtype
The data type of the pointer.
Definition: DLPack.h:280
@ kDLCUDA
CUDA GPU device.
Definition: DLPack.h:97
Tensor Mul_(const Tensor &value)
Definition: Tensor.cpp:1189
static DLDevice getDLPackDevice(const Tensor &o3d_tensor)
Definition: Tensor.cpp:187
void IndexAdd_(int64_t dim, const Tensor &index, const Tensor &src)
Advanced in-place reduction by index.
Definition: Tensor.cpp:991
int GetID() const
Returns the device index (within the same device type).
Definition: Device.h:61
Tensor & AssignObject(const Object &v) &&
Definition: Tensor.h:220
static Tensor Load(const std::string &file_name)
Load tensor from numpy's npy format.
Definition: Tensor.cpp:1881
ConstIterator(pointer tensor, int64_t index)
Definition: Tensor.cpp:291
static Tensor Init(const std::initializer_list< T > &in_list, const Device &device=Device("CPU:0"))
Definition: Tensor.h:285
static DLMT * Create(const Tensor &o3d_tensor)
Definition: Tensor.cpp:181
Tensor operator+=(Scalar value)
Definition: Tensor.h:641
void Matmul(const Tensor &A, const Tensor &B, Tensor &output)
Computes matrix multiplication C = AB.
Definition: Matmul.cpp:17
#define LogError(...)
Definition: Logging.h:60
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:31
std::vector< Tensor > NonZeroNumpy() const
Definition: Tensor.cpp:1746
Tensor operator*=(const Tensor &value)
Definition: Tensor.h:666
SizeVector InferShape(const L &list)
Definition: TensorInit.h:82
Tensor Lt(const Tensor &value) const
Element-wise less-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1586
static TensorKey Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Definition: TensorKey.cpp:138
int64_t index_
Definition: Tensor.cpp:285
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
Iterator end()
Definition: Tensor.cpp:276
Tensor operator/(Scalar value) const
Definition: Tensor.h:673
DLDevice device
The device of the tensor.
Definition: DLPack.h:276
Tensor operator-(T scalar_lhs, const Tensor &rhs)
Definition: Tensor.h:1422
DLManagedTensor * ToDLPack() const
Convert the Tensor to DLManagedTensor (DLPack v0.x).
Definition: Tensor.cpp:1808
T Item() const
Definition: Tensor.h:618
Tensor(std::vector< T > &&vec, const SizeVector &shape={})
Take ownership of data in std::vector<T>
Definition: Tensor.h:117
Tensor operator+(Scalar value) const
Definition: Tensor.h:634
DLDeviceType
The device type in DLDevice.
Definition: DLPack.h:92
void AssertTemplateDtype() const
Definition: Tensor.h:1175
Tensor Round() const
Element-wise round value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1423
SizeVector GetStrides() const
Definition: Tensor.h:1135
void AssertSameScalarType(Scalar other, const std::string &error_msg) const
Definition: Scalar.h:140
#define AssertTensorDtype(tensor,...)
Definition: TensorCheck.h:21
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
Definition: TensorKey.h:26
DLPackVersion version
The API and ABI version of the current managed Tensor.
Definition: DLPack.h:370
Tensor operator-=(Scalar value)
Definition: Tensor.h:654
Tensor & operator=(const T v) &&
Definition: Tensor.h:205
void Triu(const Tensor &A, Tensor &output, const int diagonal)
Definition: Tri.cpp:35
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
std::string ToString(bool with_suffix=true, const std::string &indent="") const
Definition: Tensor.cpp:780
#define DLPACK_MAJOR_VERSION
The current major version of dlpack.
Definition: DLPack.h:37
const void * GetDataPtr() const
Definition: Tensor.h:1162
typename NestedInitializerImpl< T, D >::type NestedInitializerList
Definition: TensorInit.h:36
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
Definition: Tensor.cpp:400
TensorKeyMode GetMode() const
Returns TensorKey mode.
Definition: TensorKey.cpp:130
Tensor Sin() const
Element-wise sine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1307
int64_t NumElements() const
Definition: Tensor.h:1170
Tensor Sqrt_()
Element-wise square root of a tensor, in-place.
Definition: Tensor.cpp:1302
static Tensor Init(const T val, const Device &device=Device("CPU:0"))
Definition: Tensor.h:275
constexpr nullopt_t nullopt
Definition: Optional.h:136
@ kDLUInt
unsigned integer
Definition: DLPack.h:164
Tensor Min(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1268
const Dtype Int8
Definition: Dtype.cpp:44
Tensor Ne(const Tensor &value) const
Element-wise not-equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1714
bool Equal(T value) const
Definition: Scalar.h:172
SizeVector DefaultStrides(const SizeVector &shape)
Compute default strides for a shape when a tensor is contiguous.
Definition: ShapeUtil.cpp:214
SizeVector shape_
SizeVector of the Tensor. shape_[i] is the length of dimension i.
Definition: Tensor.h:1309
Tensor Transpose(int64_t dim0, int64_t dim1) const
Transpose a Tensor by swapping dimension dim0 and dim1.
Definition: Tensor.cpp:1068
reference operator*() const
Definition: Tensor.cpp:240
#define LogWarning(...)
Definition: Logging.h:72
Tensor NonZero() const
Definition: Tensor.cpp:1755
Tensor IsFinite() const
Definition: Tensor.cpp:1382
Tensor Sum(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1240
@ kDLInt
signed integer
Definition: DLPack.h:162
uint32_t major
DLPack major version.
Definition: DLPack.h:81
Dtype dtype_
Data type.
Definition: Tensor.h:1336
Tensor Ge(const Tensor &value) const
Definition: Tensor.cpp:1618
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
bool IsSYCL() const
Definition: Device.h:103
bool IsObject() const
Definition: Dtype.h:63
Tensor AsRvalue()
Definition: Tensor.h:558
Tensor LogicalXor_(const Tensor &value)
Definition: Tensor.cpp:1539
pointer operator->() const
Definition: Tensor.cpp:311
void * data_ptr_
Definition: Tensor.h:1333
Tensor Gt(const Tensor &value) const
Element-wise greater-than of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1554
Iterator begin()
Definition: Tensor.cpp:269
Tensor operator-=(const Tensor &value)
Definition: Tensor.h:653
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
Tensor & operator=(const Tensor &other) &
Definition: Tensor.cpp:355
static void Deleter(DLMT *arg)
Definition: Tensor.cpp:208
DLDataTypeCode
The type code options DLDataType.
Definition: DLPack.h:160
void BinaryEW(const Tensor &lhs, const Tensor &rhs, Tensor &dst, BinaryEWOpCode op_code)
Definition: BinaryEW.cpp:30
static DLDataTypeCode DtypeToDLDataTypeCode(const Dtype &dtype)
Definition: Tensor.cpp:44
double Det(const Tensor &A)
Definition: Det.cpp:16
Tensor Eq(const Tensor &value) const
Element-wise equals-to of tensors, returning a new boolean tensor.
Definition: Tensor.cpp:1682
Tensor LogicalAnd_(const Tensor &value)
Definition: Tensor.cpp:1472
int64_t GetStride(int64_t dim) const
Definition: Tensor.h:1139
Tensor Trunc() const
Element-wise trunc value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1429
uint16_t lanes
Number of lanes in the type, used for vector types.
Definition: DLPack.h:238
Tensor All(const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
Definition: Tensor.cpp:1770
Tensor Abs() const
Element-wise absolute value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1351
Plain C Tensor object, does not manage memory.
Definition: DLPack.h:244
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
Tensor operator/=(Scalar value)
Definition: Tensor.h:680
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
Tensor Solve(const Tensor &rhs) const
Definition: Tensor.cpp:1928
Definition: Tensor.cpp:216
const SizeVector & GetStridesRef() const
Definition: Tensor.h:1137
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:61
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
DeviceType GetType() const
Returns type of the device, e.g. DeviceType::CPU, DeviceType::CUDA.
Definition: Device.h:58
Tensor LogicalXor(const Tensor &value) const
Definition: Tensor.cpp:1520
const Tensor * tensor_
Definition: Tensor.cpp:284
static Tensor FromDLPackVersioned(const DLManagedTensorVersioned *dlmt, std::function< void(void *)> deleter=nullptr)
Convert DLManagedTensorVersioned to Tensor (DLPack v1.x).
Definition: Tensor.cpp:1872
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
Tensor Cos() const
Element-wise cosine of a tensor, returning a new tensor.
Definition: Tensor.cpp:1318
bool operator==(const Iterator &other) const
Definition: Tensor.cpp:260
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
Tensor LogicalOr_(const Tensor &value)
Definition: Tensor.cpp:1506
Tensor LogicalAnd(const Tensor &value) const
Definition: Tensor.cpp:1453
Const iterator for Tensor.
Definition: Tensor.h:1234
#define AssertTensorDtypes(tensor,...)
Definition: TensorCheck.h:33
std::vector< T > ToFlatVector() const
Retrieve all values as an std::vector, for debugging and testing.
Definition: Tensor.h:1025
int64_t index_
Definition: Tensor.cpp:218
int64_t * shape
The shape of the tensor.
Definition: DLPack.h:286
uint32_t minor
DLPack minor version.
Definition: DLPack.h:83
A Device for Tensor and operator.
Definition: DLPack.h:146
Tensor Div(const Tensor &value) const
Divides a tensor and returns the resulting tensor.
Definition: Tensor.cpp:1205
Tensor Clip_(Scalar min_val, Scalar max_val)
Definition: Tensor.cpp:1398
Tensor operator>(const Tensor &value) const
Definition: Tensor.h:870
void UnaryEW(const Tensor &src, Tensor &dst, UnaryEWOpCode op_code)
Definition: UnaryEW.cpp:19
pointer operator->() const
Definition: Tensor.cpp:244
const Dtype Int64
Definition: Dtype.cpp:47
char type
Definition: FileIOFactory.cpp:131
bool IsNonZero() const
Definition: Tensor.cpp:1757
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
Tensor Gt_(const Tensor &value)
Definition: Tensor.cpp:1572
core::Tensor ReadNpy(const std::string &file_name)
Definition: NumpyIO.cpp:662
Tensor Neg() const
Element-wise negation of a tensor, returning a new tensor.
Definition: Tensor.cpp:1329
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:739
int64_t GetShape(int64_t dim) const
Definition: Tensor.h:1131
Tensor IsClose(const Tensor &other, double rtol=1e-5, double atol=1e-8) const
Definition: Tensor.cpp:1900
Tensor Le(const Tensor &value) const
Definition: Tensor.cpp:1650
Tensor operator/=(const Tensor &value)
Definition: Tensor.h:679
Tensor Prod(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1261
Tensor Ge_(const Tensor &value)
Definition: Tensor.cpp:1636
Tensor LogicalOr(const Tensor &value) const
Definition: Tensor.cpp:1487
Tensor Clip(Scalar min_val, Scalar max_val) const
Definition: Tensor.cpp:1392
Tensor IsInf() const
Definition: Tensor.cpp:1372
T * GetDataPtr()
Definition: Tensor.h:1144
void SVD(const Tensor &A, Tensor &U, Tensor &S, Tensor &VT)
Definition: SVD.cpp:17
Tensor Floor() const
Element-wise floor value of a tensor, returning a new tensor.
Definition: Tensor.cpp:1411