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

#include <TensorList.h>

Public Member Functions

 TensorList (const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"), const int64_t &size=0)
 
 TensorList (const std::vector< Tensor > &tensors, const Device &device=Device("CPU:0"))
 
 TensorList (const std::initializer_list< Tensor > &tensors, const Device &device=Device("CPU:0"))
 
template<class InputIterator >
 TensorList (InputIterator first, InputIterator last, const Device &device=Device("CPU:0"))
 
 TensorList (const Tensor &internal_tensor, bool inplace=true)
 
 TensorList (const TensorList &other)
 
void CopyFrom (const TensorList &other)
 Deep copy. More...
 
TensorListoperator= (const TensorList &other) &
 
void ShallowCopyFrom (const TensorList &other)
 Shallow copy. More...
 
Tensor AsTensor () const
 Return the reference of the contained valid tensors with shared memory. More...
 
void Resize (int64_t n)
 
void PushBack (const Tensor &tensor)
 
TensorList operator+ (const TensorList &other) const
 Concatenate two TensorLists. More...
 
void Extend (const TensorList &other)
 
TensorListoperator+= (const TensorList &other)
 
Tensor operator[] (int64_t index) const
 
void Clear ()
 Clear the tensor list by discarding all data and creating a empty one. More...
 
std::string ToString () const
 
SizeVector GetShape () const
 
Device GetDevice () const
 
Dtype GetDtype () const
 
int64_t GetSize () const
 
int64_t GetReservedSize () const
 
const TensorGetInternalTensor () const
 

Static Public Member Functions

static TensorList FromTensor (const Tensor &tensor, bool inplace=false)
 Factory constructor from a raw tensor. More...
 
static TensorList Concatenate (const TensorList &a, const TensorList &b)
 

Protected Member Functions

template<class InputIterator >
void ConstructFromIterators (InputIterator first, InputIterator last)
 
void ExpandTensor (int64_t new_reserved_size)
 Expand the size of the internal tensor. More...
 
int64_t ReserveSize (int64_t n)
 

Static Protected Member Functions

static SizeVector ExpandFrontDim (const SizeVector &shape, int64_t new_dim_size=1)
 

Protected Attributes

SizeVector shape_
 
Dtype dtype_
 
Device device_
 
int64_t reserved_size_ = 0
 
int64_t size_ = 0
 
Tensor internal_tensor_
 The internal tensor for data storage. More...
 

Detailed Description

A TensorList is an extendable tensor at the 0-th dimension. It is similar to std::vector<Tensor>, but uses Open3D's tensor memory management system.

Typical use cases:

Constructor & Destructor Documentation

◆ TensorList() [1/6]

open3d::TensorList::TensorList ( const SizeVector shape,
Dtype  dtype,
const Device device = Device("CPU:0"),
const int64_t &  size = 0 
)

Constructor for creating an (empty by default) tensor list.

Parameters
shapeShape for the contained tensors. e.g. (3) for a list points, (8, 8, 8) for a list of voxel blocks.
dtypeType for the contained tensors. e.g. Dtype::Int64.
deviceDevice to store the contained tensors. e.g. "CPU:0".
sizeSize of 0-th dimension.

◆ TensorList() [2/6]

open3d::TensorList::TensorList ( const std::vector< Tensor > &  tensors,
const Device device = Device("CPU:0") 
)

Constructor from a vector with broadcastable tensors.

Parameters
tensorsA vector of tensors. The tensors must be broadcastable to a common shape, which will be set as the shape of the TensorList. The tensors must be on the same device and have the same dtype.
deviceDevice to store the contained tensors. e.g. "CPU:0".

◆ TensorList() [3/6]

open3d::TensorList::TensorList ( const std::initializer_list< Tensor > &  tensors,
const Device device = Device("CPU:0") 
)

Constructor from a list of broadcastable tensors.

Parameters
tensorsA list of tensors. The tensors must be broadcastable to a common shape, which will be set as the shape of the TensorList.
deviceDdevice to store the contained tensors. e.g. "CPU:0".

◆ TensorList() [4/6]

template<class InputIterator >
open3d::TensorList::TensorList ( InputIterator  first,
InputIterator  last,
const Device device = Device("CPU:0") 
)
inline

Constructor from iterators, an abstract wrapper for std vectors and initializer lists.

◆ TensorList() [5/6]

open3d::TensorList::TensorList ( const Tensor internal_tensor,
bool  inplace = true 
)

Constructor from a raw internal tensor. The inverse of AsTensor().

Parameters
internal_tensorraw tensor
inplace
  • If true (default), reuse the raw internal tensor. The input tensor must be contiguous.
  • If false, create a new contiguous internal tensor with precomputed reserved size.

◆ TensorList() [6/6]

open3d::TensorList::TensorList ( const TensorList other)

Copy constructor from a tensor list. Create a new tensor list with copy of data.

Member Function Documentation

◆ AsTensor()

Tensor open3d::TensorList::AsTensor ( ) const

Return the reference of the contained valid tensors with shared memory.

◆ Clear()

void open3d::TensorList::Clear ( )

Clear the tensor list by discarding all data and creating a empty one.

◆ Concatenate()

TensorList open3d::TensorList::Concatenate ( const TensorList a,
const TensorList b 
)
static

Concatenate two TensorLists. Return a new TensorList with data copied. Two TensorLists must have the same shape, type, and device.

◆ ConstructFromIterators()

template<class InputIterator >
void open3d::TensorList::ConstructFromIterators ( InputIterator  first,
InputIterator  last 
)
inlineprotected

◆ CopyFrom()

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

Deep copy.

◆ ExpandFrontDim()

SizeVector open3d::TensorList::ExpandFrontDim ( const SizeVector shape,
int64_t  new_dim_size = 1 
)
staticprotected

Expand the shape in the first indexing dimension. e.g. (8, 8, 8) -> (1, 8, 8, 8)

◆ ExpandTensor()

void open3d::TensorList::ExpandTensor ( int64_t  new_reserved_size)
protected

Expand the size of the internal tensor.

◆ Extend()

void open3d::TensorList::Extend ( const TensorList other)

Extend the current TensorList with another TensorList appended to the end. The data is copied. The two TensorLists must have the same shape, dtype, and device.

◆ FromTensor()

TensorList open3d::TensorList::FromTensor ( const Tensor tensor,
bool  inplace = false 
)
static

Factory constructor from a raw tensor.

◆ GetDevice()

Device open3d::TensorList::GetDevice ( ) const
inline

◆ GetDtype()

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

◆ GetInternalTensor()

const Tensor& open3d::TensorList::GetInternalTensor ( ) const
inline

◆ GetReservedSize()

int64_t open3d::TensorList::GetReservedSize ( ) const
inline

◆ GetShape()

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

◆ GetSize()

int64_t open3d::TensorList::GetSize ( ) const
inline

◆ operator+()

TensorList open3d::TensorList::operator+ ( const TensorList other) const
inline

Concatenate two TensorLists.

◆ operator+=()

TensorList& open3d::TensorList::operator+= ( const TensorList other)
inline

◆ operator=()

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

TensorList assignment lvalue = lvalue, e.g. tensorlist_a = tensorlist_b, resulting in a shallow copy. We don't redirect Slice operation to tensors, so right value assignment is not explicitly supported.

◆ operator[]()

Tensor open3d::TensorList::operator[] ( int64_t  index) const

Extract the i-th Tensor along the first axis, returning a new view. For advanced indexing like Slice, use tensorlist.AsTensor().Slice().

◆ PushBack()

void open3d::TensorList::PushBack ( const Tensor tensor)

Push back the copy of a tensor to the list. The tensor must broadcastable to the TensorList's shape. The tensor must be on the same device and have the same dtype.

◆ ReserveSize()

int64_t open3d::TensorList::ReserveSize ( int64_t  n)
protected

Compute the reserved size for the desired number of tensors with reserved_size_ = (1 << (ceil(log2(size_)) + 1)).

◆ Resize()

void open3d::TensorList::Resize ( int64_t  n)

Resize an existing tensor list. If the size increases, the increased part will be assigned 0. If the size decreases, the decreased part's value will be undefined.

◆ ShallowCopyFrom()

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

Shallow copy.

◆ ToString()

std::string open3d::TensorList::ToString ( ) const

Field Documentation

◆ device_

Device open3d::TensorList::device_
protected

◆ dtype_

Dtype open3d::TensorList::dtype_
protected

◆ internal_tensor_

Tensor open3d::TensorList::internal_tensor_
protected

The internal tensor for data storage.

◆ reserved_size_

int64_t open3d::TensorList::reserved_size_ = 0
protected

Maximum number of elements in TensorList. The internal_tensor_'s shape is (reserved_size_, *shape_). In general, reserved_size_ >= (1 << (ceil(log2(size_)) + 1)) as conventionally done in std::vector. Examples: (size_, reserved_size_) = (3, 8), (4, 8), (5, 16).

◆ shape_

SizeVector open3d::TensorList::shape_
protected

The shape_ represents the shape for each element in the TensorList. The internal_tensor_'s shape is (reserved_size_, *shape_).

◆ size_

int64_t open3d::TensorList::size_ = 0
protected

Number of active (valid) elements in TensorList. The internal_tensor_ has shape (reserved_size_, *shape_), but only the front (size_, *shape_) is active.


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