16#include "utils/vec_clone.hpp"
33 std::map<cytnx_uint64, std::pair<std::vector<cytnx_uint64>,
Tensor>>
35 std::map<cytnx_uint64, std::pair<std::vector<cytnx_uint64>,
Tensor>>::iterator _elems_it;
77 }
else if (type ==
"mv_elem") {
80 "[ERROR][LinOp] currently only type=\"mv\" (matvec) can be used.%s",
"\n");
86 cytnx_error_msg(dtype < 1 || dtype >= N_Type,
"[ERROR] invalid dtype.%s",
"\n");
103 const bool check_exists =
true) {
104 this->_elems_it = this->_elems.find(i);
105 if (this->_elems_it == this->_elems.end()) {
107 Tensor x({1}, this->_dtype);
109 this->_elems[i] = std::pair<std::vector<cytnx_uint64>,
Tensor>({j}, x);
112 std::vector<cytnx_uint64> &vi = this->_elems_it->second.first;
113 Tensor &ie = this->_elems_it->second.second;
116 "[ERROR] the element is set%s",
"\n");
125 this->_elems_it = this->_elems.find(i);
126 if (this->_elems_it == this->_elems.end()) {
128 Tensor x({1}, this->_dtype);
130 this->_elems[i] = std::pair<std::vector<cytnx_uint64>,
Tensor>({j}, x);
131 return this->_elems[i].second(0);
133 std::vector<cytnx_uint64> &vi = this->_elems_it->second.first;
134 Tensor &ie = this->_elems_it->second.second;
135 auto tmp_it = std::find(vi.begin(), vi.end(), j);
141 if (tmp_it == vi.end()) {
144 return ie(vi.size() - 1);
146 return ie(std::distance(vi.begin(), tmp_it));
156 cytnx_error_msg(dtype < 1 || dtype >= N_Type,
"[ERROR] invalid dtype.%s",
"\n");
157 this->_dtype =
dtype;
159 int device()
const {
return this->_device; };
160 int dtype()
const {
return this->_dtype; };
int device() const
Definition LinOp.hpp:159
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:160
cytnx_uint64 nx() const
Definition LinOp.hpp:161
virtual Tensor matvec(const Tensor &Tin)
Definition LinOp.cpp:64
void set_elem(const cytnx_uint64 &i, const cytnx_uint64 &j, const T &elem, const bool check_exists=true)
Definition LinOp.hpp:102
void set_device(const int &device)
Definition LinOp.hpp:151
void _print()
Definition LinOp.cpp:10
void set_dtype(const int &dtype)
Definition LinOp.hpp:155
Tensor::Tproxy operator()(const cytnx_uint64 &i, const cytnx_uint64 &j)
Definition LinOp.hpp:122
an tensor (multi-dimensional array)
Definition Tensor.hpp:345
void append(const Tensor &rhs)
the append function.
Definition Tensor.hpp:1584
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:2449
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:16
Definition Accessor.hpp:12
Device_class Device
data on which devices.
Definition Device.cpp:140
uint64_t cytnx_uint64
Definition Type.hpp:45
Type_class Type
data type
Definition Type.cpp:23