Open3D (C++ API)  0.18.0+252c867
Data Structures | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
open3d::core::Tensor Class Reference

#include <Tensor.h>

Inheritance diagram for open3d::core::Tensor:
open3d::core::IsDevice

Data Structures

struct  ConstIterator
 Const iterator for Tensor. More...
 
struct  Iterator
 Iterator for Tensor. More...
 

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...
 
template<typename T >
 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. More...
 
 Tensor (const SizeVector &shape, const SizeVector &strides, void *data_ptr, Dtype dtype, const std::shared_ptr< Blob > &blob)
 
template<typename T >
 Tensor (std::vector< T > &&vec, const SizeVector &shape={})
 Take ownership of data in std::vector<T> More...
 
 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. More...
 
 Tensor (const Tensor &other)=default
 
 Tensor (Tensor &&other)=default
 
Tensoroperator= (const Tensor &other) &
 
Tensoroperator= (Tensor &&other) &
 
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) &&
 
Tensor ReinterpretCast (const core::Dtype &dtype) const
 
template<typename Object >
TensorAssignObject (const Object &v) &&
 
template<typename S >
void Fill (S v)
 Fill the whole Tensor with a scalar value, the scalar will be casted to the Tensor's Dtype. More...
 
template<typename Object >
void FillObject (const Object &v)
 
Tensor Reverse () const
 Reverse a Tensor's elements by viewing the tensor as a 1D array. 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)
 
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 must have same data-type, device, and number of dimensions. All dimensions must be the same, except the dimension along the axis the tensors are to be appended. 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 Flatten (int64_t start_dim=0, int64_t end_dim=-1) const
 
Tensor View (const SizeVector &dst_shape) const
 
Tensor Clone () const
 Copy Tensor to the same device. More...
 
void CopyFrom (const Tensor &other)
 Copy Tensor values to current tensor from the source tensor. More...
 
Tensor To (Dtype dtype, bool copy=false) const
 
Tensor To (const Device &device, bool copy=false) const
 
