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

#include <TensorList.h>

Public Member Functions

 TensorList ()
 Useful to support operator[] in a map. More...
 
 TensorList (const SizeVector &element_shape, Dtype dtype, const Device &device=Device("CPU:0"))
 
 TensorList (const std::vector< Tensor > &tensors)
 
 TensorList (int64_t size, const SizeVector &element_shape, Dtype dtype, const Device &device=Device("CPU:0"))
 
 TensorList (const std::initializer_list< Tensor > &tensors)
 
template<class InputIterator >
 TensorList (InputIterator begin, InputIterator end)
 
 TensorList (const TensorList &other)=default
 
 TensorList (TensorList &&other)=default
 
TensorListoperator= (const TensorList &other) &=default
 
TensorListoperator= (TensorList &&other) &=default
 
void CopyFrom (const TensorList &other)
 
TensorList Clone () const
 
Tensor AsTensor () const
 Return the reference of the contained valid tensors with shared memory. More...
 
void Resize (int64_t new_size)
 
void PushBack (const Tensor &tensor)
 
void Extend (const TensorList &other)
 
TensorList operator+ (const TensorList &other) const
 Concatenate two tensorlists. More...
 
TensorListoperator+= (const TensorList &other)
 
Tensor operator[] (int64_t index) const
 
void Clear ()
 
std::string ToString () const
 
SizeVector GetElementShape () const
 
void AssertElementShape (const SizeVector &expected_element_shape) const
 
void AssertDevice (const Device &expected_device) const
 
Device GetDevice () const
 
Dtype GetDtype () const
 
int64_t GetSize () const
 
int64_t GetReservedSize () const
 
const TensorGetInternalTensor () const
 
bool IsResizable () const
 

Static Public Member Functions

static TensorList FromTensor (const Tensor &tensor, bool inplace=false)
 
static TensorList Concatenate (const TensorList &a, const TensorList &b)
 

Protected Member Functions

 TensorList (const SizeVector element_shape, int64_t size, int64_t reserved_size, const Tensor &internal_tensor, bool is_resizable)
 Fully specified constructor. More...
 
void ResizeWithExpand (int64_t new_size)
 

Static Protected Member Functions

static int64_t ComputeReserveSize (int64_t size)
 

Protected Attributes

SizeVector element_shape_
 The shape for each element tensor in the tensorlist. More...
 
int64_t size_ = 0
 
int64_t reserved_size_ = 0
 
Tensor internal_tensor_
 The internal tensor for data storage. More...
 
bool is_resizable_ = true
 

Detailed Description

A tensorlist is a list of Tensors of the same shape, similar to std::vector<Tensor>. Internally, a tensorlist stores the Tensors in one bigger internal tensor, where the begin dimension of the internal tensor is extendable.

Examples:

Constructor & Destructor Documentation

◆ TensorList() [1/9]

open3d::core::TensorList::TensorList ( )
inline

Useful to support operator[] in a map.

◆ TensorList() [2/9]

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

Constructs an empty tensorlist.

Parameters
element_shapeShape of the contained tensors, e.g. {3,}. 0-sized and scalar element_shape are allowed.
dtypeData type of the contained tensors. e.g. core::Float32.
deviceDevice of the contained tensors. e.g. Device("CPU:0").

◆ TensorList() [3/9]

open3d::core::TensorList::TensorList ( const std::vector< Tensor > &  tensors)
inline

Constructs a tensorlist from a vector of Tensors. The tensors must have the same shape, dtype and device. Values will be copied.

Parameters
tensorsA vector of tensors. The tensors must have common shape, dtype and device.

◆ TensorList() [4/9]

open3d::core::TensorList::TensorList ( int64_t  size,
const SizeVector element_shape,
Dtype  dtype,
const Device device = Device("CPU:0") 
)
inline

Constructs a tensorlist with specified size.

Parameters
sizeSize of the tensorlist.
element_shapeShape of the contained tensors, e.g. {3,}. 0-sized and scalar element_shape are allowed.
dtypeData type of the contained tensors. e.g. core::Float32.
deviceDevice of the contained tensors. e.g. Device("CPU:0").

◆ TensorList() [5/9]

open3d::core::TensorList::TensorList ( const std::initializer_list< Tensor > &  tensors)
inline

Constructs a tensorlist from a list of Tensors. The tensors must have the same shape, dtype and device. Values will be copied.

Parameters
tensorsA list of tensors. The tensors must have common shape, dtype and device.

◆ TensorList() [6/9]

template<class InputIterator >
open3d::core::TensorList::TensorList ( InputIterator  begin,
InputIterator  end 
)
inline

Constructs a tensorlist from Tensor iterator. The tensors must have the same shape, dtype and device. Values will be copied.

Parameters
beginBegin iterator.
endEnd iterator.

◆ TensorList() [7/9]

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

Copy constructor for tensorlist. The internal tensor will share the same memory as the input. Also see: the copy constructor for Tensor.

◆ TensorList() [8/9]

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

Move constructor for tensorlist. The internal tensor will share the same memory as the input. Also see: the move constructor for Tensor.

