Open3D (C++ API)  0.18.0+252c867
Data Structures | Public Types | Public Member Functions | Static Public Member Functions
open3d::core::TensorKey Class Reference

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

#include <TensorKey.h>

Data Structures

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.

Member Enumeration Documentation

◆ TensorKeyMode

Enumerator
Index 
Slice 
IndexTensor 

Constructor & Destructor Documentation

◆ ~TensorKey()

open3d::core::TensorKey::~TensorKey ( )
inline

Member Function Documentation

◆ GetIndex()

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

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

◆ GetIndexTensor()

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

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

◆ GetMode()

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

Returns TensorKey mode.

◆ GetStart()

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

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

◆ GetStep()

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

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

◆ GetStop()

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

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

◆ Index()

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

Instantiates a TensorKey with single index mode.

t[0] : t.GetItem({TensorKey::Index(0)})
t[2] : t.GetItem({TensorKey::Index(2)})
t[2, 3]: t.GetItem({TensorKey::Index(2), TensorKey::Index(3)})
static TensorKey Index(int64_t index)
Definition: TensorKey.cpp:133
Parameters
indexIndex to the tensor.

◆ IndexTensor()

TensorKey open3d::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 Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Definition: TensorKey.cpp:137
static TensorKey IndexTensor(const Tensor &index_tensor)
Definition: TensorKey.cpp:143
constexpr utility::nullopt_t None
Definition: TensorKey.h:20
Parameters
index_tensorIndexing tensor of dtype int64_t or bool.

◆ InstantiateDimSize()

TensorKey open3d::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.

◆ Slice()

TensorKey open3d::core::TensorKey::Slice ( utility::optional< int64_t >  start,
utility::optional< int64_t >  stop,
utility::optional< int64_t >  step 
)
static

Instantiates a TensorKey with slice mode.

t[0:10:2]: t.GetItem({TensorKey::Slice(0 , 10 , 2 )})
t[:-1] : t.Getitem({TensorKey::Slice(None , None, -1 )})
t[3:] : t.GetItem({TensorKey::Slice(3 , None, None)})
Parameters
startStart index. None means starting from the 0-th element.
stopStop index. None means stopping at the last element.
stepStep size. None means step size 1.

◆ ToString()

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

Convert TensorKey to a string representation.


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