Tensor To (const Device &device, 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
 
Tensor AsRvalue ()
 
const Tensor AsRvalue () const
 Convert to constant rvalue. More...
 
Tensor IndexGet (const std::vector< Tensor > &index_tensors) const
 Advanced indexing getter. This will always allocate a new Tensor. More...
 
void IndexSet (const std::vector< Tensor > &index_tensors, const Tensor &src_tensor)
 Advanced indexing getter. More...
 
void IndexAdd_ (int64_t dim, const Tensor &index, const Tensor &src)
 Advanced in-place reduction by index. 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...
 
double Det () const
 Compute the determinant of a 2D square tensor. More...
 
template<typename T >
T Item () const
 
Tensor Add (const Tensor &value) const
 Adds a tensor and returns the resulting tensor. More...
 
Tensor Add (Scalar value) const
 
Tensor operator+ (const Tensor &value) const
 
Tensor operator+ (Scalar value) const
 
Tensor Add_ (const Tensor &value)
 
Tensor Add_ (Scalar value)
 
Tensor operator+= (const Tensor &value)
 
Tensor operator+= (Scalar value)
 
Tensor Sub (const Tensor &value) const
 Substracts a tensor and returns the resulting tensor. More...
 
Tensor Sub (Scalar value) const
 
Tensor operator- (const Tensor &value) const
 
Tensor operator- (Scalar value) const
 
Tensor Sub_ (const Tensor &value)
 
Tensor Sub_ (Scalar value)
 
Tensor operator-= (const Tensor &value)
 
Tensor operator-= (Scalar value)
 
Tensor Mul (const Tensor &value) const
 Multiplies a tensor and returns the resulting tensor. More...
 
Tensor Mul (Scalar value) const
 
Tensor operator* (const Tensor &value) const
 
Tensor operator* (Scalar value) const
 
Tensor Mul_ (const Tensor &value)
 
Tensor Mul_ (Scalar value)
 
Tensor operator*= (const Tensor &value)
 
Tensor operator*= (Scalar value)
 
Tensor Div (const Tensor &value) const
 Divides a tensor and returns the resulting tensor. More...
 
Tensor Div (Scalar value) const
 
Tensor operator/ (const Tensor &value) const
 
Tensor operator/ (Scalar value) const
 
Tensor Div_ (const Tensor &value)
 
Tensor Div_ (Scalar value)
 
Tensor operator/= (const Tensor &value)
 
Tensor operator/= (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 operator- () const
 Unary minus of a tensor, returning a new tensor. 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 IsNan () const
 
Tensor IsInf () const
 
Tensor IsFinite () const
 
Tensor Clip (Scalar min_val, Scalar max_val) const
 
Tensor Clip_ (Scalar min_val, Scalar max_val)
 
Tensor Floor () const
 Element-wise floor value of a tensor, returning a new tensor. More...
 
Tensor Ceil () const
 Element-wise ceil value of a tensor, returning a new tensor. More...
 
Tensor Round () const
 Element-wise round value of a tensor, returning a new tensor. More...
 
Tensor Trunc () const
 Element-wise trunc value of a tensor, returning a new tensor. More...
 
Tensor LogicalNot () const
 
Tensor LogicalNot_ ()
 
Tensor LogicalAnd (const Tensor &value) const
 
Tensor operator&& (const Tensor &value) const
 
Tensor LogicalAnd (Scalar value) const
 
Tensor LogicalAnd_ (const Tensor &value)
 
Tensor LogicalAnd_ (Scalar value)
 
Tensor LogicalOr (const Tensor &value) const
 
Tensor operator|| (const Tensor &value) const
 
Tensor LogicalOr (Scalar value) const
 
Tensor LogicalOr_ (const Tensor &value)
 
Tensor LogicalOr_ (Scalar value)
 
Tensor LogicalXor (const Tensor &value) const
 
Tensor LogicalXor (Scalar value) const
 
Tensor LogicalXor_ (const Tensor &value)
 
Tensor LogicalXor_ (Scalar 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 (Scalar value) const
 
Tensor Gt_ (const Tensor &value)
 
Tensor Gt_ (Scalar 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 (Scalar value) const
 
Tensor Lt_ (const Tensor &value)
 
Tensor Lt_ (Scalar value)
 
Tensor Ge (const Tensor &value) const
 
Tensor operator>= (const Tensor &value) const
 
Tensor Ge (Scalar value) const
 
Tensor Ge_ (const Tensor &value)
 
Tensor Ge_ (Scalar value)
 
Tensor Le (const Tensor &value) const
 
Tensor operator<= (const Tensor &value) const
 
Tensor Le (Scalar value) const
 
Tensor Le_ (const Tensor &value)
 
Tensor Le_ (Scalar 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 (Scalar value) const
 
Tensor Eq_ (const Tensor &value)
 
Tensor Eq_ (Scalar 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 (Scalar value) const
 
Tensor Ne_ (const Tensor &value)
 
Tensor Ne_ (Scalar value)
 
std::vector< TensorNonZeroNumpy () const
 
Tensor NonZero () const
 
bool IsNonZero () const
 
Tensor All (const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
 
Tensor Any (const utility::optional< SizeVector > &dims=utility::nullopt, bool keepdim=false) const
 
bool AllEqual (const Tensor &other) const
 
bool AllClose (const Tensor &other, double rtol=1e-5, double atol=1e-8) const
 
Tensor IsClose (const Tensor &other, double rtol=1e-5, double atol=1e-8) const
 
bool IsSame (const Tensor &other) const
 
template<typename T >
std::vector< TToFlatVector () const
 Retrieve all values as an std::vector, for debugging and testing. More...
 
bool IsContiguous () const
 
Tensor Contiguous () const
 
Tensor Matmul (const Tensor &rhs) const
 
Tensor Solve (const Tensor &rhs) const
 
Tensor LeastSquares (const Tensor &rhs) const
 
std::tuple< Tensor, Tensor, TensorLU (const bool permute_l=false) const
 Computes LU factorisation of the 2D square tensor, using A = P * L * U; where P is the permutation matrix, L is the lower-triangular matrix with diagonal elements as 1.0 and U is the upper-triangular matrix, and returns tuple (P, L, U). More...
 
std::tuple< Tensor, TensorLUIpiv () const
 Computes LU factorisation of the 2D square tensor, using A = P * L * U; where P is the permutation matrix, L is the lower-triangular matrix with diagonal elements as 1.0 and U is the upper-triangular matrix, and returns tuple output tensor of shape {n,n} and ipiv tensor of shape {n}, where {n,n} is the shape of input tensor. [ipiv, output = open3d.core.lu_ipiv(a)]. More...
 
Tensor Triu (const int diagonal=0) const
 Returns the upper triangular matrix of the 2D tensor, above the given diagonal index. [The value of diagonal = col - row, therefore 0 is the main diagonal (row = col), and it shifts towards right for positive values (for diagonal = 1, col - row = 1), and towards left for negative values. The value of the diagonal parameter must be between [-m, n] for a {m,n} shaped tensor. More...
 
Tensor Tril (const int diagonal=0) const
 Returns the lower triangular matrix of the 2D tensor, above the given diagonal index. [The value of diagonal = col - row, therefore 0 is the main diagonal (row = col), and it shifts towards right for positive values (for diagonal = 1, col - row = 1), and towards left for negative values. The value of the diagonal parameter must be between [-m, n] where {m, n} is the shape of input tensor. More...
 
std::tuple< Tensor, TensorTriul (const int diagonal=0) const
 Returns the tuple of upper and lower triangular matrix of the 2D tensor, above and below the given diagonal index. The diagonal elements of lower triangular matrix are taken to be unity. [The value of diagonal = col - row, therefore 0 is the main diagonal (row = col), and it shifts towards right for positive values (for diagonal = 1, col - row = 1), and towards left for negative values. The value of the diagonal parameter must be between [-m, n] where {m, n} is the shape of input tensor. More...
 
Tensor Inverse () const
 
std::tuple< Tensor, Tensor, TensorSVD () const
 
int64_t GetLength () 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
 
template<typename T >
TGetDataPtr ()
 
template<typename T >
const TGetDataPtr () const
 
void * GetDataPtr ()
 
const void * GetDataPtr () const
 
Dtype GetDtype () const
 
Device GetDevice () const override
 
std::shared_ptr< BlobGetBlob () const
 
int64_t NumElements () const
 
int64_t NumDims () const
 
template<typename T >
void AssertTemplateDtype () const
 
DLManagedTensorToDLPack () const
 Convert the Tensor to DLManagedTensor. More...
 
void Save (const std::string &file_name) const
 Save tensor to numpy's npy format. More...
 
Iterator begin ()
 
Iterator end ()
 
ConstIterator cbegin () const
 
ConstIterator cend () const
 
ConstIterator begin () const
 
ConstIterator end () const
 
template<>
 Tensor (const std::vector< bool > &init_vals, const SizeVector &shape, Dtype dtype, const Device &device)
 
template<>
std::vector< bool > ToFlatVector () const
 
template<>
bool Item () const
 
- Public Member Functions inherited from open3d::core::IsDevice
 IsDevice ()=default
 
virtual ~IsDevice ()=default
 
bool IsCPU () const
 
bool IsCUDA () const
 

Static Public Member Functions

static Tensor Empty (const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
 Create a tensor with uninitialized values. More...
 
static Tensor EmptyLike (const Tensor &other)
 
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...
 
template<typename T >
static Tensor Init (const T val, const Device &device=Device("CPU:0"))
 
template<typename T >
static Tensor Init (const std::initializer_list< T > &in_list, const Device &device=Device("CPU:0"))
 
template<typename T >
static Tensor Init (const std::initializer_list< std::initializer_list< T >> &in_list, const Device &device=Device("CPU:0"))
 
template<typename T >
static Tensor Init (const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &in_list, const Device &device=Device("CPU:0"))
 
static Tensor Eye (int64_t n, Dtype dtype, const Device &device)
 Create an identity matrix of size n x n. More...
 
static Tensor Diag (const Tensor &input)
 Create a square matrix with specified diagonal elements in input. More...
 
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. More...
 
static Tensor FromDLPack (const DLManagedTensor *dlmt)
 Convert DLManagedTensor to Tensor. More...
 
static Tensor Load (const std::string &file_name)
 Load tensor from numpy's npy format. More...
 

Protected Member Functions

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

Protected Attributes

SizeVector shape_ = {0}
 SizeVector of the Tensor. shape_[i] is the length of dimension i. More...
 
SizeVector strides_ = {1}
 
void * data_ptr_ = nullptr
 
Dtype dtype_ = core::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/10]

open3d::core::Tensor::Tensor ( )
inline

◆ Tensor() [2/10]

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

Constructor for creating a contiguous Tensor.

◆ Tensor() [3/10]

template<typename T >
open3d::core::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/10]

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

Constructor from raw host buffer. The memory will be copied.

◆ Tensor() [5/10]

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

The fully specified constructor. Since you're responsible for creating the Blob, take care of Blob's deleter if the memory is allocated elsewhere. See Blob.h for more details.

◆ Tensor() [6/10]

template<typename T >
open3d::core::Tensor::Tensor ( std::vector< T > &&  vec,
const SizeVector shape = {} 
)
inline

Take ownership of data in std::vector<T>

Create a Tensor from data "moved" from an std::vector<T>. This always produces a Tensor on the CPU device.

Parameters
vecsource for the data as an r-value reference. After the Tensor is created this will not have access to or manage the data any more.
shapeList of dimensions of data in buffer. e.g. {640, 480, 3} for a 640x480 RGB image. A 1D {vec.size()} shape is assumed if not specified.

◆ Tensor() [7/10]

open3d::core::Tensor::Tensor ( void *  data_ptr,
Dtype  dtype,
const SizeVector shape,
const SizeVector strides = {},
const Device device = Device("CPU:0") 
)
inline

Tensor wrapper constructor from raw host buffer.

This creates a Tensor wrapper for externally managed memory. It is the user's responsibility to keep the buffer valid during the lifetime of this Tensor and deallocate it afterwards.

Parameters
data_ptrPointer to externally managed buffer.
dtypeTensor element data type. e.g. Float32 for single precision float.
shapeList of dimensions of data in buffer. e.g. {640, 480, 3} for a 640x480 RGB image.
stridesNumber of elements to advance to reach the next element, for every dimension. This will be calculated from the shape assuming a contiguous buffer if not specified. For the above Float32 image, the value of an element will be read as:
image[row, col, ch] = *(float *) (data_ptr + sizeof(float) *
(row * stride[0] + col * stride[1] + ch * stride[2]));
deviceDevice containing the data buffer.

◆ Tensor() [8/10]

open3d::core::Tensor::Tensor ( const Tensor other)
default

Copy constructor performs a "shallow" copy of the Tensor. This takes a lvalue input, e.g. Tensor dst(src).

◆ Tensor() [9/10]

open3d::core::Tensor::Tensor ( Tensor &&  other)
default

Move constructor performs a "shallow" copy of the Tensor. This takes a rvalue input, e.g. Tensor dst(src[0]).

◆ Tensor() [10/10]

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

Member Function Documentation

◆ Abs()

Tensor open3d::core::Tensor::Abs ( ) const

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

◆ Abs_()

Tensor open3d::core::Tensor::Abs_ ( )

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

◆ Add() [1/2]

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

Adds a tensor and returns the resulting tensor.

◆ Add() [2/2]

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

◆ Add_() [1/2]

Tensor open3d::core::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]

Tensor open3d::core::Tensor::Add_ ( Scalar  value)

◆ All()

Tensor open3d::core::Tensor::All ( const utility::optional< SizeVector > &  dims = utility::nullopt,
bool  keepdim = false 
) const

Returns true if all elements in the tensor are true. Only works for boolean tensors.

◆ AllClose()

bool open3d::core::Tensor::AllClose ( const Tensor other,
double  rtol = 1e-5,
double  atol = 1e-8 
) const

Returns true if the two tensors are element-wise equal within a tolerance.

  • If the device is not the same: throws exception.
  • If the dtype is not the same: throws exception.
  • If the shape is not the same: returns false.
  • Returns true if: abs(self - other) <= (atol + rtol * abs(other)).

The equation is not symmetrical, i.e. a.AllClose(b) might not be the same as b.AllClose(a). Also see Numpy's documentation: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html.

TODO: support nan

Parameters
otherThe other tensor to compare with.
rtolRelative tolerance.
atolAbsolute tolerance.

◆ AllEqual()

bool open3d::core::Tensor::AllEqual ( const Tensor other) const

Returns true if the two tensors are element-wise equal.

  • If the device is not the same: throws exception.
  • If the dtype is not the same: throws exception.
  • If the shape is not the same: returns false.
  • Returns true if: the device, dtype and shape are the same and all corresponding elements are equal.

TODO: support nan

Parameters
otherThe other tensor to compare with.

◆ Any()

Tensor open3d::core::Tensor::Any ( const utility::optional< SizeVector > &  dims = utility::nullopt,
bool  keepdim = false 
) const

Returns true if any elements in the tensor are true. Only works for boolean tensors.

◆ Append()

Tensor open3d::core::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 must have same data-type, device, and number of dimensions. All dimensions must be the same, except the dimension along the axis the tensors are to be appended.

This is the same as NumPy's semantics:

Example:

Tensor a = Tensor::Init<int64_t>({0, 1}, {2, 3});
Tensor b = Tensor::Init<int64_t>({4, 5});
Tensor t1 = a.Append(b, 0);
// t1:
// [[0 1],
// [2 3],
// [4 5]]
// Tensor[shape={3, 2}, stride={2, 1}, Int64, CPU:0, 0x55555abc6b00]
Tensor t2 = a.Append(b);
// t2:
// [0 1 2 3 4 5]
// Tensor[shape={6}, stride={1}, Int64, CPU:0, 0x55555abc6b70]
Tensor()
Definition: Tensor.h:34
Parameters
otherValues of this tensor is appended to the tensor.
axis[optional] The axis along which values are appended. If axis is not given, both tensors are flattened before use.
Returns
A copy of the tensor with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled. If axis is None, out is a flattened tensor.

◆ Arange()

Tensor open3d::core::Tensor::Arange ( const Scalar  start,
const Scalar  stop,
const Scalar  step = 1,
const Dtype  dtype = core::Int64,
const Device device = core::Device("CPU:0") 
)
static

Create a 1D tensor with evenly spaced values in the given interval.

◆ ArgMax()

Tensor open3d::core::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 flattened tensor.

◆ ArgMin()

Tensor open3d::core::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 flattened tensor.

◆ AsRvalue() [1/2]

Tensor open3d::core::Tensor::AsRvalue ( )
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 reference 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.

◆ AsRvalue() [2/2]

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

Convert to constant rvalue.

◆ AssertTemplateDtype()

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

◆ AssignObject()

template<typename Object >
Tensor& open3d::core::Tensor::AssignObject ( const Object &  v) &&
inline

Assign an object to a tensor. The tensor being assigned to must be a scalar tensor of shape {}. The element byte size of the tensor must be the same as the size of the object. The object must be a POD.

◆ AsStrided()

Tensor open3d::core::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.

◆ begin() [1/2]

Tensor::Iterator open3d::core::Tensor::begin ( )

Returns the beginning of the tensor iterator. The iterator iterates over the first dimension of the tensor. The generated tensor slices share the same memory with the original tensor.

◆ begin() [2/2]

ConstIterator open3d::core::Tensor::begin ( ) const
inline

Returns the beginning of the const tensor iterator. The iterator iterates over the first dimension of the tensor. The generated tensor slices share the same memory with the original tensor. This is equivalent to Tensor::cbegin().

◆ Broadcast()

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

Broadcast Tensor to a new broadcastable shape.

◆ cbegin()

Tensor::ConstIterator open3d::core::Tensor::cbegin ( ) const

Returns the beginning of the const tensor iterator. The iterator iterates over the first dimension of the tensor. The generated tensor slices share the same memory with the original tensor.

◆ Ceil()

Tensor open3d::core::Tensor::Ceil ( ) const

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

◆ cend()

Tensor::ConstIterator open3d::core::Tensor::cend ( ) const

Returns the end of the const tensor iterator. The iterator iterates over the first dimension of the tensor. The generated tensor slices share the same memory with the original tensor.

◆ Clip()

Tensor open3d::core::Tensor::Clip ( Scalar  min_val,
Scalar  max_val 
) const

Element-wise clipping of tensor values so that resulting values lie in the range [min_val, max_val], returning a new tensor.

Parameters
min_valLower bound for output values.
max_valUpper bound for output values.

◆ Clip_()

Tensor open3d::core::Tensor::Clip_ ( Scalar  min_val,
Scalar  max_val 
)

Element-wise clipping of tensor values so that resulting values lie in the range [min_val, max_val]. In-place version.

Parameters
min_valLower bound for output values.
max_valUpper bound for output values.

◆ Clone()

Tensor open3d::core::Tensor::Clone ( ) const
inline

Copy Tensor to the same device.

◆ Contiguous()

Tensor open3d::core::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.

◆ CopyFrom()

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

Copy Tensor values to current tensor from the source tensor.

◆ Cos()

Tensor open3d::core::Tensor::Cos ( ) const

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

◆ Cos_()

Tensor open3d::core::Tensor::Cos_ ( )

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

◆ Det()

double open3d::core::Tensor::Det ( ) const

Compute the determinant of a 2D square tensor.

Returns
returns the determinant of the matrix (double).

◆ Diag()

Tensor open3d::core::Tensor::Diag ( const Tensor input)
static

Create a square matrix with specified diagonal elements in input.

◆ Div() [1/2]

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

Divides a tensor and returns the resulting tensor.

◆ Div() [2/2]

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

◆ Div_() [1/2]

Tensor open3d::core::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]

Tensor open3d::core::Tensor::Div_ ( Scalar  value)

◆ Empty()

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

Create a tensor with uninitialized values.

◆ EmptyLike()

static Tensor open3d::core::Tensor::EmptyLike ( const Tensor other)
inlinestatic

Create a tensor with uninitialized values with the same Dtype and Device as the other tensor.

◆ end() [1/2]

Tensor::Iterator open3d::core::Tensor::end ( )

Returns the end of the tensor iterator. The iterator iterates over the first dimension of the tensor. The generated tensor slices share the same memory with the original tensor.

◆ end() [2/2]

ConstIterator open3d::core::Tensor::end ( ) const
inline

Returns the end of the const tensor iterator. The iterator iterates over the first dimension of the tensor. The generated tensor slices share the same memory with the original tensor. This is equivalent to Tensor::cend().

◆ Eq() [1/2]

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

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

◆ Eq() [2/2]

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

◆ Eq_() [1/2]

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

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

◆ Eq_() [2/2]

Tensor open3d::core::Tensor::Eq_ ( Scalar  value)

◆ Exp()

Tensor open3d::core::Tensor::Exp ( ) const

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

◆ Exp_()

Tensor open3d::core::Tensor::Exp_ ( )

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

◆ Expand()

Tensor open3d::core::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.

◆ Eye()

Tensor open3d::core::Tensor::Eye ( int64_t  n,
Dtype  dtype,
const Device device 
)
static

Create an identity matrix of size n x n.

◆ Fill()

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

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

◆ FillObject()

template<typename Object >
void open3d::core::Tensor::FillObject ( const Object &  v)
inline

◆ Flatten()

Tensor open3d::core::Tensor::Flatten ( int64_t  start_dim = 0,
int64_t  end_dim = -1 
) const

Flattens input by reshaping it into a one-dimensional tensor. If start_dim or end_dim are passed, only dimensions starting with start_dim and ending with end_dim are flattened. The order of elements in input is unchanged.

Unlike NumPy’s flatten, which always copies input’s data, this function may return the original object, a view, or copy. If no dimensions are flattened, then the original object input is returned. Otherwise, if input can be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the flattened shape is input’s data copied.

Ref:

Parameters
start_dimThe first dimension to flatten (inclusive).
end_dimThe last dimension to flatten, starting from start_dim (inclusive).

◆ Floor()

Tensor open3d::core::Tensor::Floor ( ) const

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

◆ FromDLPack()

Tensor open3d::core::Tensor::FromDLPack ( const DLManagedTensor dlmt)
static

Convert DLManagedTensor to Tensor.

◆ Full()

template<typename T >
static Tensor open3d::core::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() [1/2]

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

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

◆ Ge() [2/2]

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

◆ Ge_() [1/2]

Tensor open3d::core::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.

◆ Ge_() [2/2]

Tensor open3d::core::Tensor::Ge_ ( Scalar  value)

◆ GetBlob()

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

◆ GetDataPtr() [1/4]

template<typename T >
T* open3d::core::Tensor::GetDataPtr ( )
inline

◆ GetDataPtr() [2/4]

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

◆ GetDataPtr() [3/4]

template<typename T >
const T* open3d::core::Tensor::GetDataPtr ( ) const
inline

◆ GetDataPtr() [4/4]

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

◆ GetDevice()

Device open3d::core::Tensor::GetDevice ( ) const
overridevirtual

◆ GetDtype()

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

◆ GetItem() [1/2]

Tensor open3d::core::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 t({4, 5}, core::Float32);
Tensor t1 = t.GetItem({TensorIndex(2), TensorSlice(0, 4, 2)});
const Dtype Float32
Definition: Dtype.cpp:42

◆ GetItem() [2/2]

Tensor open3d::core::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 t({4, 5}, core::Float32);
Tensor t1 = t.GetItem(TensorIndex(2));
Tensor t2 = t.GetItem(TensorSlice(0, 4, 2));

◆ GetLength()

int64_t open3d::core::Tensor::GetLength ( ) const
inline

Returns the size of the first dimension. If NumDims() == 0, an exception will be thrown.

◆ GetShape() [1/2]

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

◆ GetShape() [2/2]

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

◆ GetShapeRef()

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

◆ GetStride()

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

◆ GetStrides()

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

◆ GetStridesRef()

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

◆ Gt() [1/2]

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

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

◆ Gt() [2/2]

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

◆ Gt_() [1/2]

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

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

◆ Gt_() [2/2]

Tensor open3d::core::Tensor::Gt_ ( Scalar  value)

◆ IndexAdd_()

void open3d::core::Tensor::IndexAdd_ ( int64_t  dim,
const Tensor index,
const Tensor src 
)

Advanced in-place reduction by index.

See https://pytorch.org/docs/stable/generated/torch.Tensor.index_add_.html

self[index[i]] = operator(self[index[i]], src[i]).

Note: Only support 1D index and src tensors now.

◆ IndexExtract()

Tensor open3d::core::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::core::Tensor::IndexGet ( const std::vector< Tensor > &  index_tensors) const

Advanced indexing getter. This will always allocate a new Tensor.

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

◆ IndexSet()

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

Advanced indexing getter.

We use the Numpy advanced indexing semantics, 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.

◆ Init() [1/4]

template<typename T >
static Tensor open3d::core::Tensor::Init ( const std::initializer_list< std::initializer_list< std::initializer_list< T >>> &  in_list,
const Device device = Device("CPU:0") 
)
inlinestatic

Create a 3-D tensor with nested initializer list, e.g., core::Tensor::Init<float>({{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}});

◆ Init() [2/4]

template<typename T >
static Tensor open3d::core::Tensor::Init ( const std::initializer_list< std::initializer_list< T >> &  in_list,
const Device device = Device("CPU:0") 
)
inlinestatic

Create a 2-D tensor with nested initializer list, e.g., core::Tensor::Init<float>({{0, 1, 2}, {3, 4, 5}});

◆ Init() [3/4]

template<typename T >
static Tensor open3d::core::Tensor::Init ( const std::initializer_list< T > &  in_list,
const Device device = Device("CPU:0") 
)
inlinestatic

Create a 1-D tensor with initializer list, e.g., core::Tensor::Init<float>({0, 1, 2});

◆ Init() [4/4]

template<typename T >
static Tensor open3d::core::Tensor::Init ( const T  val,
const Device device = Device("CPU:0") 
)
inlinestatic

Create a 0-D tensor (scalar) with given value, e.g., core::Tensor::Init<float>(0);

◆ Inverse()

Tensor open3d::core::Tensor::Inverse ( ) const

Computes the matrix inversion of the square matrix *this with LU factorization and returns the result.

◆ IsClose()

Tensor open3d::core::Tensor::IsClose ( const Tensor other,
double  rtol = 1e-5,
double  atol = 1e-8 
) const

Element-wise version of Tensor::AllClose().

  • If the device is not the same: throws exception.
  • If the dtype is not the same: throws exception.
  • If the shape is not the same: throws exception.
  • For each element in the returned tensor: abs(self - other) <= (atol + rtol * abs(other)).

The equation is not symmetrial, i.e. a.AllClose(b) might not be the same as b.AllClose(a). Also see Numpy's documentation: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html.

TODO: support nan

Parameters
otherThe other tensor to compare with.
rtolRelative tolerance.
atolAbsolute tolerance.
Returns
A boolean tensor indicating where the tensor is close.

◆ IsContiguous()

bool open3d::core::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_.

◆ IsFinite()

Tensor open3d::core::Tensor::IsFinite ( ) const

Element-wise check for finite values (not Inf or NaN) in a tensor, returning a new Boolean tensor. Non-floating point tensors return all True values.

◆ IsInf()

Tensor open3d::core::Tensor::IsInf ( ) const

Element-wise check for Infinity values in a tensor, returning a new Boolean tensor. Non-floating point tensors return all False values.

◆ IsNan()

Tensor open3d::core::Tensor::IsNan ( ) const

Element-wise check for NaN values in a tensor, returning a new Boolean tensor. Non-floating point tensors return all False values.

◆ IsNonZero()

bool open3d::core::Tensor::IsNonZero ( ) const

Evaluate a single-element Tensor as a boolean value. This can be used to implement Tensor.__bool__() in Python, e.g.

assert Tensor([True]) # Passes.
assert Tensor([123]) # Passes.
assert Tensor([False]) # AssertionError.
assert Tensor([0]) # AssertionError.
assert Tensor([True, False]) # ValueError: cannot be evaluated as bool.

◆ IsSame()

bool open3d::core::Tensor::IsSame ( const Tensor other) const

Returns true iff the tensor is the other tensor. This means that, the two tensors have the same underlying memory, device, dtype, shape, strides and etc.

◆ Item() [1/2]

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

Helper function to return scalar value of a scalar Tensor, the Tensor must have empty shape.

◆ Item() [2/2]

template<>
bool open3d::core::Tensor::Item ( ) const
inline

◆ Le() [1/2]

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

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

◆ Le() [2/2]

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

◆ Le_() [1/2]

Tensor open3d::core::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.

◆ Le_() [2/2]

Tensor open3d::core::Tensor::Le_ ( Scalar  value)

◆ LeastSquares()

Tensor open3d::core::Tensor::LeastSquares ( const Tensor rhs) const

Solves the linear system AX = B with QR decomposition and returns X. A is a (m, n) matrix with m >= n.

◆ Load()

Tensor open3d::core::Tensor::Load ( const std::string &  file_name)
static

Load tensor from numpy's npy format.

◆ LogicalAnd() [1/2]

Tensor open3d::core::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() [2/2]

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

◆ LogicalAnd_() [1/2]

Tensor open3d::core::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.

◆ LogicalAnd_() [2/2]

Tensor open3d::core::Tensor::LogicalAnd_ ( Scalar  value)

◆ LogicalNot()

Tensor open3d::core::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::core::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() [1/2]

Tensor open3d::core::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() [2/2]

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

◆ LogicalOr_() [1/2]

Tensor open3d::core::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.

◆ LogicalOr_() [2/2]

Tensor open3d::core::Tensor::LogicalOr_ ( Scalar  value)

◆ LogicalXor() [1/2]

Tensor open3d::core::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() [2/2]

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

◆ LogicalXor_() [1/2]

Tensor open3d::core::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.

◆ LogicalXor_() [2/2]

Tensor open3d::core::Tensor::LogicalXor_ ( Scalar  value)

◆ Lt() [1/2]

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

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

◆ Lt() [2/2]

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

◆ Lt_() [1/2]

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

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

◆ Lt_() [2/2]

Tensor open3d::core::Tensor::Lt_ ( Scalar  value)

◆ LU()

std::tuple< Tensor, Tensor, Tensor > open3d::core::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 matrix, L is the lower-triangular matrix with diagonal elements as 1.0 and U is the upper-triangular matrix, and returns tuple (P, L, U).

Parameters
permute_l[optional input] If true: returns L as P * L.
Returns
Tuple (P, L, U).

◆ LUIpiv()

std::tuple< Tensor, Tensor > open3d::core::Tensor::LUIpiv ( ) const

Computes LU factorisation of the 2D square tensor, using A = P * L * U; where P is the permutation matrix, L is the lower-triangular matrix with diagonal elements as 1.0 and U is the upper-triangular matrix, and returns tuple output tensor of shape {n,n} and ipiv tensor of shape {n}, where {n,n} is the shape of input tensor. [ipiv, output = open3d.core.lu_ipiv(a)].

Returns
Tuple {ipiv, output}. Where ipiv is a 1D integer pivort indices tensor. It contains the pivot indices, indicating row i of the matrix was interchanged with row ipiv(i)); and output it has L as lower triangular values and U as upper triangle values including the main diagonal (diagonal elements of L to be taken as unity).

◆ Matmul()

Tensor open3d::core::Tensor::Matmul ( const Tensor rhs) const

Computes matrix multiplication with *this and rhs and returns the result.

◆ Max()

Tensor open3d::core::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::core::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::core::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::core::Tensor::Mul ( const Tensor value) const

Multiplies a tensor and returns the resulting tensor.

◆ Mul() [2/2]

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

◆ Mul_() [1/2]

Tensor open3d::core::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]

Tensor open3d::core::Tensor::Mul_ ( Scalar  value)

◆ Ne() [1/2]

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

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

◆ Ne() [2/2]

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

◆ Ne_() [1/2]

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

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

◆ Ne_() [2/2]

Tensor open3d::core::Tensor::Ne_ ( Scalar  value)

◆ Neg()

Tensor open3d::core::Tensor::Neg ( ) const

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

◆ Neg_()

Tensor open3d::core::Tensor::Neg_ ( )

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

◆ NonZero()

Tensor open3d::core::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::core::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::core::Tensor::NumDims ( ) const
inline

◆ NumElements()

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

◆ Ones()

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

Create a tensor fill with ones.

◆ operator!=()

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

◆ operator&&()

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

◆ operator*() [1/2]

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

◆ operator*() [2/2]

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

◆ operator*=() [1/2]

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

◆ operator*=() [2/2]

Tensor open3d::core::Tensor::operator*= ( Scalar  value)
inline

◆ operator+() [1/2]

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

◆ operator+() [2/2]

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

◆ operator+=() [1/2]

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

◆ operator+=() [2/2]

Tensor open3d::core::Tensor::operator+= ( Scalar  value)
inline

◆ operator-() [1/3]

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

Unary minus of a tensor, returning a new tensor.

◆ operator-() [2/3]

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

◆ operator-() [3/3]

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

◆ operator-=() [1/2]

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

◆ operator-=() [2/2]

Tensor open3d::core::Tensor::operator-= ( Scalar  value)
inline

◆ operator/() [1/2]

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

◆ operator/() [2/2]

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

◆ operator/=() [1/2]

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

◆ operator/=() [2/2]

Tensor open3d::core::Tensor::operator/= ( Scalar  value)
inline

◆ operator<()

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

◆ operator<=()

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

◆ operator=() [1/5]

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

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

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

◆ operator=() [2/5]

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

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

◆ operator=() [3/5]

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

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

Tensor assignment rvalue = lvalue, e.g. tensor_a[0] = tensor_b. An actual copy of the data will be performed.

◆ operator=() [4/5]

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

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

◆ operator=() [5/5]

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

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

Tensor assignment rvalue = rvalue, e.g. tensor_a[0] = tensor_b[0]. An actual copy of the data will be performed.

◆ operator==()

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

◆ operator>()

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

◆ operator>=()

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

◆ operator[]()

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

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

◆ operator||()

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

◆ Permute()

Tensor open3d::core::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::core::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.

◆ ReinterpretCast()

Tensor open3d::core::Tensor::ReinterpretCast ( const core::Dtype dtype) const

Tensor reinterpret cast operator. It changes the tensor's dtype without changing the underlying memory blob itself. The byte-size of dtype must be same as the original dtype before casting.

◆ Reshape()

Tensor open3d::core::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:

◆ Reverse()

Tensor open3d::core::Tensor::Reverse ( ) const

Reverse a Tensor's elements by viewing the tensor as a 1D array.

◆ Round()

Tensor open3d::core::Tensor::Round ( ) const

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

◆ Save()

void open3d::core::Tensor::Save ( const std::string &  file_name) const

Save tensor to numpy's npy format.

◆ ScalarPtrToString()

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

◆ SetItem() [1/3]

Tensor open3d::core::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:

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

◆ SetItem() [2/3]

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

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

◆ SetItem() [3/3]

Tensor open3d::core::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:

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

◆ Sin()

Tensor open3d::core::Tensor::Sin ( ) const

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

◆ Sin_()

Tensor open3d::core::Tensor::Sin_ ( )

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

◆ Slice()

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

Slice Tensor.

Parameters
dimThe dimension to slice.
startThe start index (inclusive).
stopThe end index (exclusive).
stepPick one element for every step elements.

◆ Solve()

Tensor open3d::core::Tensor::Solve ( const Tensor rhs) const

Solves the linear system AX = B with LU decomposition and returns X. A must be a square matrix.

◆ Sqrt()

Tensor open3d::core::Tensor::Sqrt ( ) const

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

◆ Sqrt_()

Tensor open3d::core::Tensor::Sqrt_ ( )

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

◆ Sub() [1/2]

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

Substracts a tensor and returns the resulting tensor.

◆ Sub() [2/2]

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

◆ Sub_() [1/2]

Tensor open3d::core::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]

Tensor open3d::core::Tensor::Sub_ ( Scalar  value)

◆ Sum()

Tensor open3d::core::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.

◆ SVD()

std::tuple< Tensor, Tensor, Tensor > open3d::core::Tensor::SVD ( ) const

Computes the matrix SVD decomposition A = U S VT and returns the result. Note VT (V transpose) is returned instead of V.

◆ T()

Tensor open3d::core::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() [1/3]

Tensor open3d::core::Tensor::To ( const Device device,
bool  copy = false 
) const

Returns a tensor with the specified device.

Parameters
deviceThe targeted device to convert to.
copyIf true, a new tensor is always created; if false, the copy is avoided when the original tensor is already on the targeted device.

◆ To() [2/3]

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

Returns a tensor with the specified device and dtype.

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

◆ To() [3/3]

Tensor open3d::core::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 has the targeted dtype.

◆ ToDLPack()

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

Convert the Tensor to DLManagedTensor.

◆ ToFlatVector() [1/2]

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

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

◆ ToFlatVector() [2/2]

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

◆ ToString()

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

◆ Transpose()

Tensor open3d::core::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.

◆ Tril()

Tensor open3d::core::Tensor::Tril ( const int  diagonal = 0) const

Returns the lower triangular matrix of the 2D tensor, above the given diagonal index. [The value of diagonal = col - row, therefore 0 is the main diagonal (row = col), and it shifts towards right for positive values (for diagonal = 1, col - row = 1), and towards left for negative values. The value of the diagonal parameter must be between [-m, n] where {m, n} is the shape of input tensor.

Parameters
diagonalvalue of [col - row], below which the elements are to be taken for lower triangular matrix.

◆ Triu()

Tensor open3d::core::Tensor::Triu ( const int  diagonal = 0) const

Returns the upper triangular matrix of the 2D tensor, above the given diagonal index. [The value of diagonal = col - row, therefore 0 is the main diagonal (row = col), and it shifts towards right for positive values (for diagonal = 1, col - row = 1), and towards left for negative values. The value of the diagonal parameter must be between [-m, n] for a {m,n} shaped tensor.

Parameters
diagonalvalue of [col - row], above which the elements are to be taken for upper triangular matrix.

◆ Triul()

std::tuple< Tensor, Tensor > open3d::core::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 diagonal index. The diagonal elements of lower triangular matrix are taken to be unity. [The value of diagonal = col - row, therefore 0 is the main diagonal (row = col), and it shifts towards right for positive values (for diagonal = 1, col - row = 1), and towards left for negative values. The value of the diagonal parameter must be between [-m, n] where {m, n} is the shape of input tensor.

Parameters
diagonalvalue of [col - row], above and below which the elements are to be taken for upper (diag. included) and lower triangular matrix.

◆ Trunc()

Tensor open3d::core::Tensor::Trunc ( ) const

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

◆ View()

Tensor open3d::core::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:

◆ Zeros()

Tensor open3d::core::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::core::Tensor::blob_ = nullptr
protected

Underlying memory buffer for Tensor.

◆ data_ptr_

void* open3d::core::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::core::Tensor::dtype_ = core::Undefined
protected

Data type.

◆ shape_

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

SizeVector of the Tensor. shape_[i] is the length of dimension i.

◆ strides_

SizeVector open3d::core::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 reaching 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: