Open3D (C++ API)
0.18.0+3975044
|
#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 | |
TensorList & | operator= (const TensorList &other) &=default |
TensorList & | operator= (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... | |
TensorList & | operator+= (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 Tensor & | GetInternalTensor () 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 |
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:
|
inline |
Useful to support operator[] in a map.
|
inline |
Constructs an empty tensorlist.
element_shape | Shape of the contained tensors, e.g. {3,}. 0-sized and scalar element_shape are allowed. |
dtype | Data type of the contained tensors. e.g. core::Float32. |
device | Device of the contained tensors. e.g. Device("CPU:0"). |
|
inline |
Constructs a tensorlist from a vector of Tensors. The tensors must have the same shape, dtype and device. Values will be copied.
tensors | A vector of tensors. The tensors must have common shape, dtype and device. |
|
inline |
Constructs a tensorlist with specified size.
size | Size of the tensorlist. |
element_shape | Shape of the contained tensors, e.g. {3,}. 0-sized and scalar element_shape are allowed. |
dtype | Data type of the contained tensors. e.g. core::Float32. |
device | Device of the contained tensors. e.g. Device("CPU:0"). |
|
inline |
Constructs a tensorlist from a list of Tensors. The tensors must have the same shape, dtype and device. Values will be copied.
tensors | A list of tensors. The tensors must have common shape, dtype and device. |
|
inline |
Constructs a tensorlist from Tensor iterator. The tensors must have the same shape, dtype and device. Values will be copied.
begin | Begin iterator. |
end | End iterator. |
|
default |
Copy constructor for tensorlist. The internal tensor will share the same memory as the input. Also see: the copy constructor for Tensor.
|
default |
Move constructor for tensorlist. The internal tensor will share the same memory as the input. Also see: the move constructor for Tensor.
|
inlineprotected |
Fully specified constructor.
|
inline |
|
inline |
Tensor open3d::core::TensorList::AsTensor | ( | ) | const |
Return the reference of the contained valid tensors with shared memory.
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.
TensorList open3d::core::TensorList::Clone | ( | ) | const |
Duplicate the current tensorlist. Values will be copied. The returned tensor will always be resizable.
|
staticprotected |
Compute the reserved size for the desired number of tensors with reserved_size_ = (1 << (ceil(log2(size_)) + 1)).
|
static |
Concatenate two tensorlists. Return a new tensorlists with data copied. Two tensorlists must have the same element_shape, type, and device.
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.
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.
|
static |
Factory function to create tensorlist from a Tensor.
tensor | The 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). |
inplace | If 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. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Concatenate two tensorlists.
|
inline |
Inplace concatenate with another tensorlist. This operation is only valid for resizable tensorlist.
|
default |
Copy assignment operator. The internal tensor will share the same memory as the input.
|
default |
Move assignment operator. The internal tensor will share the same memory as the input.
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().
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.
tensor | The 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. |
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.
|
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.
new_size | The requested size. |
std::string open3d::core::TensorList::ToString | ( | ) | const |
|
protected |
The shape for each element tensor in the tensorlist.
|
protected |
The internal tensor for data storage.
|
protected |
Whether the tensorlist is resizable. Typically, if the tensorlist is created with pre-allocated shared buffer, the tensorlist is not resizable.
|
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
|
protected |
Number of active (valid) elements in tensorlist. The internal_tensor_ has shape (reserved_size_, *shape_), but only the front (size_, *shape_) is active.