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());
69 explicit Accessor(
const std::vector<T> &list) {
70 this->_type = this->list;
71 this->idx_list = std::vector<cytnx_int64>(list.begin(), list.end());
77 explicit Accessor(
const std::string &str);
80 Accessor(
const cytnx_int64 &min,
const cytnx_int64 &max,
const cytnx_int64 &
step);
91 int type()
const {
return this->_type; }
128 const cytnx_int64 &
step = 1) {
135 out._type = Accessor::Tilend;
144 out._type = Accessor::Step;
154 out._type = Accessor::Qns;
164 void get_len_pos(
const cytnx_uint64 &dim, cytnx_uint64 &len,
165 std::vector<cytnx_uint64> &pos)
const;
171 std::ostream &operator<<(std::ostream &os,
const Accessor &in);
175 void _resolve_elems(std::vector<cytnx::Accessor> &cool,
const T &a) {
179 template <
class T,
class... Ts>
180 void _resolve_elems(std::vector<cytnx::Accessor> &cool,
const T &a,
const Ts &...args) {
182 _resolve_elems(cool, args...);
185 template <
class T,
class... Ts>
186 std::vector<cytnx::Accessor> Indices_resolver(
const T &a,
const Ts &...args) {
187 std::vector<cytnx::Accessor> idxs;
188 _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:132
static Accessor step(const cytnx_int64 &step)
Definition Accessor.hpp:141
static Accessor all()
access the whole rank, this is similar to [:] in python
Definition Accessor.hpp:107
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:127
static Accessor qns(const std::vector< std::vector< cytnx_int64 > > &qns)
Definition Accessor.hpp:150
int type() const
Definition Accessor.hpp:91
Accessor(const cytnx_int64 &loc)
access the specific index at the assigned rank in Tensor.
Accessor(const std::vector< T > &list)
Definition Accessor.hpp:69
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:115
Definition Accessor.hpp:12
Tensor operator==(const Tensor &Lt, const Tensor &Rt)
The comparison operator for Tensor.