ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
TensorKey.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Logging.h>
11 #include <Optional.h>
12 
13 namespace cloudViewer {
14 namespace core {
15 
16 // Avoids circular include.
17 class Tensor;
18 
19 // Same as utility::nullopt. Provides a similar Python slicing API.
21 
26 class TensorKey {
27 public:
37  static TensorKey Index(int64_t index);
38 
53 
65  static TensorKey IndexTensor(const Tensor& index_tensor);
66 
69 
71  TensorKeyMode GetMode() const;
72 
74  std::string ToString() const;
75 
76 public:
79  int64_t GetIndex() const;
80 
83  int64_t GetStart() const;
84 
87  int64_t GetStop() const;
88 
91  int64_t GetStep() const;
92 
104  TensorKey InstantiateDimSize(int64_t dim_size) const;
105 
108  Tensor GetIndexTensor() const;
109 
110 private:
111  class Impl;
112  class IndexImpl;
113  class SliceImpl;
114  class IndexTensorImpl;
115  std::shared_ptr<Impl> impl_;
116  TensorKey(const std::shared_ptr<Impl>& impl);
117 };
118 
119 } // namespace core
120 } // namespace cloudViewer
cloudViewer::core::TensorKey::InstantiateDimSize
TensorKey InstantiateDimSize(int64_t dim_size) const
Definition: TensorKey.cpp:177
cloudViewer::utility::optional::value
constexpr T const & value() const &
Definition: Optional.h:465
cloudViewer::utility::nullopt_t::init
Definition: Optional.h:133
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
cloudViewer::core::TensorKey::IndexTensorImpl::ToString
std::string ToString() const override
Definition: TensorKey.cpp:118
cloudViewer::core::TensorKey::SliceImpl::ToString
std::string ToString() const override
Definition: TensorKey.cpp:82
Optional.h
cloudViewer::core::TensorKey::SliceImpl::InstantiateDimSize
std::shared_ptr< SliceImpl > InstantiateDimSize(int64_t dim_size) const
Definition: TensorKey.cpp:55
cloudViewer::core::TensorKey::GetIndexTensor
Tensor GetIndexTensor() const
Definition: TensorKey.cpp:186
cloudViewer::utility::optional::has_value
constexpr bool has_value() const noexcept
Definition: Optional.h:440
cloudViewer::core::TensorKey::IndexTensor
static TensorKey IndexTensor(const Tensor &index_tensor)
Definition: TensorKey.cpp:144
cloudViewer::core::TensorKey::IndexImpl
Definition: TensorKey.cpp:31
cloudViewer::core::TensorKey::TensorKeyMode
TensorKeyMode
Definition: TensorKey.h:67
cloudViewer::core::TensorKey::IndexImpl::IndexImpl
IndexImpl(int64_t index)
Definition: TensorKey.cpp:33
cloudViewer::core::TensorKey::GetStart
int64_t GetStart() const
Definition: TensorKey.cpp:156
cloudViewer::core::TensorKey::SliceImpl
Definition: TensorKey.cpp:46
cloudViewer::core::TensorKey::GetStop
int64_t GetStop() const
Definition: TensorKey.cpp:163
cloudViewer::core::TensorKey::SliceImpl::GetStep
int64_t GetStep() const
Definition: TensorKey.cpp:75
cloudViewer::core::Tensor
Definition: Tensor.h:32
cloudViewer::core::TensorKey::IndexTensorImpl::IndexTensorImpl
IndexTensorImpl(const Tensor &index_tensor)
Definition: TensorKey.cpp:114
cloudViewer::core::TensorKey::SliceImpl::GetStart
int64_t GetStart() const
Definition: TensorKey.cpp:61
cloudViewer::core::TensorKey::TensorKeyMode::IndexTensor
@ IndexTensor
cloudViewer::core::None
constexpr utility::nullopt_t None
Definition: TensorKey.h:20
cloudViewer::core::TensorKey::ToString
std::string ToString() const
Convert TensorKey to a string representation.
Definition: TensorKey.cpp:132
cloudViewer::core::TensorKey::Impl::Impl
Impl(TensorKeyMode mode)
Definition: TensorKey.cpp:22
cloudViewer::core::TensorKey::Index
static TensorKey Index(int64_t index)
Definition: TensorKey.cpp:134
cloudViewer::core::TensorKey::Impl::ToString
virtual std::string ToString() const =0
cloudViewer::core::TensorKey::TensorKeyMode::Index
@ Index
cloudViewer::core::TensorKey::Impl::GetMode
TensorKeyMode GetMode() const
Definition: TensorKey.cpp:23
cloudViewer::core::TensorKey::IndexImpl::ToString
std::string ToString() const override
Definition: TensorKey.cpp:36
core
cloudViewer::core::TensorKey::IndexImpl::GetIndex
int64_t GetIndex() const
Definition: TensorKey.cpp:35
cloudViewer::core::TensorKey::GetStep
int64_t GetStep() const
Definition: TensorKey.cpp:170
cloudViewer::core::TensorKey::GetIndex
int64_t GetIndex() const
Definition: TensorKey.cpp:148
cloudViewer::utility::nullopt_t
Definition: Optional.h:132
cloudViewer::core::TensorKey::Impl::~Impl
virtual ~Impl()
Definition: TensorKey.cpp:24
cloudViewer::utility::optional< int64_t >
LogError
#define LogError(...)
Definition: Logging.h:60
cloudViewer::core::TensorKey::TensorKeyMode::Slice
@ Slice
cloudViewer::core::TensorKey::Slice
static TensorKey Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Definition: TensorKey.cpp:138
cloudViewer::core::TensorKey::SliceImpl::GetStop
int64_t GetStop() const
Definition: TensorKey.cpp:68
cloudViewer::core::TensorKey
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
Definition: TensorKey.h:26
cloudViewer::core::TensorKey::IndexTensorImpl
Definition: TensorKey.cpp:112
cloudViewer::core::Tensor::ToString
std::string ToString(bool with_suffix=true, const std::string &indent="") const
Definition: Tensor.cpp:780
cloudViewer::core::TensorKey::GetMode
TensorKeyMode GetMode() const
Returns TensorKey mode.
Definition: TensorKey.cpp:130
cloudViewer::utility::nullopt
constexpr nullopt_t nullopt
Definition: Optional.h:136
Tensor.h
cloudViewer::core::TensorKey::~TensorKey
~TensorKey()
Definition: TensorKey.h:68
cloudViewer::core::TensorKey::IndexTensorImpl::GetIndexTensor
Tensor GetIndexTensor() const
Definition: TensorKey.cpp:117
cloudViewer::core::TensorKey::Impl
Definition: TensorKey.cpp:20
TensorKey.h
cloudViewer::core::TensorKey::SliceImpl::SliceImpl
SliceImpl(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Definition: TensorKey.cpp:48