◆ TensorList() [9/9]

open3d::core::TensorList::TensorList ( const SizeVector  element_shape,
int64_t  size,
int64_t  reserved_size,
const Tensor internal_tensor,
bool  is_resizable 
)
inlineprotected

Fully specified constructor.

Member Function Documentation

◆ AssertDevice()

void open3d::core::TensorList::AssertDevice ( const Device expected_device) const
inline

◆ AssertElementShape()

void open3d::core::TensorList::AssertElementShape ( const SizeVector expected_element_shape) const
inline

◆ AsTensor()

Tensor open3d::core::TensorList::AsTensor ( ) const

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

◆ Clear()

void open3d::core::TensorList::Clear ( )

Clear the tensorlist by disgarding the internal tensor and resetting the size to 0. This operation is only valid for resizable tensorlist.

◆ Clone()

TensorList open3d::core::TensorList::Clone ( ) const

Duplicate the current tensorlist. Values will be copied. The returned tensor will always be resizable.

◆ ComputeReserveSize()

int64_t open3d::core::TensorList::ComputeReserveSize ( int64_t  size)
staticprotected

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

◆ Concatenate()

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

Concatenate two tensorlists. Return a new tensorlists with data copied. Two tensorlists must have the same element_shape, type, and device.

◆ CopyFrom()

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

Performs actual copy from another tensorlist. The internal tensor will be explicitly copied. All attributes will be copied and replaced. The returned tensor will always be resizable.

◆ Extend()

void open3d::core::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 element_shape, dtype, and device. This operation is only valid for resizable tensorlist.

◆ FromTensor()

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

Factory function to create tensorlist from a Tensor.

Parameters
tensorThe input tensor. The tensor must have at least one dimension (tensor.NumDims() >= 1). The first dimension of the tensor will be used as the "size" dimension of the tensorlist, while the remaining dimensions will be used as the element shape of the tensor list. For example, if the input tensor has shape (2, 3, 4), the resulting tensorlist will have size 2 and element shape (3, 4).
inplaceIf inplace == true, the tensorlist shares the same memory with the input tensor. The input tensor must be contiguous. The resulting tensorlist cannot be extended. If inplace == false, the tensor values will be copied when creating the tensorlist.

◆ GetDevice()

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

◆ GetDtype()

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

◆ GetElementShape()

SizeVector open3d::core::TensorList::GetElementShape ( ) const
inline

◆ GetInternalTensor()

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

◆ GetReservedSize()

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

◆ GetSize()

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

◆ IsResizable()

bool open3d::core::TensorList::IsResizable ( ) const
inline

◆ operator+()

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

Concatenate two tensorlists.

◆ operator+=()

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

Inplace concatenate with another tensorlist. This operation is only valid for resizable tensorlist.

◆ operator=() [1/2]

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

Copy assignment operator. The internal tensor will share the same memory as the input.

◆ operator=() [2/2]

TensorList& open3d::core::TensorList::operator= ( TensorList &&  other) &
default

Move assignment operator. The internal tensor will share the same memory as the input.

◆ operator[]()

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

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

◆ PushBack()

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

Push back a tensor to the tensorlist. The values will be copied. This operation is only valid for resizable tensorlist.

Parameters
tensorThe tensor to to be copied to the end of the tensorlist. The tensor must be of the same shape, dtype and device as the tensot list.

◆ Resize()

void open3d::core::TensorList::Resize ( int64_t  new_size)

Resize tensorlist. If the size increases, the increased part will be initialized with 0. If the size decreases, the reserved_size_ remain unchanged. This operation is only valid for resizable tensorlist.

◆ ResizeWithExpand()

void open3d::core::TensorList::ResizeWithExpand ( int64_t  new_size)
protected

Expand internal tensor to be larger or equal to the requested size. If the current reserved size is smaller than the requested size, the reserved size will be increased, a new internal tensor will be allocated and the original data will be copied. If the current reserved size is larger than or equal to the requested size, no operation will be performed.

Parameters
new_sizeThe requested size.

◆ ToString()

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

Field Documentation

◆ element_shape_

SizeVector open3d::core::TensorList::element_shape_
protected

The shape for each element tensor in the tensorlist.

◆ internal_tensor_

Tensor open3d::core::TensorList::internal_tensor_
protected

The internal tensor for data storage.

◆ is_resizable_

bool open3d::core::TensorList::is_resizable_ = true
protected

Whether the tensorlist is resizable. Typically, if the tensorlist is created with pre-allocated shared buffer, the tensorlist is not resizable.

◆ reserved_size_

int64_t open3d::core::TensorList::reserved_size_ = 0
protected

Maximum number of elements in tensorlist.

The internal_tensor_'s shape is (reserved_size_, *element_shape_). In general, reserved_size_ >= (1 << (ceil(log2(size_)) + 1)) as conventionally done in std::vector.

Examples: size_ = 3, reserved_size_ = 8 size_ = 4, reserved_size_ = 8 size_ = 5, reserved_size_ = 16

◆ size_

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