ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::core::TensorKey Class Reference

TensorKey is used to represent single index, slice or advanced indexing on a Tensor. More...

#include <TensorKey.h>

Classes

class  Impl
 
class  IndexImpl
 
class  IndexTensorImpl
 
class  SliceImpl
 

Public Types

enum class  TensorKeyMode { Index , Slice , IndexTensor }
 

Public Member Functions

 ~TensorKey ()
 
TensorKeyMode GetMode () const
 Returns TensorKey mode. More...
 
std::string ToString () const
 Convert TensorKey to a string representation. More...
 
int64_t GetIndex () const
 
int64_t GetStart () const
 
int64_t GetStop () const
 
int64_t GetStep () const
 
TensorKey InstantiateDimSize (int64_t dim_size) const
 
Tensor GetIndexTensor () const
 

Static Public Member Functions

static TensorKey Index (int64_t index)
 
static TensorKey Slice (utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
 
static TensorKey IndexTensor (const Tensor &index_tensor)
 

Detailed Description

TensorKey is used to represent single index, slice or advanced indexing on a Tensor.

See https://numpy.org/doc/stable/reference/arrays.indexing.html for details.

Definition at line 26 of file TensorKey.h.

Member Enumeration Documentation

◆ TensorKeyMode

Enumerator
Index 
Slice 
IndexTensor 

Definition at line 67 of file TensorKey.h.

Constructor & Destructor Documentation

◆ ~TensorKey()

cloudViewer::core::TensorKey::~TensorKey ( )
inline

Definition at line 68 of file TensorKey.h.

Member Function Documentation

◆ GetIndex()

int64_t cloudViewer::core::TensorKey::GetIndex ( ) const

Get (single) index. For TensorKeyMode::Index only.

Definition at line 148 of file TensorKey.cpp.

References LogError.

Referenced by cloudViewer::core::Tensor::GetItem(), and cloudViewer::core::Tensor::SetItem().

◆ GetIndexTensor()

Tensor cloudViewer::core::TensorKey::GetIndexTensor ( ) const

Get advanced indexing tensor. For TensorKeyMode::IndexTensor only.

Definition at line 186 of file TensorKey.cpp.

References LogError.

Referenced by cloudViewer::core::Tensor::GetItem(), and cloudViewer::core::Tensor::SetItem().

◆ GetMode()

TensorKey::TensorKeyMode cloudViewer::core::TensorKey::GetMode ( ) const

Returns TensorKey mode.

Definition at line 130 of file TensorKey.cpp.

Referenced by cloudViewer::core::Tensor::GetItem(), and cloudViewer::core::Tensor::SetItem().

◆ GetStart()

int64_t cloudViewer::core::TensorKey::GetStart ( ) const

Get start index. Throws exception if start is None. For TensorKeyMode::Slice only.

Definition at line 156 of file TensorKey.cpp.

References LogError.

Referenced by cloudViewer::core::Tensor::GetItem().

◆ GetStep()

int64_t cloudViewer::core::TensorKey::GetStep ( ) const

Get step index. Throws exception if step is None. For TensorKeyMode::Slice only.

Definition at line 170 of file TensorKey.cpp.

References LogError.

Referenced by cloudViewer::core::Tensor::GetItem().

◆ GetStop()

int64_t cloudViewer::core::TensorKey::GetStop ( ) const

Get stop index. Throws exception if stop is None. For TensorKeyMode::Slice only.

Definition at line 163 of file TensorKey.cpp.

References LogError.

Referenced by cloudViewer::core::Tensor::GetItem().

◆ Index()

TensorKey cloudViewer::core::TensorKey::Index ( int64_t  index)
static

◆ IndexTensor()

TensorKey cloudViewer::core::TensorKey::IndexTensor ( const Tensor index_tensor)
static

Instantiates a TensorKey with tensor-index (advanced indexing) mode.

[[1, 2], [3:]]: advanced indexing on dim-0, slicing on dim-1.
t.GetItem({
TensorKey::IndexTensor(Tensor::Init<int64_t>({1, 2}, device),
});
static TensorKey IndexTensor(const Tensor &index_tensor)
Definition: TensorKey.cpp:144
static TensorKey Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Definition: TensorKey.cpp:138
constexpr utility::nullopt_t None
Definition: TensorKey.h:20
Parameters
index_tensorIndexing tensor of dtype int64_t or bool.

Definition at line 144 of file TensorKey.cpp.

Referenced by cloudViewer::core::Tensor::Clip_(), cloudViewer::t::geometry::PointCloud::SelectByIndex(), and cloudViewer::core::ToTensorKey().

◆ InstantiateDimSize()

TensorKey cloudViewer::core::TensorKey::InstantiateDimSize ( int64_t  dim_size) const

When dim_size is know, convert the None values in start, stop, step with to concrete values and returns a new TensorKey.

E.g. if t.shape == (5,), t[:4]:
before compute: Slice(None, 4, None)
after compute : Slice( 0, 4, 1)
E.g. if t.shape == (5,), t[1:]:
before compute: Slice( 1, None, None)
after compute : Slice( 1, 5, 1)

For TensorKeyMode::Slice only.

Definition at line 177 of file TensorKey.cpp.

References LogError.

Referenced by cloudViewer::core::Tensor::GetItem().

◆ Slice()

◆ ToString()

std::string cloudViewer::core::TensorKey::ToString ( ) const

Convert TensorKey to a string representation.

Definition at line 132 of file TensorKey.cpp.


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