1#ifndef CYTNX_ACCESSOR_H_
2#define CYTNX_ACCESSOR_H_
10#include <initializer_list>
23 cytnx_int64 _min{}, _max{}, _step{};
25 std::vector<cytnx_int64> idx_list;
27 std::vector<std::vector<cytnx_int64>> qns_list;
35 enum : cytnx_int64 { none, Singl, All, Range, Tilend, Step, Tn, list, Qns };
37 Accessor() : _type(Accessor::none){};
62 explicit Accessor(
const std::initializer_list<T> &list) {
63 std::vector<T> tmp = list;
64 this->_type = this->list;
65 this->idx_list = std::vector<cytnx_int64>(tmp.begin(), tmp.end());
70 explicit Accessor(
const std::vector<T> &list) {
71 this->_type = this->list;
72 this->idx_list = std::vector<cytnx_int64>(list.begin(), list.end());
78 explicit Accessor(
const std::string &str);
81 Accessor(
const cytnx_int64 &min,
const cytnx_int64 &max,
const cytnx_int64 &
step);
89 int type()
const {
return this->_type; }
125 const cytnx_int64 &
step = 1) {
132 out._type = Accessor::Tilend;
141 out._type = Accessor::Step;
151 out._type = Accessor::Qns;
161 void get_len_pos(
const cytnx_uint64 &dim, cytnx_uint64 &len,
162 std::vector<cytnx_uint64> &pos)
const;
168 std::ostream &operator<<(std::ostream &os,
const Accessor &in);
172 void _resolve_elems(std::vector<cytnx::Accessor> &cool,
const T &a) {
176 template <
class T,
class... Ts>
177 void _resolve_elems(std::vector<cytnx::Accessor> &cool,
const T &a,
const Ts &...args) {
179 _resolve_elems(cool, args...);
182 template <
class T,
class... Ts>
183 std::vector<cytnx::Accessor> Indices_resolver(
const T &a,
const Ts &...args) {
185 std::vector<cytnx::Accessor> idxs;
186 _resolve_elems(idxs, a, args...);
object that mimic the python slice to access elements in C++ [this is for c++ API only].
Definition Accessor.hpp:17
static Accessor tilend(const cytnx_int64 &min, const cytnx_int64 &step=1)
Definition Accessor.hpp:129
static Accessor step(const cytnx_int64 &step)
Definition Accessor.hpp:138
static Accessor all()
access the whole rank, this is similar to [:] in python
Definition Accessor.hpp:105
Accessor(const std::initializer_list< T > &list)
Definition Accessor.hpp:62
static Accessor range(const cytnx_int64 &min, const cytnx_int64 &max, const cytnx_int64 &step=1)
access the range at assigned rank, this is similar to min:max:step in python
Definition Accessor.hpp:124
static Accessor qns(const std::vector< std::vector< cytnx_int64 > > &qns)
Definition Accessor.hpp:147
int type() const
Definition Accessor.hpp:89
Accessor(const cytnx_int64 &loc)
access the specific index at the assigned rank in Tensor.
Accessor(const std::vector< T > &list)
Definition Accessor.hpp:70
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
Definition Accessor.hpp:12