16#include "utils/vec_clone.hpp"
35 std::map<cytnx_uint64,std::pair<std::vector<cytnx_uint64>,
Tensor> > _elems;
36 std::map<cytnx_uint64,std::pair<std::vector<cytnx_uint64>,
Tensor> >::iterator _elems_it;
78 }
else if(type==
"mv_elem"){
82 cytnx_error_msg(type!=
"mv",
"[ERROR][LinOp] currently only type=\"mv\" (matvec) can be used.%s",
"\n");
88 cytnx_error_msg(dtype<1 || dtype >= N_Type,
"[ERROR] invalid dtype.%s",
"\n");
106 this->_elems_it = this->_elems.find(i);
107 if(this->_elems_it == this->_elems.end()){
109 Tensor x({1},this->_dtype);
111 this->_elems[i] = std::pair<std::vector<cytnx_uint64>,
Tensor>({j},x);
114 std::vector<cytnx_uint64> &vi = this->_elems_it->second.first;
115 Tensor &ie = this->_elems_it->second.second;
117 cytnx_error_msg(std::find(vi.begin(), vi.end(), j)!=vi.end(),
"[ERROR] the element is set%s",
"\n");
127 this->_elems_it = this->_elems.find(i);
128 if(this->_elems_it == this->_elems.end()){
130 Tensor x({1},this->_dtype);
132 this->_elems[i] = std::pair<std::vector<cytnx_uint64>,
Tensor>({j},x);
133 return this->_elems[i].second(0);
135 std::vector<cytnx_uint64> &vi = this->_elems_it->second.first;
136 Tensor &ie = this->_elems_it->second.second;
137 auto tmp_it = std::find(vi.begin(), vi.end(), j);
142 if(tmp_it==vi.end()){
145 return ie(vi.size()-1);
147 return ie(std::distance(vi.begin(), tmp_it));
157 cytnx_error_msg(dtype<1 || dtype >= N_Type,
"[ERROR] invalid dtype.%s",
"\n");
158 this->_dtype =
dtype;
161 return this->_device;
int device() const
Definition LinOp.hpp:160
LinOp(const std::string &type, const cytnx_uint64 &nx, const int &dtype=Type.Double, const int &device=Device.cpu)
Linear Operator class for iterative solvers.
Definition LinOp.hpp:74
int dtype() const
Definition LinOp.hpp:163
cytnx_uint64 nx() const
Definition LinOp.hpp:166
virtual Tensor matvec(const Tensor &Tin)
Definition LinOp.cpp:67
void set_elem(const cytnx_uint64 &i, const cytnx_uint64 &j, const T &elem, const bool check_exists=true)
Definition LinOp.hpp:105
void set_device(const int &device)
Definition LinOp.hpp:152
void _print()
Definition LinOp.cpp:11
void set_dtype(const int &dtype)
Definition LinOp.hpp:156
Tensor::Tproxy operator()(const cytnx_uint64 &i, const cytnx_uint64 &j)
Definition LinOp.hpp:124
an tensor (multi-dimensional array)
Definition Tensor.hpp:344
void append(const Tensor &rhs)
Definition Tensor.hpp:1363
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1122
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
Definition Accessor.hpp:12
Device_class Device
Definition Device.cpp:105
uint64_t cytnx_uint64
Definition Type.hpp:22
Type_class Type
Definition Type.cpp:143