Open3D (C++ API)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
open3d::Tensor Class Reference

#include <Tensor.h>

Public Member Functions

 Tensor ()
 
 Tensor (const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
 Constructor for creating a contiguous Tensor. More...
 
template<typename T >
 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. More...
 
 Tensor (const SizeVector &shape, const SizeVector &strides, void *data_ptr, Dtype dtype, const std::shared_ptr< Blob > &blob)
 The fully specified constructor. More...
 
 Tensor (const Tensor &other)
 Shallow copy constructor with lvalue input, e.g. Tensor dst(src). More...
 
 Tensor (Tensor &&other)
 Shallow copy constructor with rvalue input, e.g. Tensor dst(src[0]). More...
 
Tensoroperator= (const Tensor &other) &
 Tensor assignment lvalue = lvalue, e.g. tensor_a = tensor_b More...
 
Tensoroperator= (Tensor &&other) &
 Tensor assignment lvalue = rvalue, e.g. tensor_a = tensor_b[0] More...
 
Tensoroperator= (const Tensor &other) &&
 Tensor assignment rvalue = lvalue, e.g. tensor_a[0] = tensor_b More...
 
Tensoroperator= (Tensor &&other) &&
 Tensor assignment rvalue = rvalue, e.g. tensor_a[0] = tensor_b[0] More...
 
template<typename T >
Tensoroperator= (const T &v) &&
 
template<typename T >
void Fill (T v)
 Fill the whole Tensor with a scalar value, the scalar will be casted to the Tensor's dtype. More...
 
Tensor GetItem (const TensorKey &tk) const
 
Tensor GetItem (const std::vector< TensorKey > &tks) const
 
Tensor SetItem (const Tensor &value)
 Set all items. Equivalent to tensor[:] = value in Python. More...
 
Tensor SetItem (const TensorKey &tk, const Tensor &value)
 
Tensor SetItem (const std::vector< TensorKey > &tks, const Tensor &value)
 
DLManagedTensorToDLPack () const
 
void Assign (const Tensor &other)
 Assign (copy) values from another Tensor, shape, dtype, device may change. More...
 
Tensor Broadcast (const SizeVector &dst_shape) const
 Broadcast Tensor to a new broadcastable shape. More...
 
Tensor Expand (const SizeVector &dst_shape) const
 
Tensor Reshape (const SizeVector &dst_shape) const
 
Tensor View (const SizeVector &dst_shape) const
 
Tensor Copy (const Device &device) const
 
void CopyFrom (const Tensor &other)
 Copy Tensor values to current tensor for source tensor. More...
 
void ShallowCopyFrom (const Tensor &other)
 Shallow copy a tensor, returning a tensor sharing the same memory. More...
 
Tensor To (Dtype dtype, bool copy=false) const
 
std::string ToString (bool with_suffix=true, const std::string &indent="") const
 
Tensor operator[] (int64_t i) const
 Extract the i-th Tensor along the first axis, returning a new view. More...
 
Tensor IndexExtract (int64_t dim, int64_t idx) const
 
Tensor Slice (int64_t dim, int64_t start, int64_t stop, int64_t step=1) const
 Slice Tensor. More...
 
Tensor AsRvalue () const
 
Tensor IndexGet (const std::vector< Tensor > &index_tensors) const
 Advanced indexing getter. More...
 
void IndexSet (const std::vector< Tensor > &index_tensors, const Tensor &src_tensor)
 Advanced indexing getter. More...
 
Tensor Permute (const SizeVector &dims) const
 Permute (dimension shuffle) the Tensor, returns a view. More...
 
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 remain the same. More...
 
Tensor Transpose (int64_t dim0, int64_t dim1) const
 Transpose a Tensor by swapping dimension dim0 and dim1. More...
 
Tensor T () const
 Expects input to be <= 2-D Tensor by swapping dimension 0 and 1. More...
 
template<typename T >
T Item () const
 
Tensor Add (const Tensor &value) const
 Adds a tensor and returns the resulting tensor. More...
 
template<typename T >
Tensor Add (T scalar_value) const
 
Tensor operator+ (const Tensor &value) const
 
template<typename T >
Tensor operator+ (T scalar_value) const
 
Tensor Add_ (const Tensor &value)
 
template<typename T >
Tensor Add_ (T scalar_value)
 
Tensor operator+= (const Tensor &value)
 
template<typename T >
Tensor operator+= (T scalar_value)
 
Tensor Sub (const Tensor &value) const
 Substracts a tensor and returns the resulting tensor. More...
 
template<typename T >
Tensor Sub (T scalar_value) const
 
Tensor operator- (const Tensor &value) const
 
template<typename T >
Tensor operator- (T scalar_value) const
 
Tensor Sub_ (const Tensor &value)
 
template<typename T >
Tensor Sub_ (T scalar_value)
 
Tensor operator-= (const Tensor &value)
 
template<typename T >
Tensor operator-= (T scalar_value)
 
Tensor Mul (const Tensor &value) const
 Multiplies a tensor and returns the resulting tensor. More...
 
template<typename T >
Tensor Mul (T scalar_value) const
 
Tensor operator* (const Tensor &value) const
 
template<typename T >
Tensor operator* (T scalar_value) const
 
Tensor Mul_ (const Tensor &value)
 
template<typename T >
Tensor Mul_ (T scalar_value)
 
Tensor operator*= (const Tensor &value)
 
template<typename T >
Tensor operator*= (T scalar_value)
 
Tensor Div (const Tensor &value) const
 Divides a tensor and returns the resulting tensor. More...
 
template<typename T >
Tensor Div (T scalar_value) const
 
Tensor operator/ (const Tensor &value) const
 
template<typename T >
Tensor operator/ (T scalar_value) const
 
Tensor Div_ (const Tensor &value)
 
template<typename T >
Tensor Div_ (T scalar_value)
 
Tensor operator/= (const Tensor &value)
 
template<typename T >
Tensor operator/= (T scalar_value)
 
Tensor Sum (const SizeVector &dims, bool keepdim=false) const
 
Tensor Mean (const SizeVector &dims, bool keepdim=false) const
 
Tensor Prod (const SizeVector &dims, bool keepdim=false) const
 
Tensor Min (const SizeVector &dims, bool keepdim=false) const
 
Tensor Max (const SizeVector &dims, bool keepdim=false) const
 
Tensor ArgMin (const SizeVector &dims) const
 
Tensor ArgMax (const SizeVector &dims) const
 
Tensor Sqrt () const
 Element-wise square root of a tensor, returns a new tensor. More...
 
Tensor Sqrt_ ()
 Element-wise square root of a tensor, in-place. More...
 
Tensor Sin () const
 Element-wise sine of a tensor, returning a new tensor. More...
 
Tensor Sin_ ()
 Element-wise sine of a tensor, in-place. More...
 
Tensor Cos () const
 Element-wise cosine of a tensor, returning a new tensor. More...
 
Tensor Cos_ ()
 Element-wise cosine of a tensor, in-place. More...
 
Tensor Neg () const
 Element-wise negation of a tensor, returning a new tensor. More...
 
Tensor Neg_ ()
 Element-wise negation of a tensor, in-place. More...
 
Tensor Exp () const
 Element-wise exponential of a tensor, returning a new tensor. More...
 
Tensor Exp_ ()
 Element-wise base-e exponential of a tensor, in-place. More...
 
Tensor Abs () const
 Element-wise absolute value of a tensor, returning a new tensor. More...
 
Tensor Abs_ ()
 Element-wise absolute value of a tensor, in-place. More...
 
Tensor LogicalNot () const
 
Tensor LogicalNot_ ()
 
Tensor LogicalAnd (const Tensor &value) const
 
Tensor operator && (const Tensor &value) const
 
Tensor LogicalAnd_ (const Tensor &value)
 
Tensor LogicalOr (const Tensor &value) const
 
Tensor operator|| (const Tensor &value) const
 
Tensor LogicalOr_ (const Tensor &value)
 
Tensor LogicalXor (const Tensor &value) const
 
Tensor LogicalXor_ (const Tensor &value)
 
Tensor Gt (const Tensor &value) const
 Element-wise greater-than of tensors, returning a new boolean tensor. More...
 
Tensor operator> (const Tensor &value) const
 
Tensor Gt_ (const Tensor &value)
 
Tensor Lt (const Tensor &value) const
 Element-wise less-than of tensors, returning a new boolean tensor. More...
 
Tensor operator< (const Tensor &value) const
 
Tensor Lt_ (const Tensor &value)
 
Tensor Ge (const Tensor &value) const
 
Tensor operator>= (const Tensor &value) const
 
Tensor Ge_ (const Tensor &value)
 
Tensor Le (const Tensor &value) const
 
Tensor operator<= (const Tensor &value) const
 
Tensor Le_ (const Tensor &value)
 
Tensor Eq (const Tensor &value) const
 Element-wise equals-to of tensors, returning a new boolean tensor. More...
 
Tensor operator== (const Tensor &value) const
 
Tensor Eq_ (const Tensor &value)
 
Tensor Ne (const Tensor &value) const
 Element-wise not-equals-to of tensors, returning a new boolean tensor. More...
 
Tensor operator!= (const Tensor &value) const
 
Tensor Ne_ (const Tensor &value)
 
std::vector< TensorNonZeroNumpy () const
 
Tensor NonZero () const
 
template<typename T >
std::vector< TToFlatVector () const
 Retrive all values as an std::vector, for debugging and testing. More...
 
bool IsContiguous () const
 
Tensor Contiguous () const
 
SizeVector GetShape () const
 
const SizeVectorGetShapeRef () const
 
int64_t GetShape (int64_t dim) const
 
SizeVector GetStrides () const
 
const SizeVectorGetStridesRef () const
 
int64_t GetStride (int64_t dim) const
 
void * GetDataPtr ()
 
const void * GetDataPtr () const
 
Dtype GetDtype () const
 
Device GetDevice () const
 
std::shared_ptr< BlobGetBlob () const
 
int64_t NumElements () const
 
int64_t NumDims () const
 
template<typename T >
void AssertTemplateDtype () const
 
template<>
 Tensor (const std::vector< bool > &init_vals, const SizeVector &shape, Dtype dtype, const Device &device)
 
template<>
std::vector< bool > ToFlatVector () const
 
template<typename Scalar >
void Fill (Scalar v)
 

Static Public Member Functions

static Tensor Empty (const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
 Create a tensor with uninitilized values. More...
 
template<typename T >
static Tensor Full (const SizeVector &shape, T fill_value, Dtype dtype, const Device &device=Device("CPU:0"))
 Create a tensor fill with specified value. More...
 
static Tensor Zeros (const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
 Create a tensor fill with zeros. More...
 
static Tensor Ones (const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
 Create a tensor fill with ones. More...
 
static Tensor FromDLPack (DLManagedTensor *src)
 
static SizeVector DefaultStrides (const SizeVector &shape)
 
static std::pair< bool, SizeVectorComputeNewStrides (const SizeVector &old_shape, const SizeVector &old_strides, const SizeVector &new_shape)
 

Protected Member Functions

std::string ScalarPtrToString (const void *ptr) const
 

Protected Attributes

SizeVector shape_ = {0}
 SizeVector of the Tensor. SizeVector[i] is the legnth of dimension i. More...
 
SizeVector strides_ = {1}
 
void * data_ptr_ = nullptr
 
Dtype dtype_ = Dtype::Undefined
 Data type. More...
 
std::shared_ptr< Blobblob_ = nullptr
 Underlying memory buffer for Tensor. More...
 

Detailed Description

A Tensor is a "view" of a data Blob with shape, stride, data_ptr. Tensor can also be used to perform numerical operations.

Constructor & Destructor Documentation

◆ Tensor() [1/7]

open3d::Tensor::Tensor ( )
inline

◆ Tensor() [2/7]

open3d::Tensor::Tensor ( const SizeVector shape,
Dtype  dtype,
const Device device = Device("CPU:0") 
)
inline

Constructor for creating a contiguous Tensor.

◆ Tensor() [3/7]

template<typename T >
open3d::Tensor::Tensor ( const std::vector< T > &  init_vals,
const SizeVector shape,
Dtype  dtype,
const Device device = Device("CPU:0") 
)
inline

Constructor for creating a contiguous Tensor with initial values.

◆ Tensor() [4/7]

open3d::Tensor::Tensor ( const SizeVector shape,
const SizeVector strides,
void *  data_ptr,
Dtype  dtype,
const std::shared_ptr< Blob > &  blob 
)
inline

The fully specified constructor.

◆ Tensor() [5/7]

open3d::Tensor::Tensor ( const Tensor other)
inline

Shallow copy constructor with lvalue input, e.g. Tensor dst(src).

◆ Tensor() [6/7]

open3d::Tensor::Tensor ( Tensor &&  other)
inline

Shallow copy constructor with rvalue input, e.g. Tensor dst(src[0]).

◆ Tensor() [7/7]

template<>
open3d::Tensor::Tensor ( const std::vector< bool > &  init_vals,
const SizeVector shape,
Dtype  dtype,
const Device device 
)
inline

Member Function Documentation

◆ Abs()

Tensor open3d::Tensor::Abs ( ) const

Element-wise absolute value of a tensor, returning a new tensor.

◆ Abs_()

Tensor open3d::Tensor::Abs_ ( )

Element-wise absolute value of a tensor, in-place.

◆ Add() [1/2]

Tensor open3d::Tensor::Add ( const Tensor value) const

Adds a tensor and returns the resulting tensor.

◆ Add() [2/2]

template<typename T >
Tensor open3d::Tensor::Add ( T  scalar_value) const
inline

◆ Add_() [1/2]

Tensor open3d::Tensor::Add_ ( const Tensor value)

Inplace version of Tensor::Add. Adds a tensor to the current tensor and returns the current tensor.

◆ Add_() [2/2]

template<typename T >
Tensor open3d::Tensor::Add_ ( T  scalar_value)
inline

◆ ArgMax()

Tensor open3d::Tensor::ArgMax ( const SizeVector dims) const

Returns maximum index of the tensor along the given dim. The returned tensor has dtype int64_t, and has the same shape as original tensor except that the reduced dimension is removed.

Parameters
dimsdims can only contain a single dimension or all dimensions. If dims contains a single dimension, the index is along the specified dimension. If dims contains all dimensions, the index is into the flattend tensor.

◆ ArgMin()

Tensor open3d::Tensor::ArgMin ( const SizeVector dims) const

Returns minimum index of the tensor along the given dim. The returned tensor has dtype int64_t, and has the same shape as original tensor except that the reduced dimension is removed.

Parameters
dimsdims can only contain a single dimension or all dimensions. If dims contains a single dimension, the index is along the specified dimension. If dims contains all dimensions, the index is into the flattend tensor.

◆ AsRvalue()

Tensor open3d::Tensor::AsRvalue ( ) const
inline

Convert to rvalue such that the Tensor can be assigned. E.g. in numpy tensor_a = tensor_b # tensor_a is lvalue, tensor_a variable will

now referecne tensor_b, that is, tensor_a

and tensor_b share exactly the same memory.

tensor_a[:] = tensor_b # tensor_a[:] is rvalue, tensor_b's values are

assigned to tensor_a's memory.

◆ AssertTemplateDtype()

template<typename T >
void open3d::Tensor::AssertTemplateDtype ( ) const
inline

◆ Assign()

void open3d::Tensor::Assign ( const Tensor other)

Assign (copy) values from another Tensor, shape, dtype, device may change.

Assign (copy) values from another Tensor, shape, dtype, device may change. Slices of the original Tensor still keeps the original memory. After assignment, the Tensor will be contiguous.

◆ AsStrided()

Tensor open3d::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 remain the same.

◆ Broadcast()

Tensor open3d::Tensor::Broadcast ( const SizeVector dst_shape) const

Broadcast Tensor to a new broadcastable shape.

◆ ComputeNewStrides()

std::pair< bool, SizeVector > open3d::Tensor::ComputeNewStrides ( const SizeVector old_shape,
const SizeVector old_strides,
const SizeVector new_shape 
)
static
  1. Separate oldshape into chunks of dimensions, where the dimensions are ``contiguous'' in each chunk, i.e., oldstride[i] = oldshape[i+1] * oldstride[i+1]
  2. newshape must be able to be separated into same number of chunks as oldshape was separated into, where each chunk of newshape has matching ``numel'', i.e., number of subspaces, as the corresponding chunk of oldshape. Ref: aten/src/ATen/TensorUtils.cpp

◆ Contiguous()

Tensor open3d::Tensor::Contiguous ( ) const

Returns a contiguous Tensor containing the same data in the same device. If self tensor is already contiguous, the same underlying memory will be used.

◆ Copy()

Tensor open3d::Tensor::Copy ( const Device device) const

Copy Tensor to a specified device The resulting Tensor will be compacted and contiguous

◆ CopyFrom()

void open3d::Tensor::CopyFrom ( const Tensor other)

Copy Tensor values to current tensor for source tensor.

◆ Cos()

Tensor open3d::Tensor::Cos ( ) const

Element-wise cosine of a tensor, returning a new tensor.

◆ Cos_()

Tensor open3d::Tensor::Cos_ ( )

Element-wise cosine of a tensor, in-place.

◆ DefaultStrides()

SizeVector open3d::Tensor::DefaultStrides ( const SizeVector shape)
static

◆ Div() [1/2]

Tensor open3d::Tensor::Div ( const Tensor value) const

Divides a tensor and returns the resulting tensor.

◆ Div() [2/2]

template<typename T >
Tensor open3d::Tensor::Div ( T  scalar_value) const
inline

◆ Div_() [1/2]

Tensor open3d::Tensor::Div_ ( const Tensor value)

Inplace version of Tensor::Div. Divides a tensor to the current tensor and returns the current tensor.

◆ Div_() [2/2]

template<typename T >
Tensor open3d::Tensor::Div_ ( T  scalar_value)
inline

◆ Empty()

Tensor open3d::Tensor::Empty ( const SizeVector shape,
Dtype  dtype,
const Device device = Device("CPU:0") 
)
static

Create a tensor with uninitilized values.

◆ Eq()

Tensor open3d::Tensor::Eq ( const Tensor value) const

Element-wise equals-to of tensors, returning a new boolean tensor.

◆ Eq_()

Tensor open3d::Tensor::Eq_ ( const Tensor value)

Element-wise equals-to of tensors, in-place. This operation won't change the tensor's dtype.

◆ Exp()

Tensor open3d::Tensor::Exp ( ) const

Element-wise exponential of a tensor, returning a new tensor.

◆ Exp_()

Tensor open3d::Tensor::Exp_ ( )

Element-wise base-e exponential of a tensor, in-place.

◆ Expand()

Tensor open3d::Tensor::Expand ( const SizeVector dst_shape) const

Expand Tensor to a new broadcastable shape, returning a new view.

Tensors can be expanded to broadcastable shape by setting dimension of size 1 to have stride 0, without allocating new memory.

◆ Fill() [1/2]

template<typename T >
void open3d::Tensor::Fill ( T  v)

Fill the whole Tensor with a scalar value, the scalar will be casted to the Tensor's dtype.

◆ Fill() [2/2]

template<typename Scalar >
void open3d::Tensor::Fill ( Scalar  v)
inline

◆ FromDLPack()

static Tensor open3d::Tensor::FromDLPack ( DLManagedTensor src)
inlinestatic

◆ Full()

template<typename T >
static Tensor open3d::Tensor::Full ( const SizeVector shape,
T  fill_value,
Dtype  dtype,
const Device device = Device("CPU:0") 
)
inlinestatic

Create a tensor fill with specified value.

◆ Ge()

Tensor open3d::Tensor::Ge ( const Tensor value) const

Element-wise greater-than-or-equals-to of tensors, returning a new boolean tensor.

◆ Ge_()

Tensor open3d::Tensor::Ge_ ( const Tensor value)

Element-wise greater-than-or-equals-to of tensors, in-place. This operation won't change the tensor's dtype.

◆ GetBlob()

std::shared_ptr<Blob> open3d::Tensor::GetBlob ( ) const
inline

◆ GetDataPtr() [1/2]

void* open3d::Tensor::GetDataPtr ( )
inline

◆ GetDataPtr() [2/2]

const void* open3d::Tensor::GetDataPtr ( ) const
inline

◆ GetDevice()

Device open3d::Tensor::GetDevice ( ) const

◆ GetDtype()

Dtype open3d::Tensor::GetDtype ( ) const
inline

◆ GetItem() [1/2]

Tensor open3d::Tensor::GetItem ( const TensorKey tk) const

Pythonic getitem for tensor.

Returns a view of the original tensor, if TensorKey is TensorKeyMode::Index or TensorKeyMode::Slice. Returns a copy if the TensorKey contains TensorKeyMode::IndexTensor (advanced indexing).

For example, in numpy:

t = np.empty((4, 5), dtype=np.float32)
t1 = t[2]
t2 = t[0:4:2]

The equivalent Open3D C++ calls:

Tensor t1 = t.GetItem(TensorIndex(2));
Tensor t2 = t.GetItem(TensorSlice(0, 4, 2));

◆ GetItem() [2/2]

Tensor open3d::Tensor::GetItem ( const std::vector< TensorKey > &  tks) const

Pythonic getitem for tensor.

Returns a view of the original tensor, if TensorKey only contains TensorKeyMode::Index or TensorKeyMode::Slice. Returns a copy if the TensorKey contains IndexTensor (advanced indexing).

For example, in numpy:

t = np.empty((4, 5), dtype=np.float32)
t1 = t[1, 0:4:2]

The equivalent Open3D C++ calls:

Tensor t1 = t.GetItem({TensorIndex(2), TensorSlice(0, 4, 2)});

◆ GetShape() [1/2]

SizeVector open3d::Tensor::GetShape ( ) const
inline

◆ GetShape() [2/2]

int64_t open3d::Tensor::GetShape ( int64_t  dim) const
inline

◆ GetShapeRef()

const SizeVector& open3d::Tensor::GetShapeRef ( ) const
inline

◆ GetStride()

int64_t open3d::Tensor::GetStride ( int64_t  dim) const
inline

◆ GetStrides()

SizeVector open3d::Tensor::GetStrides ( ) const
inline

◆ GetStridesRef()

const SizeVector& open3d::Tensor::GetStridesRef ( ) const
inline

◆ Gt()

Tensor open3d::Tensor::Gt ( const Tensor value) const

Element-wise greater-than of tensors, returning a new boolean tensor.

◆ Gt_()

Tensor open3d::Tensor::Gt_ ( const Tensor value)

Element-wise greater-than of tensors, in-place. This operation won't change the tensor's dtype.

◆ IndexExtract()

Tensor open3d::Tensor::IndexExtract ( int64_t  dim,
int64_t  idx 
) const

Extract the idx -th sub-tensor in dimension dim. After IndexExtract, the dimension dim will be removed.

◆ IndexGet()

Tensor open3d::Tensor::IndexGet ( const std::vector< Tensor > &  index_tensors) const

Advanced indexing getter.

We use the Numpy advanced indexing symnatics, see: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

◆ IndexSet()

void open3d::Tensor::IndexSet ( const std::vector< Tensor > &  index_tensors,
const Tensor src_tensor 
)

Advanced indexing getter.

We use the Numpy advanced indexing symnatics, see: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

Note: Only support 1D index tensors. Note: Only support advanced indices are all next to each other.

◆ IsContiguous()

bool open3d::Tensor::IsContiguous ( ) const
inline

Returns True if the underlying memory buffer is contiguous. A contiguous Tensor's data_ptr_ does not need to point to the beginning of blob_.

◆ Item()

template<typename T >
T open3d::Tensor::Item ( ) const
inline

Helper function to return scalar value of a scalar Tensor, the Tensor mush have empty shape ()

◆ Le()

Tensor open3d::Tensor::Le ( const Tensor value) const

Element-wise less-than-or-equals-to of tensors, returning a new boolean tensor.

◆ Le_()

Tensor open3d::Tensor::Le_ ( const Tensor value)

Element-wise less-than-or-equals-to of tensors, in-place. This operation won't change the tensor's dtype.

◆ LogicalAnd()

Tensor open3d::Tensor::LogicalAnd ( const Tensor value) const

Element-wise logical and of a tensor, returning a new boolean tensor.

If the tensor is not boolean, zero will be treated as False, while non-zero values will be treated as True.

◆ LogicalAnd_()

Tensor open3d::Tensor::LogicalAnd_ ( const Tensor value)

Element-wise logical and of tensors, in-place. This operation won't change the tensor's dtype.

If the tensor is not boolean, 0 will be treated as False, while non-zero will be treated as True. The tensor will be filled with 0 or 1 casted to the tensor's dtype.

◆ LogicalNot()

Tensor open3d::Tensor::LogicalNot ( ) const

Element-wise logical not of a tensor, returning a new boolean tensor.

If the tensor is not boolean, 0 will be treated as False, while non-zero will be treated as True.

◆ LogicalNot_()

Tensor open3d::Tensor::LogicalNot_ ( )

Element-wise logical not of a tensor, in-place. This operation won't change the tensor's dtype.

If the tensor is not boolean, 0 will be treated as False, while non-zero will be treated as True. The tensor will be filled with 0 or 1 casted to the tensor's dtype.

◆ LogicalOr()

Tensor open3d::Tensor::LogicalOr ( const Tensor value) const

Element-wise logical or of tensors, returning a new boolean tensor.

If the tensor is not boolean, zero will be treated as False, while non-zero values will be treated as True.

◆ LogicalOr_()

Tensor open3d::Tensor::LogicalOr_ ( const Tensor value)

Element-wise logical or of tensors, in-place. This operation won't change the tensor's dtype.

If the tensor is not boolean, 0 will be treated as False, while non-zero will be treated as True. The tensor will be filled with 0 or 1 casted to the tensor's dtype.

◆ LogicalXor()

Tensor open3d::Tensor::LogicalXor ( const Tensor value) const

Element-wise logical exclusive-or of tensors, returning a new boolean tensor.

If the tensor is not boolean, zero will be treated as False, while non-zero values will be treated as True.

◆ LogicalXor_()

Tensor open3d::Tensor::LogicalXor_ ( const Tensor value)

Element-wise logical exclusive-or of tensors, in-place. This operation won't change the tensor's dtype.

If the tensor is not boolean, zero will be treated as False, while non-zero values will be treated as True. The tensor will be filled with 0 or 1 casted to the tensor's dtype.

◆ Lt()

Tensor open3d::Tensor::Lt ( const Tensor value) const

Element-wise less-than of tensors, returning a new boolean tensor.

◆ Lt_()

Tensor open3d::Tensor::Lt_ ( const Tensor value)

Element-wise less-than of tensors, in-place. This operation won't change the tensor's dtype.

◆ Max()

Tensor open3d::Tensor::Max ( const SizeVector dims,
bool  keepdim = false 
) const

Returns max of the tensor along the given dims.

Parameters
dimsA list of dimensions to be reduced.
keepdimIf true, the reduced dims will be retained as size 1.

◆ Mean()

Tensor open3d::Tensor::Mean ( const SizeVector dims,
bool  keepdim = false 
) const

Returns the mean of the tensor along the given dims.

Parameters
dimsA list of dimensions to be reduced.
keepdimIf true, the reduced dims will be retained as size 1.

◆ Min()

Tensor open3d::Tensor::Min ( const SizeVector dims,
bool  keepdim = false 
) const

Returns min of the tensor along the given dims.

Parameters
dimsA list of dimensions to be reduced.
keepdimIf true, the reduced dims will be retained as size 1.

◆ Mul() [1/2]

Tensor open3d::Tensor::Mul ( const Tensor value) const

Multiplies a tensor and returns the resulting tensor.

◆ Mul() [2/2]

template<typename T >
Tensor open3d::Tensor::Mul ( T  scalar_value) const
inline

◆ Mul_() [1/2]

Tensor open3d::Tensor::Mul_ ( const Tensor value)

Inplace version of Tensor::Mul. Multiplies a tensor to the current tensor and returns the current tensor.

◆ Mul_() [2/2]

template<typename T >
Tensor open3d::Tensor::Mul_ ( T  scalar_value)
inline

◆ Ne()

Tensor open3d::Tensor::Ne ( const Tensor value) const

Element-wise not-equals-to of tensors, returning a new boolean tensor.

◆ Ne_()

Tensor open3d::Tensor::Ne_ ( const Tensor value)

Element-wise equals-to of tensors, in-place. This operation won't change the tensor's dtype.

◆ Neg()

Tensor open3d::Tensor::Neg ( ) const

Element-wise negation of a tensor, returning a new tensor.

◆ Neg_()

Tensor open3d::Tensor::Neg_ ( )

Element-wise negation of a tensor, in-place.

◆ NonZero()

Tensor open3d::Tensor::NonZero ( ) const

Find the indices of the elements that are non-zero. Returns an int64 tensor of shape {num_dims, num_non_zeros}, where the i-th row contains the indices of the non-zero elements in i-th dimension of the original tensor.

◆ NonZeroNumpy()

std::vector< Tensor > open3d::Tensor::NonZeroNumpy ( ) const

Find the indices of the elements that are non-zero. Returns a vector of int64 Tensors, each containing the indices of the non-zero elements in each dimension.

◆ NumDims()

int64_t open3d::Tensor::NumDims ( ) const
inline

◆ NumElements()

int64_t open3d::Tensor::NumElements ( ) const
inline

◆ Ones()

Tensor open3d::Tensor::Ones ( const SizeVector shape,
Dtype  dtype,
const Device device = Device("CPU:0") 
)
static

Create a tensor fill with ones.

◆ operator &&()

Tensor open3d::Tensor::operator&& ( const Tensor value) const
inline

◆ operator!=()

Tensor open3d::Tensor::operator!= ( const Tensor value) const
inline

◆ operator*() [1/2]

Tensor open3d::Tensor::operator* ( const Tensor value) const
inline

◆ operator*() [2/2]

template<typename T >
Tensor open3d::Tensor::operator* ( T  scalar_value) const
inline

◆ operator*=() [1/2]

Tensor open3d::Tensor::operator*= ( const Tensor value)
inline

◆ operator*=() [2/2]

template<typename T >
Tensor open3d::Tensor::operator*= ( T  scalar_value)
inline

◆ operator+() [1/2]

Tensor open3d::Tensor::operator+ ( const Tensor value) const
inline

◆ operator+() [2/2]

template<typename T >
Tensor open3d::Tensor::operator+ ( T  scalar_value) const
inline

◆ operator+=() [1/2]

Tensor open3d::Tensor::operator+= ( const Tensor value)
inline

◆ operator+=() [2/2]

template<typename T >
Tensor open3d::Tensor::operator+= ( T  scalar_value)
inline

◆ operator-() [1/2]

Tensor open3d::Tensor::operator- ( const Tensor value) const
inline

◆ operator-() [2/2]

template<typename T >
Tensor open3d::Tensor::operator- ( T  scalar_value) const
inline

◆ operator-=() [1/2]

Tensor open3d::Tensor::operator-= ( const Tensor value)
inline

◆ operator-=() [2/2]

template<typename T >
Tensor open3d::Tensor::operator-= ( T  scalar_value)
inline

◆ operator/() [1/2]

Tensor open3d::Tensor::operator/ ( const Tensor value) const
inline

◆ operator/() [2/2]

template<typename T >
Tensor open3d::Tensor::operator/ ( T  scalar_value) const
inline

◆ operator/=() [1/2]

Tensor open3d::Tensor::operator/= ( const Tensor value)
inline

◆ operator/=() [2/2]

template<typename T >
Tensor open3d::Tensor::operator/= ( T  scalar_value)
inline

◆ operator<()

Tensor open3d::Tensor::operator< ( const Tensor value) const
inline

◆ operator<=()

Tensor open3d::Tensor::operator<= ( const Tensor value) const
inline

◆ operator=() [1/5]

Tensor & open3d::Tensor::operator= ( const Tensor other) &

Tensor assignment lvalue = lvalue, e.g. tensor_a = tensor_b

Tensor assignment lvalue = lvalue, e.g. tensor_a = tensor_b, resulting in a "shallow" copy.

◆ operator=() [2/5]

Tensor & open3d::Tensor::operator= ( Tensor &&  other) &

Tensor assignment lvalue = rvalue, e.g. tensor_a = tensor_b[0]

Tensor assignment lvalue = rvalue, e.g. tensor_a = tensor_b[0], resulting in a "shallow" copy.

◆ operator=() [3/5]

Tensor & open3d::Tensor::operator= ( const Tensor other) &&

Tensor assignment rvalue = lvalue, e.g. tensor_a[0] = tensor_b

◆ operator=() [4/5]

Tensor & open3d::Tensor::operator= ( Tensor &&  other) &&

Tensor assignment rvalue = rvalue, e.g. tensor_a[0] = tensor_b[0]

◆ operator=() [5/5]

template<typename T >
Tensor& open3d::Tensor::operator= ( const T v) &&
inline

Tensor assignment rvalue = rvalue_scalar, e.g. tensor_a[0] = 100 Implicit casting is performed to the underlying dtype.

Note that we don't have lvalue = rvalue_scalar, e.g. we don't support Tensor a_slice = tensor_a[0]; a_slice = 100;

◆ operator==()

Tensor open3d::Tensor::operator== ( const Tensor value) const
inline

◆ operator>()

Tensor open3d::Tensor::operator> ( const Tensor value) const
inline

◆ operator>=()

Tensor open3d::Tensor::operator>= ( const Tensor value) const
inline

◆ operator[]()

Tensor open3d::Tensor::operator[] ( int64_t  i) const

Extract the i-th Tensor along the first axis, returning a new view.

◆ operator||()

Tensor open3d::Tensor::operator|| ( const Tensor value) const
inline

◆ Permute()

Tensor open3d::Tensor::Permute ( const SizeVector dims) const

Permute (dimension shuffle) the Tensor, returns a view.

Parameters
dimsThe desired ordering of dimensions.
Returns
A Tensor with the desired ordering of the dimensions.

◆ Prod()

Tensor open3d::Tensor::Prod ( const SizeVector dims,
bool  keepdim = false 
) const

Returns the product of the tensor along the given dims.

Parameters
dimsA list of dimensions to be reduced.
keepdimIf true, the reduced dims will be retained as size 1.

◆ Reshape()

Tensor open3d::Tensor::Reshape ( const SizeVector dst_shape) const

Returns a tensor with the same data and number of elements as input, but with the specified shape. When possible, the returned tensor will be a view of input. Otherwise, it will be a copy.

Contiguous inputs and inputs with compatible strides can be reshaped without copying, but you should not depend on the copying vs. viewing behavior.

Ref: https://pytorch.org/docs/stable/tensors.html aten/src/ATen/native/TensorShape.cpp aten/src/ATen/TensorUtils.cpp

◆ ScalarPtrToString()

std::string open3d::Tensor::ScalarPtrToString ( const void *  ptr) const
protected

◆ SetItem() [1/3]

Tensor open3d::Tensor::SetItem ( const Tensor value)

Set all items. Equivalent to tensor[:] = value in Python.

◆ SetItem() [2/3]

Tensor open3d::Tensor::SetItem ( const TensorKey tk,
const Tensor value 
)

Pythonic setitem for tensor.

For example, in numpy:

t = np.empty((4, 5), dtype=np.float32)
t[2] = np.empty((5,), dtype=np.float32)
t[0:4:2] = np.empty((2, 5), dtype=np.float32)

The equivalent Open3D C++ calls:

t.SetItem(TensorIndex(2), Tensor({5}, Dtype::Float32));
t.SetItem(TensorSlice(0, 4, 2), Tensor({2, 5}, Dtype::Float32));

◆ SetItem() [3/3]

Tensor open3d::Tensor::SetItem ( const std::vector< TensorKey > &  tks,
const Tensor value 
)

Pythonic setitem for tensor.

For example, in numpy:

t = np.empty((4, 5), dtype=np.float32)
t[2, 0:4:2] = np.empty((2, 5), dtype=np.float32)

The equivalent Open3D C++ calls:

t.SetItem({TensorIndex(2), TensorSlice(0, 4, 2)},

◆ ShallowCopyFrom()

void open3d::Tensor::ShallowCopyFrom ( const Tensor other)

Shallow copy a tensor, returning a tensor sharing the same memory.

◆ Sin()

Tensor open3d::Tensor::Sin ( ) const

Element-wise sine of a tensor, returning a new tensor.

◆ Sin_()

Tensor open3d::Tensor::Sin_ ( )

Element-wise sine of a tensor, in-place.

◆ Slice()

Tensor open3d::Tensor::Slice ( int64_t  dim,
int64_t  start,
int64_t  stop,
int64_t  step = 1 
) const

Slice Tensor.

◆ Sqrt()

Tensor open3d::Tensor::Sqrt ( ) const

Element-wise square root of a tensor, returns a new tensor.

◆ Sqrt_()

Tensor open3d::Tensor::Sqrt_ ( )

Element-wise square root of a tensor, in-place.

◆ Sub() [1/2]

Tensor open3d::Tensor::Sub ( const Tensor value) const

Substracts a tensor and returns the resulting tensor.

◆ Sub() [2/2]

template<typename T >
Tensor open3d::Tensor::Sub ( T  scalar_value) const
inline

◆ Sub_() [1/2]

Tensor open3d::Tensor::Sub_ ( const Tensor value)

Inplace version of Tensor::Sub. Substracts a tensor to the current tensor and returns the current tensor.

◆ Sub_() [2/2]

template<typename T >
Tensor open3d::Tensor::Sub_ ( T  scalar_value)
inline

◆ Sum()

Tensor open3d::Tensor::Sum ( const SizeVector dims,
bool  keepdim = false 
) const

Returns the sum of the tensor along the given dims.

Parameters
dimsA list of dimensions to be reduced.
keepdimIf true, the reduced dims will be retained as size 1.

◆ T()

Tensor open3d::Tensor::T ( ) const

Expects input to be <= 2-D Tensor by swapping dimension 0 and 1.

0-D and 1-D Tensor remains the same.

◆ To()

Tensor open3d::Tensor::To ( Dtype  dtype,
bool  copy = false 
) const

Returns a tensor with the specified dtype.

Parameters
dtypeThe targeted dtype to convert to.
copyIf true, a new tensor is always created; if false, the copy is avoided when the original tensor already have the targeted dtype.

◆ ToDLPack()

DLManagedTensor* open3d::Tensor::ToDLPack ( ) const
inline

◆ ToFlatVector() [1/2]

template<typename T >
std::vector<T> open3d::Tensor::ToFlatVector ( ) const
inline

Retrive all values as an std::vector, for debugging and testing.

◆ ToFlatVector() [2/2]

template<>
std::vector<bool> open3d::Tensor::ToFlatVector ( ) const
inline

◆ ToString()

std::string open3d::Tensor::ToString ( bool  with_suffix = true,
const std::string &  indent = "" 
) const

◆ Transpose()

Tensor open3d::Tensor::Transpose ( int64_t  dim0,
int64_t  dim1 
) const

Transpose a Tensor by swapping dimension dim0 and dim1.

Parameters
dim0The first dimension to be transposed.
dim1The second dimension to be transposed.

◆ View()

Tensor open3d::Tensor::View ( const SizeVector dst_shape) const

Returns a new tensor view with the same data but of a different shape.

The returned tensor shares the same data and must have the same number of elements, but may have a different size. For a tensor to be viewed, the new view size must be compatible with its original size and stride, i.e., each new view dimension must either be a subspace of an original dimension, or only span across original dimensions d, d+1, ..., d+kd,d+1, ..., d+k that satisfy the following contiguity-like condition that for all i = 0, ..., k-1, strides[i] = stride[i + 1] * shape[i + 1].

Otherwise, contiguous() needs to be called before the tensor can be viewed. See also: reshape(), which returns a view if the shapes are compatible, and copies (equivalent to calling contiguous()) otherwise.

Ref: https://pytorch.org/docs/stable/tensors.html aten/src/ATen/native/TensorShape.cpp aten/src/ATen/TensorUtils.cpp

◆ Zeros()

Tensor open3d::Tensor::Zeros ( const SizeVector shape,
Dtype  dtype,
const Device device = Device("CPU:0") 
)
static

Create a tensor fill with zeros.

Field Documentation

◆ blob_

std::shared_ptr<Blob> open3d::Tensor::blob_ = nullptr
protected

Underlying memory buffer for Tensor.

◆ data_ptr_

void* open3d::Tensor::data_ptr_ = nullptr
protected

Data pointer pointing to the beginning element of the Tensor.

Note that this is not necessarily the same as blob_.GetDataPtr(). When this happens, it means that the beginning element of the Tensor is not located a the beginning of the underlying blob. This could happen, for instance, at slicing:

// a.GetDataPtr() == a.GetBlob().GetDataPtr()
Tensor a({2, 3}, dtype, "CPU:0");
// b.GetDataPtr() != b.GetBlob().GetDataPtr()
b = a[1];

◆ dtype_

Dtype open3d::Tensor::dtype_ = Dtype::Undefined
protected

Data type.

◆ shape_

SizeVector open3d::Tensor::shape_ = {0}
protected

SizeVector of the Tensor. SizeVector[i] is the legnth of dimension i.

◆ strides_

SizeVector open3d::Tensor::strides_ = {1}
protected

Stride of a Tensor. The stride of a n-dimensional tensor is also n-dimensional. Stride(i) is the number of elements (not bytes) to jump in a continuous memory space before eaching the next element in dimension i. For example, a 2x3x4 float32 dense tensor has shape(2, 3, 4) and stride(12, 4, 1). A slicing operation performed on the tensor can change the shape and stride.


The documentation for this class was generated from the following files: