15#include "utils/vec_clone.hpp"
36 std::map<cytnx_uint64,std::pair<std::vector<cytnx_uint64>,
Tensor> > _elems;
37 std::map<cytnx_uint64,std::pair<std::vector<cytnx_uint64>,
Tensor> >::iterator _elems_it;
80 this->_mvfunc=custom_f;
82 }
else if(type==
"mv_elem"){
83 cytnx_error_msg(custom_f !=
nullptr,
"[ERROR][LinOp] with type=mv_elem cannot accept any function. use set_elem/set_elemts instead.%s",
"\n");
87 cytnx_error_msg(type!=
"mv",
"[ERROR][LinOp] currently only type=\"mv\" (matvec) can be used.%s",
"\n");
97 if(this->_type==
"mv"){
102 this->_dtype =
dtype;
104 cytnx_error_msg(
true,
"[ERROR] cannot specify func with type=mv_elem%s. use set_elem instead.",
"\n");
110 this->_elems_it = this->_elems.find(
i);
111 if(this->_elems_it == this->_elems.end()){
113 Tensor x({1},this->_dtype);
115 this->_elems[
i] = std::pair<std::vector<cytnx_uint64>,
Tensor>({
j},x);
118 std::vector<cytnx_uint64> &
vi = this->_elems_it->second.first;
119 Tensor &
ie = this->_elems_it->second.second;
131 this->_elems_it = this->_elems.find(
i);
132 if(this->_elems_it == this->_elems.end()){
134 Tensor x({1},this->_dtype);
136 this->_elems[
i] = std::pair<std::vector<cytnx_uint64>,
Tensor>({
j},x);
137 return this->_elems[
i].second(0);
139 std::vector<cytnx_uint64> &
vi = this->_elems_it->second.first;
140 Tensor &
ie = this->_elems_it->second.second;
149 return ie(
vi.size()-1);
162 this->_dtype =
dtype;
165 return this->_device;
LinOp(const std::string &type, const cytnx_uint64 &nx, const int &dtype=Type.Double, const int &device=Device.cpu, std::function< Tensor(const Tensor &)> custom_f=nullptr)
Linear Operator class for iterative solvers.
Definition LinOp.hpp:77
virtual Tensor matvec(const Tensor &Tin)
Definition LinOp.cpp:67
void set_func(std::function< Tensor(const Tensor &)> custom_f, const int &dtype, const int &device)
Definition LinOp.hpp:96
int device() const
Definition LinOp.hpp:164
int dtype() const
Definition LinOp.hpp:167
cytnx_uint64 nx() const
Definition LinOp.hpp:170
void set_elem(const cytnx_uint64 &i, const cytnx_uint64 &j, const T &elem, const bool check_exists=true)
Definition LinOp.hpp:109
void set_device(const int &device)
Definition LinOp.hpp:156
void _print()
Definition LinOp.cpp:11
void set_dtype(const int &dtype)
Definition LinOp.hpp:160
Tensor::Tproxy operator()(const cytnx_uint64 &i, const cytnx_uint64 &j)
Definition LinOp.hpp:128
an tensor (multi-dimensional array)
Definition Tensor.hpp:289
int device() const
the device-id of the Tensor
Definition Tensor.hpp:668
#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:137