31 std::map<cytnx_uint64, std::pair<std::vector<cytnx_uint64>,
Tensor>>
33 std::map<cytnx_uint64, std::pair<std::vector<cytnx_uint64>,
Tensor>>::iterator _elems_it;
71 }
else if (type ==
"mv_elem") {
74 "[ERROR][LinOp] currently only type=\"mv\" (matvec) can be used.%s",
"\n");
96 void set_elem(
const cytnx_uint64 &i,
const cytnx_uint64 &j,
const T &elem,
97 const bool check_exists =
true) {
98 this->_elems_it = this->_elems.find(i);
99 if (this->_elems_it == this->_elems.end()) {
101 Tensor x({1}, this->_dtype);
103 this->_elems[i] = std::pair<std::vector<cytnx_uint64>,
Tensor>({j}, x);
106 std::vector<cytnx_uint64> &vi = this->_elems_it->second.first;
107 Tensor &ie = this->_elems_it->second.second;
110 "[ERROR] the element is set%s",
"\n");
116 Tensor::Tproxy
operator()(
const cytnx_uint64 &i,
const cytnx_uint64 &j) {
119 this->_elems_it = this->_elems.find(i);
120 if (this->_elems_it == this->_elems.end()) {
122 Tensor x({1}, this->_dtype);
124 this->_elems[i] = std::pair<std::vector<cytnx_uint64>,
Tensor>({j}, x);
125 return this->_elems[i].second(0);
127 std::vector<cytnx_uint64> &vi = this->_elems_it->second.first;
128 Tensor &ie = this->_elems_it->second.second;
129 auto tmp_it = std::find(vi.begin(), vi.end(), j);
135 if (tmp_it == vi.end()) {
138 return ie(vi.size() - 1);
140 return ie(std::distance(vi.begin(), tmp_it));
151 this->_dtype =
dtype;
153 int device()
const {
return this->_device; };
154 int dtype()
const {
return this->_dtype; };
155 cytnx_uint64
nx()
const {
return this->_nx; };
constexpr Type_class Type
data type
Definition Type.hpp:553
virtual Tensor matvec(const Tensor &Tin)
int device() const
Definition LinOp.hpp:153
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:68
int dtype() const
Definition LinOp.hpp:154
cytnx_uint64 nx() const
Definition LinOp.hpp:155
void set_elem(const cytnx_uint64 &i, const cytnx_uint64 &j, const T &elem, const bool check_exists=true)
Definition LinOp.hpp:96
void set_device(const int &device)
Definition LinOp.hpp:145
void set_dtype(const int &dtype)
Definition LinOp.hpp:149
Tensor::Tproxy operator()(const cytnx_uint64 &i, const cytnx_uint64 &j)
Definition LinOp.hpp:116
an tensor (multi-dimensional array)
Definition Tensor.hpp:33
void append(const Tensor &rhs)
the append function.
Definition Tensor.hpp:1503
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:2773
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:118
Definition Accessor.hpp:12
Device_class Device
data on which devices.