38 ss <<
"TensorKey::Index(" << index_ <<
")";
56 return std::make_shared<SliceImpl>(
63 return start_.
value();
84 ss <<
"TensorKey::Slice(";
116 index_tensor_(index_tensor) {}
119 std::stringstream ss;
120 ss <<
"TensorKey::IndexTensor(" << index_tensor_.
ToString() <<
")";
128 TensorKey::TensorKey(
const std::shared_ptr<Impl>& impl) : impl_(impl) {}
135 return TensorKey(std::make_shared<IndexImpl>(index));
141 return TensorKey(std::make_shared<SliceImpl>(start, stop, step));
145 return TensorKey(std::make_shared<IndexTensorImpl>(index_tensor));
149 if (
auto index_impl = std::dynamic_pointer_cast<IndexImpl>(impl_)) {
150 return index_impl->GetIndex();
157 if (
auto slice_impl = std::dynamic_pointer_cast<SliceImpl>(impl_)) {
158 return slice_impl->GetStart();
164 if (
auto slice_impl = std::dynamic_pointer_cast<SliceImpl>(impl_)) {
165 return slice_impl->GetStop();
171 if (
auto slice_impl = std::dynamic_pointer_cast<SliceImpl>(impl_)) {
172 return slice_impl->GetStep();
178 if (
auto slice_impl = std::dynamic_pointer_cast<SliceImpl>(impl_)) {
179 return TensorKey(slice_impl->InstantiateDimSize(dim_size));
182 "InstantiateDimSize() failed: the impl is not SliceImpl.");
187 if (
auto index_tensor_impl =
188 std::dynamic_pointer_cast<IndexTensorImpl>(impl_)) {
189 return index_tensor_impl->GetIndexTensor();
192 "GetIndexTensor() failed: the impl is not IndexTensorImpl.");
virtual std::string ToString() const =0
TensorKeyMode GetMode() const
std::string ToString() const override
IndexTensorImpl(const Tensor &index_tensor)
Tensor GetIndexTensor() const
std::string ToString() const override
std::shared_ptr< SliceImpl > InstantiateDimSize(int64_t dim_size) const
SliceImpl(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
std::string ToString() const override
TensorKey is used to represent single index, slice or advanced indexing on a Tensor.
std::string ToString() const
Convert TensorKey to a string representation.
TensorKeyMode GetMode() const
Returns TensorKey mode.
TensorKey InstantiateDimSize(int64_t dim_size) const
static TensorKey IndexTensor(const Tensor &index_tensor)
Tensor GetIndexTensor() const
static TensorKey Index(int64_t index)
static TensorKey Slice(utility::optional< int64_t > start, utility::optional< int64_t > stop, utility::optional< int64_t > step)
std::string ToString(bool with_suffix=true, const std::string &indent="") const
constexpr bool has_value() const noexcept
constexpr T const & value() const &
constexpr nullopt_t nullopt
Generic file read and write utility for python interface.