Open3D (C++ API)
|
#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... | |
TensorList & | operator= (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) |
TensorList & | operator+= (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 Tensor & | GetInternalTensor () 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... | |
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:
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.
shape | Shape for the contained tensors. e.g. (3) for a list points, (8, 8, 8) for a list of voxel blocks. |
dtype | Type for the contained tensors. e.g. Dtype::Int64. |
device | Device to store the contained tensors. e.g. "CPU:0". |
size | Size of 0-th dimension. |
open3d::TensorList::TensorList | ( | const std::vector< Tensor > & | tensors, |
const Device & | device = Device("CPU:0") |
||
) |
Constructor from a vector with broadcastable tensors.
tensors | A 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. |
device | Device to store the contained tensors. e.g. "CPU:0". |
open3d::TensorList::TensorList | ( | const std::initializer_list< Tensor > & | tensors, |
const Device & | device = Device("CPU:0") |
||
) |
Constructor from a list of broadcastable tensors.
tensors | A list of tensors. The tensors must be broadcastable to a common shape, which will be set as the shape of the TensorList. |
device | Ddevice to store the contained tensors. e.g. "CPU:0". |
|
inline |
Constructor from iterators, an abstract wrapper for std vectors and initializer lists.
open3d::TensorList::TensorList | ( | const Tensor & | internal_tensor, |
bool | inplace = true |
||
) |
Constructor from a raw internal tensor. The inverse of AsTensor().
internal_tensor | raw tensor |
inplace |
|
open3d::TensorList::TensorList | ( | const TensorList & | other | ) |
Copy constructor from a tensor list. Create a new tensor list with copy of data.
Tensor open3d::TensorList::AsTensor | ( | ) | const |
Return the reference of the contained valid tensors with shared memory.
void open3d::TensorList::Clear | ( | ) |
Clear the tensor list by discarding all data and creating a empty one.
|
static |
Concatenate two TensorLists. Return a new TensorList with data copied. Two TensorLists must have the same shape, type, and device.
|
inlineprotected |
void open3d::TensorList::CopyFrom | ( | const TensorList & | other | ) |
Deep copy.
|
staticprotected |
Expand the shape in the first indexing dimension. e.g. (8, 8, 8) -> (1, 8, 8, 8)
|
protected |
Expand the size of the internal tensor.
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.
|
static |
Factory constructor from a raw tensor.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Concatenate two TensorLists.
|
inline |
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.
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().
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.
|
protected |
Compute the reserved size for the desired number of tensors with reserved_size_ = (1 << (ceil(log2(size_)) + 1)).
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.
void open3d::TensorList::ShallowCopyFrom | ( | const TensorList & | other | ) |
Shallow copy.
std::string open3d::TensorList::ToString | ( | ) | const |
|
protected |
|
protected |
|
protected |
The internal tensor for data storage.
|
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).
|
protected |
The shape_ represents the shape for each element in the TensorList. The internal_tensor_'s shape is (reserved_size_, *shape_).
|
protected |
Number of active (valid) elements in TensorList. The internal_tensor_ has shape (reserved_size_, *shape_), but only the front (size_, *shape_) is active.