Open3D (C++ API)  0.16.1
TensorKey.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
31
32namespace open3d {
33namespace core {
34
35// Avoids circular include.
36class Tensor;
37
38// Same as utility::nullopt. Provides a similar Python slicing API.
40
45class TensorKey {
46public:
56 static TensorKey Index(int64_t index);
57
72
84 static TensorKey IndexTensor(const Tensor& index_tensor);
85
88
90 TensorKeyMode GetMode() const;
91
93 std::string ToString() const;
94
95public:
98 int64_t GetIndex() const;
99
102 int64_t GetStart() const;
103
106 int64_t GetStop() const;
107
110 int64_t GetStep() const;
111
123 TensorKey InstantiateDimSize(int64_t dim_size) const;
124
127 Tensor GetIndexTensor() const;
128
129private:
130 class Impl;
131 class IndexImpl;
132 class SliceImpl;
133 class IndexTensorImpl;
134 std::shared_ptr<Impl> impl_;
135 TensorKey(const std::shared_ptr<Impl>& impl);
136};
137
138} // namespace core
139} // namespace open3d
Definition: Tensor.h:51
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
Definition: TensorKey.h:45
int64_t GetStart() const
Definition: TensorKey.cpp:174
std::string ToString() const
Convert TensorKey to a string representation.
Definition: TensorKey.cpp:150
static TensorKey Index(int64_t index)
Definition: TensorKey.cpp:152
int64_t GetIndex() const
Definition: TensorKey.cpp:166
Tensor GetIndexTensor() const
Definition: TensorKey.cpp:204
int64_t GetStop() const
Definition: TensorKey.cpp:181
static TensorKey Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
Definition: TensorKey.cpp:156
TensorKeyMode
Definition: TensorKey.h:86
TensorKeyMode GetMode() const
Returns TensorKey mode.
Definition: TensorKey.cpp:148
static TensorKey IndexTensor(const Tensor &index_tensor)
Definition: TensorKey.cpp:162
~TensorKey()
Definition: TensorKey.h:87
TensorKey InstantiateDimSize(int64_t dim_size) const
Definition: TensorKey.cpp:195
int64_t GetStep() const
Definition: TensorKey.cpp:188
constexpr utility::nullopt_t None
Definition: TensorKey.h:39
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Optional.h:168
Definition: Optional.h:167