Cytnx v0.7.6
Loading...
Searching...
No Matches
Scalar.hpp
Go to the documentation of this file.
1#ifndef _H_Scalar_
2#define _H_Scalar_
3
4#include "Type.hpp"
5#include "cytnx_error.hpp"
6//#include "lapack_wrapper.hpp"
8#include <vector>
9#include <initializer_list>
10#include <string>
11#include <iostream>
12#include <cmath>
13#include <type_traits>
14#include <limits>
15namespace cytnx{
16
17
19 class Storage_base;
20 class Tensor_base;
21
22 // real implementation
23 class Scalar_base{
24 private:
25
26 public:
27 int _dtype;
28
29 //Scalar_base(const Scalar_base &rhs);
30 //Scalar_base& operator=(const Scalar_base &rhs);
31 Scalar_base(): _dtype(Type.Void){};
32
33 virtual cytnx_float to_cytnx_float() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n"); return 0;};
34 virtual cytnx_double to_cytnx_double() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n"); return 0;};
35 virtual cytnx_complex64 to_cytnx_complex64() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return cytnx_complex64(0,0);};
36 virtual cytnx_complex128 to_cytnx_complex128() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return cytnx_complex128(0,0);};
37 virtual cytnx_int64 to_cytnx_int64() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return 0;};
38 virtual cytnx_uint64 to_cytnx_uint64() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return 0;};
39 virtual cytnx_int32 to_cytnx_int32() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return 0;};
40 virtual cytnx_uint32 to_cytnx_uint32() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return 0;};
41 virtual cytnx_int16 to_cytnx_int16() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return 0;};
42 virtual cytnx_uint16 to_cytnx_uint16() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return 0;};
43 virtual cytnx_bool to_cytnx_bool() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot cast to anytype!!%s","\n");return 0;}
44
45 virtual void iadd(const Scalar_base* c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
46 virtual void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
47 virtual void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
48 virtual void iadd(const cytnx_double &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
49 virtual void iadd(const cytnx_float &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
50 virtual void iadd(const cytnx_uint64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
51 virtual void iadd(const cytnx_int64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
52 virtual void iadd(const cytnx_uint32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
53 virtual void iadd(const cytnx_int32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
54 virtual void iadd(const cytnx_uint16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
55 virtual void iadd(const cytnx_int16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
56 virtual void iadd(const cytnx_bool &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
57
58 virtual void isub(const Scalar_base* c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
59 virtual void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
60 virtual void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
61 virtual void isub(const cytnx_double &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
62 virtual void isub(const cytnx_float &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
63 virtual void isub(const cytnx_uint64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
64 virtual void isub(const cytnx_int64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
65 virtual void isub(const cytnx_uint32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
66 virtual void isub(const cytnx_int32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
67 virtual void isub(const cytnx_uint16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
68 virtual void isub(const cytnx_int16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
69 virtual void isub(const cytnx_bool &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
70
71 virtual void imul(const Scalar_base* c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
72 virtual void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
73 virtual void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
74 virtual void imul(const cytnx_double &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
75 virtual void imul(const cytnx_float &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
76 virtual void imul(const cytnx_uint64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
77 virtual void imul(const cytnx_int64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
78 virtual void imul(const cytnx_uint32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
79 virtual void imul(const cytnx_int32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
80 virtual void imul(const cytnx_uint16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
81 virtual void imul(const cytnx_int16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
82 virtual void imul(const cytnx_bool &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
83
84 virtual void idiv(const Scalar_base* c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
85 virtual void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
86 virtual void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
87 virtual void idiv(const cytnx_double &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
88 virtual void idiv(const cytnx_float &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
89 virtual void idiv(const cytnx_uint64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
90 virtual void idiv(const cytnx_int64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
91 virtual void idiv(const cytnx_uint32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
92 virtual void idiv(const cytnx_int32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
93 virtual void idiv(const cytnx_uint16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
94 virtual void idiv(const cytnx_int16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
95 virtual void idiv(const cytnx_bool &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
96
97
98 virtual bool less(const Scalar_base* c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
99 virtual bool less(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
100 virtual bool less(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
101 virtual bool less(const cytnx_double &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
102 virtual bool less(const cytnx_float &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
103 virtual bool less(const cytnx_uint64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
104 virtual bool less(const cytnx_int64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
105 virtual bool less(const cytnx_uint32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
106 virtual bool less(const cytnx_int32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
107 virtual bool less(const cytnx_uint16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
108 virtual bool less(const cytnx_int16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
109 virtual bool less(const cytnx_bool &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
110
111 virtual bool greater(const Scalar_base* c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
112 virtual bool greater(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
113 virtual bool greater(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
114 virtual bool greater(const cytnx_double &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
115 virtual bool greater(const cytnx_float &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
116 virtual bool greater(const cytnx_uint64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
117 virtual bool greater(const cytnx_int64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
118 virtual bool greater(const cytnx_uint32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
119 virtual bool greater(const cytnx_int32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
120 virtual bool greater(const cytnx_uint16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
121 virtual bool greater(const cytnx_int16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
122 virtual bool greater(const cytnx_bool &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");return 0;}
123
124 virtual bool eq(const Scalar_base* c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n"); return 0;}
125
126
127 virtual void set_maxval(){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");};
128 virtual void set_minval(){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");};
129
130 virtual void conj_(){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
131 virtual Scalar_base* get_real(){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n"); return nullptr;}
132 virtual Scalar_base* get_imag(){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n"); return nullptr;}
133
134 virtual void iabs(){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
135 virtual void isqrt(){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
136
137 virtual void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
138 virtual void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
139 virtual void assign_selftype(const cytnx_double &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
140 virtual void assign_selftype(const cytnx_float &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
141 virtual void assign_selftype(const cytnx_uint64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
142 virtual void assign_selftype(const cytnx_int64 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
143 virtual void assign_selftype(const cytnx_uint32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
144 virtual void assign_selftype(const cytnx_int32 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
145 virtual void assign_selftype(const cytnx_uint16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
146 virtual void assign_selftype(const cytnx_int16 &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
147 virtual void assign_selftype(const cytnx_bool &c){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n");}
148
149 virtual Scalar_base* astype(const unsigned int &dtype){cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n"); return nullptr;}
150
151 virtual void* get_raw_address() const{cytnx_error_msg(true,"[ERROR] Void Type Scalar cannot have operation!!%s","\n"); return nullptr;}
152
153 virtual void print(std::ostream& os) const{};
154 virtual Scalar_base* copy() const{
155 Scalar_base *tmp = new Scalar_base();
156 return tmp;
157 };
158
159 //virtual ~Scalar_base(){};
160
161
162 };
163
164 typedef Scalar_base* (*pScalar_init)();
166
168 class Scalar_init_interface: public Type_class{
169 public:
170 std::vector<pScalar_init> UScIInit;
171 Scalar_init_interface();
172 };
173 extern Scalar_init_interface __ScII;
175
177 class ComplexDoubleScalar: public Scalar_base{
178
179 public:
180 cytnx_complex128 _elem;
181
182 ComplexDoubleScalar(): _elem(0){this->_dtype = Type.ComplexDouble;};
183 ComplexDoubleScalar(const cytnx_complex128 &in):_elem(0){
184 this->_dtype = Type.ComplexDouble;
185 this->_elem = in;
186 }
187
188 cytnx_float to_cytnx_float() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
189 cytnx_double to_cytnx_double() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
190 cytnx_complex64 to_cytnx_complex64() const{return cytnx_complex64(this->_elem);};
191 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
192 cytnx_int64 to_cytnx_int64() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
193 cytnx_uint64 to_cytnx_uint64() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
194 cytnx_int32 to_cytnx_int32() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
195 cytnx_uint32 to_cytnx_uint32() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
196 cytnx_int16 to_cytnx_int16() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
197 cytnx_uint16 to_cytnx_uint16() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
198 cytnx_bool to_cytnx_bool() const{cytnx_error_msg(true,"[ERROR] cannot cast complex128 to real%s","\n");return 0;};
199
200 void assign_selftype(const cytnx_complex128 &c){this->_elem = c;}
201 void assign_selftype(const cytnx_complex64 &c){this->_elem = c;}
202 void assign_selftype(const cytnx_double &c){this->_elem = c;}
203 void assign_selftype(const cytnx_float &c){this->_elem = c;}
204 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
205 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
206 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
207 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
208 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
209 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
210 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
211
212 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_complex128();}
213 void iadd(const cytnx_complex128 &c){this->_elem += c;}
214 void iadd(const cytnx_complex64 &c){this->_elem += c;}
215 void iadd(const cytnx_double &c){this->_elem += c;}
216 void iadd(const cytnx_float &c){this->_elem += c;}
217 void iadd(const cytnx_uint64 &c){this->_elem += c;}
218 void iadd(const cytnx_int64 &c){this->_elem += c;}
219 void iadd(const cytnx_uint32 &c){this->_elem += c;}
220 void iadd(const cytnx_int32 &c){this->_elem += c;}
221 void iadd(const cytnx_uint16 &c){this->_elem += c;}
222 void iadd(const cytnx_int16 &c){this->_elem += c;}
223 void iadd(const cytnx_bool &c){this->_elem += c;}
224
225 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_complex128();}
226 void isub(const cytnx_complex128 &c){this->_elem -= c;}
227 void isub(const cytnx_complex64 &c){this->_elem -= c;}
228 void isub(const cytnx_double &c){this->_elem -= c;}
229 void isub(const cytnx_float &c){this->_elem -= c;}
230 void isub(const cytnx_uint64 &c){this->_elem -= c;}
231 void isub(const cytnx_int64 &c){this->_elem -= c;}
232 void isub(const cytnx_uint32 &c){this->_elem -= c;}
233 void isub(const cytnx_int32 &c){this->_elem -= c;}
234 void isub(const cytnx_uint16 &c){this->_elem -= c;}
235 void isub(const cytnx_int16 &c){this->_elem -= c;}
236 void isub(const cytnx_bool &c){this->_elem -= c;}
237
238 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_complex128();}
239 void imul(const cytnx_complex128 &c){this->_elem *= c;}
240 void imul(const cytnx_complex64 &c){this->_elem *= c;}
241 void imul(const cytnx_double &c){this->_elem *= c;}
242 void imul(const cytnx_float &c){this->_elem *= c;}
243 void imul(const cytnx_uint64 &c){this->_elem *= c;}
244 void imul(const cytnx_int64 &c){this->_elem *= c;}
245 void imul(const cytnx_uint32 &c){this->_elem *= c;}
246 void imul(const cytnx_int32 &c){this->_elem *= c;}
247 void imul(const cytnx_uint16 &c){this->_elem *= c;}
248 void imul(const cytnx_int16 &c){this->_elem *= c;}
249 void imul(const cytnx_bool &c){this->_elem *= c;}
250
251 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_complex128();}
252 void idiv(const cytnx_complex128 &c){this->_elem /= c;}
253 void idiv(const cytnx_complex64 &c){this->_elem /= c;}
254 void idiv(const cytnx_double &c){this->_elem /= c;}
255 void idiv(const cytnx_float &c){this->_elem /= c;}
256 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
257 void idiv(const cytnx_int64 &c){this->_elem /= c;}
258 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
259 void idiv(const cytnx_int32 &c){this->_elem /= c;}
260 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
261 void idiv(const cytnx_int16 &c){this->_elem /= c;}
262 void idiv(const cytnx_bool &c){this->_elem /= c;}
263
264 void iabs(){this->_elem=std::abs(cytnx_complex128(this->_elem));}
265 void isqrt(){this->_elem=std::sqrt(this->_elem);}
266
267 bool less(const Scalar_base* c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
268 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
269 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
270 bool less(const cytnx_double &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
271 bool less(const cytnx_float &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
272 bool less(const cytnx_uint64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
273 bool less(const cytnx_int64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
274 bool less(const cytnx_uint32 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
275 bool less(const cytnx_int32 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
276 bool less(const cytnx_uint16 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
277 bool less(const cytnx_int16 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
278 bool less(const cytnx_bool &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
279
280 bool greater(const Scalar_base* c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
281 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
282 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
283 bool greater(const cytnx_double &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
284 bool greater(const cytnx_float &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
285 bool greater(const cytnx_uint64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
286 bool greater(const cytnx_int64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
287 bool greater(const cytnx_uint32 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
288 bool greater(const cytnx_int32 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
289 bool greater(const cytnx_uint16 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
290 bool greater(const cytnx_int16 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
291 bool greater(const cytnx_bool &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
292
293 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_complex128();}
294
295 void set_maxval(){cytnx_error_msg(true, "[ERROR] maxval not supported for complex type%s","\n");}
296 void set_minval(){cytnx_error_msg(true, "[ERROR] minval not supported for complex type%s","\n");}
297
298 void conj_(){this->_elem = std::conj(this->_elem);}
299 Scalar_base* get_real(){
300 Scalar_base *tmp = __ScII.UScIInit[Type.Double]();
301 tmp->assign_selftype(this->_elem.real());
302 return tmp;
303 }
304 Scalar_base* get_imag(){
305 Scalar_base *tmp = __ScII.UScIInit[Type.Double]();
306 tmp->assign_selftype(this->_elem.imag());
307 return tmp;
308 }
309
310 void* get_raw_address() const{return (void*)(&this->_elem);}
311
312 Scalar_base* astype(const unsigned int &dtype){
313 Scalar_base *tmp = __ScII.UScIInit[dtype]();
314 tmp->assign_selftype(this->_elem);
315 return tmp;
316 }
317
318 Scalar_base* copy() const{
319 ComplexDoubleScalar *tmp = new ComplexDoubleScalar(this->_elem);
320 return tmp;
321 };
322 void print(std::ostream& os) const{
323 os << "< " << this->_elem << " >";
324 };
325 };
326
327 class ComplexFloatScalar: public Scalar_base{
328
329 public:
330 cytnx_complex64 _elem;
331
332 ComplexFloatScalar(): _elem(0){this->_dtype = Type.ComplexFloat;};
333 ComplexFloatScalar(const cytnx_complex64 &in): _elem(0){
334 this->_dtype = Type.ComplexFloat;
335 this->_elem = in;
336 }
337
338 cytnx_float to_cytnx_float() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
339 cytnx_double to_cytnx_double() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
340 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
341 cytnx_complex128 to_cytnx_complex128() const{return cytnx_complex128(this->_elem);};
342 cytnx_int64 to_cytnx_int64() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
343 cytnx_uint64 to_cytnx_uint64() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
344 cytnx_int32 to_cytnx_int32() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
345 cytnx_uint32 to_cytnx_uint32() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
346 cytnx_int16 to_cytnx_int16() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
347 cytnx_uint16 to_cytnx_uint16() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
348 cytnx_bool to_cytnx_bool() const{cytnx_error_msg(true,"[ERROR] cannot cast complex64 to real%s","\n");return 0;};
349
350 void assign_selftype(const cytnx_complex128 &c){this->_elem = c;}
351 void assign_selftype(const cytnx_complex64 &c){this->_elem = c;}
352 void assign_selftype(const cytnx_double &c){this->_elem = c;}
353 void assign_selftype(const cytnx_float &c){this->_elem = c;}
354 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
355 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
356 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
357 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
358 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
359 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
360 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
361
362
363 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_complex64();}
364 void iadd(const cytnx_complex128 &c){this->_elem += c;}
365 void iadd(const cytnx_complex64 &c){this->_elem += c;}
366 void iadd(const cytnx_double &c){this->_elem += c;}
367 void iadd(const cytnx_float &c){this->_elem += c;}
368 void iadd(const cytnx_uint64 &c){this->_elem += c;}
369 void iadd(const cytnx_int64 &c){this->_elem += c;}
370 void iadd(const cytnx_uint32 &c){this->_elem += c;}
371 void iadd(const cytnx_int32 &c){this->_elem += c;}
372 void iadd(const cytnx_uint16 &c){this->_elem += c;}
373 void iadd(const cytnx_int16 &c){this->_elem += c;}
374 void iadd(const cytnx_bool &c){this->_elem += c;}
375
376 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_complex64();}
377 void isub(const cytnx_complex128 &c){this->_elem -= c;}
378 void isub(const cytnx_complex64 &c){this->_elem -= c;}
379 void isub(const cytnx_double &c){this->_elem -= c;}
380 void isub(const cytnx_float &c){this->_elem -= c;}
381 void isub(const cytnx_uint64 &c){this->_elem -= c;}
382 void isub(const cytnx_int64 &c){this->_elem -= c;}
383 void isub(const cytnx_uint32 &c){this->_elem -= c;}
384 void isub(const cytnx_int32 &c){this->_elem -= c;}
385 void isub(const cytnx_uint16 &c){this->_elem -= c;}
386 void isub(const cytnx_int16 &c){this->_elem -= c;}
387 void isub(const cytnx_bool &c){this->_elem -= c;}
388
389 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_complex64();}
390 void imul(const cytnx_complex128 &c){this->_elem *= c;}
391 void imul(const cytnx_complex64 &c){this->_elem *= c;}
392 void imul(const cytnx_double &c){this->_elem *= c;}
393 void imul(const cytnx_float &c){this->_elem *= c;}
394 void imul(const cytnx_uint64 &c){this->_elem *= c;}
395 void imul(const cytnx_int64 &c){this->_elem *= c;}
396 void imul(const cytnx_uint32 &c){this->_elem *= c;}
397 void imul(const cytnx_int32 &c){this->_elem *= c;}
398 void imul(const cytnx_uint16 &c){this->_elem *= c;}
399 void imul(const cytnx_int16 &c){this->_elem *= c;}
400 void imul(const cytnx_bool &c){this->_elem *= c;}
401
402 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_complex64();}
403 void idiv(const cytnx_complex128 &c){this->_elem /= c;}
404 void idiv(const cytnx_complex64 &c){this->_elem /= c;}
405 void idiv(const cytnx_double &c){this->_elem /= c;}
406 void idiv(const cytnx_float &c){this->_elem /= c;}
407 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
408 void idiv(const cytnx_int64 &c){this->_elem /= c;}
409 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
410 void idiv(const cytnx_int32 &c){this->_elem /= c;}
411 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
412 void idiv(const cytnx_int16 &c){this->_elem /= c;}
413 void idiv(const cytnx_bool &c){this->_elem /= c;}
414
415
416 bool less(const Scalar_base* c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
417 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
418 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
419 bool less(const cytnx_double &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
420 bool less(const cytnx_float &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
421 bool less(const cytnx_uint64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
422 bool less(const cytnx_int64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
423 bool less(const cytnx_uint32 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
424 bool less(const cytnx_int32 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
425 bool less(const cytnx_uint16 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
426 bool less(const cytnx_int16 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
427 bool less(const cytnx_bool &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
428
429 bool greater(const Scalar_base* c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
430 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
431 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
432 bool greater(const cytnx_double &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
433 bool greater(const cytnx_float &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
434 bool greater(const cytnx_uint64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
435 bool greater(const cytnx_int64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
436 bool greater(const cytnx_uint32 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
437 bool greater(const cytnx_int32 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
438 bool greater(const cytnx_uint16 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
439 bool greater(const cytnx_int16 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
440 bool greater(const cytnx_bool &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
441
442 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_complex64();}
443
444 void set_maxval(){cytnx_error_msg(true, "[ERROR] maxval not supported for complex type%s","\n");}
445 void set_minval(){cytnx_error_msg(true, "[ERROR] minval not supported for complex type%s","\n");}
446
447 void conj_(){this->_elem = std::conj(this->_elem);}
448 Scalar_base* get_real(){
449 Scalar_base *tmp = __ScII.UScIInit[Type.Float]();
450 tmp->assign_selftype(this->_elem.real());
451 return tmp;
452 }
453 Scalar_base* get_imag(){
454 Scalar_base *tmp = __ScII.UScIInit[Type.Float]();
455 tmp->assign_selftype(this->_elem.imag());
456 return tmp;
457 }
458
459 void iabs(){this->_elem=std::abs(this->_elem);}
460 void isqrt(){this->_elem=std::sqrt(this->_elem);}
461
462 void* get_raw_address() const{return (void*)(&this->_elem);}
463 Scalar_base* astype(const unsigned int &dtype){
464 Scalar_base *tmp = __ScII.UScIInit[dtype]();
465 tmp->assign_selftype(this->_elem);
466 return tmp;
467 }
468
469 Scalar_base* copy() const{
470 ComplexFloatScalar *tmp = new ComplexFloatScalar(this->_elem);
471 return tmp;
472 };
473 void print(std::ostream& os) const{
474 os << "< " << this->_elem << " >";
475 };
476 };
477
478 class DoubleScalar: public Scalar_base{
479
480 public:
481 cytnx_double _elem;
482
483 DoubleScalar(): _elem(0){this->_dtype = Type.Double;};
484 DoubleScalar(const cytnx_double &in): _elem(0){
485 this->_dtype = Type.Double;
486 this->_elem = in;
487 }
488
489 cytnx_float to_cytnx_float() const{return this->_elem;};
490 cytnx_double to_cytnx_double() const{return this->_elem;};
491 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
492 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
493 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
494 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
495 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
496 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
497 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
498 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
499 cytnx_bool to_cytnx_bool() const{return this->_elem;};
500
501 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
502 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
503 void assign_selftype(const cytnx_double &c){this->_elem = c;}
504 void assign_selftype(const cytnx_float &c){this->_elem = c;}
505 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
506 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
507 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
508 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
509 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
510 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
511 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
512
513
514 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_double();}
515 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
516 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
517 void iadd(const cytnx_double &c){this->_elem += c;}
518 void iadd(const cytnx_float &c){this->_elem += c;}
519 void iadd(const cytnx_uint64 &c){this->_elem += c;}
520 void iadd(const cytnx_int64 &c){this->_elem += c;}
521 void iadd(const cytnx_uint32 &c){this->_elem += c;}
522 void iadd(const cytnx_int32 &c){this->_elem += c;}
523 void iadd(const cytnx_uint16 &c){this->_elem += c;}
524 void iadd(const cytnx_int16 &c){this->_elem += c;}
525 void iadd(const cytnx_bool &c){this->_elem += c;}
526
527 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_double();}
528 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
529 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
530 void isub(const cytnx_double &c){this->_elem -= c;}
531 void isub(const cytnx_float &c){this->_elem -= c;}
532 void isub(const cytnx_uint64 &c){this->_elem -= c;}
533 void isub(const cytnx_int64 &c){this->_elem -= c;}
534 void isub(const cytnx_uint32 &c){this->_elem -= c;}
535 void isub(const cytnx_int32 &c){this->_elem -= c;}
536 void isub(const cytnx_uint16 &c){this->_elem -= c;}
537 void isub(const cytnx_int16 &c){this->_elem -= c;}
538 void isub(const cytnx_bool &c){this->_elem -= c;}
539
540 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_double();}
541 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
542 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
543 void imul(const cytnx_double &c){this->_elem *= c;}
544 void imul(const cytnx_float &c){this->_elem *= c;}
545 void imul(const cytnx_uint64 &c){this->_elem *= c;}
546 void imul(const cytnx_int64 &c){this->_elem *= c;}
547 void imul(const cytnx_uint32 &c){this->_elem *= c;}
548 void imul(const cytnx_int32 &c){this->_elem *= c;}
549 void imul(const cytnx_uint16 &c){this->_elem *= c;}
550 void imul(const cytnx_int16 &c){this->_elem *= c;}
551 void imul(const cytnx_bool &c){this->_elem *= c;}
552
553 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_double();}
554 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
555 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
556 void idiv(const cytnx_double &c){this->_elem /= c;}
557 void idiv(const cytnx_float &c){this->_elem /= c;}
558 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
559 void idiv(const cytnx_int64 &c){this->_elem /= c;}
560 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
561 void idiv(const cytnx_int32 &c){this->_elem /= c;}
562 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
563 void idiv(const cytnx_int16 &c){this->_elem /= c;}
564 void idiv(const cytnx_bool &c){this->_elem /= c;}
565
566 void iabs(){this->_elem=std::abs(this->_elem);}
567 void isqrt(){this->_elem=std::sqrt(this->_elem);}
568
569 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_double();}
570 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
571 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
572 bool less(const cytnx_double &c){return this->_elem < c;}
573 bool less(const cytnx_float &c){return this->_elem < c;}
574 bool less(const cytnx_uint64 &c){return this->_elem < c;}
575 bool less(const cytnx_int64 &c){return this->_elem < c;}
576 bool less(const cytnx_uint32 &c){return this->_elem < c;}
577 bool less(const cytnx_int32 &c){return this->_elem < c;}
578 bool less(const cytnx_uint16 &c){return this->_elem < c;}
579 bool less(const cytnx_int16 &c){return this->_elem < c;}
580 bool less(const cytnx_bool &c){return this->_elem < c;}
581
582 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_double();}
583 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
584 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
585 bool greater(const cytnx_double &c){return this->_elem > c;}
586 bool greater(const cytnx_float &c){return this->_elem > c;}
587 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
588 bool greater(const cytnx_int64 &c){return this->_elem > c;}
589 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
590 bool greater(const cytnx_int32 &c){return this->_elem > c;}
591 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
592 bool greater(const cytnx_int16 &c){return this->_elem > c;}
593 bool greater(const cytnx_bool &c){return this->_elem > c;}
594
595 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_double();}
596
597 void set_maxval(){this->_elem = std::numeric_limits<double>::max();}
598 void set_minval(){this->_elem = std::numeric_limits<double>::min();}
599
600 void conj_(){return;}
601 Scalar_base* get_real(){return this->copy();}
602 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
603
604
605 void* get_raw_address() const{return (void*)(&this->_elem);}
606 Scalar_base* astype(const unsigned int &dtype){
607 Scalar_base *tmp = __ScII.UScIInit[dtype]();
608 tmp->assign_selftype(this->_elem);
609 return tmp;
610 }
611 Scalar_base* copy() const{
612 DoubleScalar *tmp = new DoubleScalar(this->_elem);
613 return tmp;
614 };
615 void print(std::ostream& os) const{
616 os << "< " << this->_elem << " >";
617 };
618 };
619
620 class FloatScalar: public Scalar_base{
621
622 public:
623 cytnx_float _elem;
624
625 FloatScalar(): _elem(0){this->_dtype = Type.Float;};
626 FloatScalar(const cytnx_float &in): _elem(0){
627 this->_dtype = Type.Float;
628 this->_elem = in;
629 }
630
631 cytnx_float to_cytnx_float() const{return this->_elem;};
632 cytnx_double to_cytnx_double() const{return this->_elem;};
633 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
634 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
635 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
636 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
637 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
638 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
639 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
640 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
641 cytnx_bool to_cytnx_bool() const{return this->_elem;};
642
643 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
644 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
645 void assign_selftype(const cytnx_double &c){this->_elem = c;}
646 void assign_selftype(const cytnx_float &c){this->_elem = c;}
647 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
648 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
649 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
650 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
651 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
652 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
653 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
654
655 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_float();}
656 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
657 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
658 void iadd(const cytnx_double &c){this->_elem += c;}
659 void iadd(const cytnx_float &c){this->_elem += c;}
660 void iadd(const cytnx_uint64 &c){this->_elem += c;}
661 void iadd(const cytnx_int64 &c){this->_elem += c;}
662 void iadd(const cytnx_uint32 &c){this->_elem += c;}
663 void iadd(const cytnx_int32 &c){this->_elem += c;}
664 void iadd(const cytnx_uint16 &c){this->_elem += c;}
665 void iadd(const cytnx_int16 &c){this->_elem += c;}
666 void iadd(const cytnx_bool &c){this->_elem += c;}
667
668 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_float();}
669 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
670 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
671 void isub(const cytnx_double &c){this->_elem -= c;}
672 void isub(const cytnx_float &c){this->_elem -= c;}
673 void isub(const cytnx_uint64 &c){this->_elem -= c;}
674 void isub(const cytnx_int64 &c){this->_elem -= c;}
675 void isub(const cytnx_uint32 &c){this->_elem -= c;}
676 void isub(const cytnx_int32 &c){this->_elem -= c;}
677 void isub(const cytnx_uint16 &c){this->_elem -= c;}
678 void isub(const cytnx_int16 &c){this->_elem -= c;}
679 void isub(const cytnx_bool &c){this->_elem -= c;}
680
681 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_float();}
682 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
683 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
684 void imul(const cytnx_double &c){this->_elem *= c;}
685 void imul(const cytnx_float &c){this->_elem *= c;}
686 void imul(const cytnx_uint64 &c){this->_elem *= c;}
687 void imul(const cytnx_int64 &c){this->_elem *= c;}
688 void imul(const cytnx_uint32 &c){this->_elem *= c;}
689 void imul(const cytnx_int32 &c){this->_elem *= c;}
690 void imul(const cytnx_uint16 &c){this->_elem *= c;}
691 void imul(const cytnx_int16 &c){this->_elem *= c;}
692 void imul(const cytnx_bool &c){this->_elem *= c;}
693
694 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_float();}
695 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
696 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
697 void idiv(const cytnx_double &c){this->_elem /= c;}
698 void idiv(const cytnx_float &c){this->_elem /= c;}
699 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
700 void idiv(const cytnx_int64 &c){this->_elem /= c;}
701 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
702 void idiv(const cytnx_int32 &c){this->_elem /= c;}
703 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
704 void idiv(const cytnx_int16 &c){this->_elem /= c;}
705 void idiv(const cytnx_bool &c){this->_elem /= c;}
706
707
708
709 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_float();}
710 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
711 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
712 bool less(const cytnx_double &c){return this->_elem < c;}
713 bool less(const cytnx_float &c){return this->_elem < c;}
714 bool less(const cytnx_uint64 &c){return this->_elem < c;}
715 bool less(const cytnx_int64 &c){return this->_elem < c;}
716 bool less(const cytnx_uint32 &c){return this->_elem < c;}
717 bool less(const cytnx_int32 &c){return this->_elem < c;}
718 bool less(const cytnx_uint16 &c){return this->_elem < c;}
719 bool less(const cytnx_int16 &c){return this->_elem < c;}
720 bool less(const cytnx_bool &c){return this->_elem < c;}
721
722 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_float();}
723 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
724 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
725 bool greater(const cytnx_double &c){return this->_elem > c;}
726 bool greater(const cytnx_float &c){return this->_elem > c;}
727 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
728 bool greater(const cytnx_int64 &c){return this->_elem > c;}
729 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
730 bool greater(const cytnx_int32 &c){return this->_elem > c;}
731 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
732 bool greater(const cytnx_int16 &c){return this->_elem > c;}
733 bool greater(const cytnx_bool &c){return this->_elem > c;}
734
735 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_float();}
736 void isqrt(){this->_elem=std::sqrt(this->_elem);}
737
738 void conj_(){return;}
739 Scalar_base* get_real(){return this->copy();}
740 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
741
742 void set_maxval(){this->_elem = std::numeric_limits<float>::max();}
743 void set_minval(){this->_elem = std::numeric_limits<float>::min();}
744
745 void iabs(){this->_elem=std::abs(this->_elem);}
746
747 void* get_raw_address() const{return (void*)(&this->_elem);}
748 Scalar_base* astype(const unsigned int &dtype){
749 Scalar_base *tmp = __ScII.UScIInit[dtype]();
750 tmp->assign_selftype(this->_elem);
751 return tmp;
752 }
753 Scalar_base* copy() const{
754 FloatScalar *tmp = new FloatScalar(this->_elem);
755 return tmp;
756 };
757 void print(std::ostream& os) const{
758 os << "< " << this->_elem << " >";
759 };
760 };
761
762 class Int64Scalar: public Scalar_base{
763
764 public:
765 cytnx_int64 _elem;
766
767 Int64Scalar(): _elem(0){this->_dtype = Type.Int64;};
768 Int64Scalar(const cytnx_int64 &in): _elem(0){
769 this->_dtype = Type.Int64;
770 this->_elem = in;
771 }
772
773 cytnx_float to_cytnx_float() const{return this->_elem;};
774 cytnx_double to_cytnx_double() const{return this->_elem;};
775 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
776 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
777 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
778 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
779 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
780 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
781 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
782 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
783 cytnx_bool to_cytnx_bool() const{return this->_elem;};
784
785 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
786 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
787 void assign_selftype(const cytnx_double &c){this->_elem = c;}
788 void assign_selftype(const cytnx_float &c){this->_elem = c;}
789 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
790 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
791 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
792 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
793 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
794 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
795 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
796
797 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_int64();}
798 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
799 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
800 void iadd(const cytnx_double &c){this->_elem += c;}
801 void iadd(const cytnx_float &c){this->_elem += c;}
802 void iadd(const cytnx_uint64 &c){this->_elem += c;}
803 void iadd(const cytnx_int64 &c){this->_elem += c;}
804 void iadd(const cytnx_uint32 &c){this->_elem += c;}
805 void iadd(const cytnx_int32 &c){this->_elem += c;}
806 void iadd(const cytnx_uint16 &c){this->_elem += c;}
807 void iadd(const cytnx_int16 &c){this->_elem += c;}
808 void iadd(const cytnx_bool &c){this->_elem += c;}
809
810 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_int64();}
811 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
812 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
813 void isub(const cytnx_double &c){this->_elem -= c;}
814 void isub(const cytnx_float &c){this->_elem -= c;}
815 void isub(const cytnx_uint64 &c){this->_elem -= c;}
816 void isub(const cytnx_int64 &c){this->_elem -= c;}
817 void isub(const cytnx_uint32 &c){this->_elem -= c;}
818 void isub(const cytnx_int32 &c){this->_elem -= c;}
819 void isub(const cytnx_uint16 &c){this->_elem -= c;}
820 void isub(const cytnx_int16 &c){this->_elem -= c;}
821 void isub(const cytnx_bool &c){this->_elem -= c;}
822
823 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_int64();}
824 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
825 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
826 void imul(const cytnx_double &c){this->_elem *= c;}
827 void imul(const cytnx_float &c){this->_elem *= c;}
828 void imul(const cytnx_uint64 &c){this->_elem *= c;}
829 void imul(const cytnx_int64 &c){this->_elem *= c;}
830 void imul(const cytnx_uint32 &c){this->_elem *= c;}
831 void imul(const cytnx_int32 &c){this->_elem *= c;}
832 void imul(const cytnx_uint16 &c){this->_elem *= c;}
833 void imul(const cytnx_int16 &c){this->_elem *= c;}
834 void imul(const cytnx_bool &c){this->_elem *= c;}
835
836
837 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_int64();}
838 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
839 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
840 void idiv(const cytnx_double &c){this->_elem /= c;}
841 void idiv(const cytnx_float &c){this->_elem /= c;}
842 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
843 void idiv(const cytnx_int64 &c){this->_elem /= c;}
844 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
845 void idiv(const cytnx_int32 &c){this->_elem /= c;}
846 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
847 void idiv(const cytnx_int16 &c){this->_elem /= c;}
848 void idiv(const cytnx_bool &c){this->_elem /= c;}
849
850 void iabs(){this->_elem=std::abs(this->_elem);}
851 void isqrt(){this->_elem=std::sqrt(this->_elem);}
852
853 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_int64();}
854 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
855 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
856 bool less(const cytnx_double &c){return this->_elem < c;}
857 bool less(const cytnx_float &c){return this->_elem < c;}
858 bool less(const cytnx_uint64 &c){return this->_elem < c;}
859 bool less(const cytnx_int64 &c){return this->_elem < c;}
860 bool less(const cytnx_uint32 &c){return this->_elem < c;}
861 bool less(const cytnx_int32 &c){return this->_elem < c;}
862 bool less(const cytnx_uint16 &c){return this->_elem < c;}
863 bool less(const cytnx_int16 &c){return this->_elem < c;}
864 bool less(const cytnx_bool &c){return this->_elem < c;}
865
866 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_int64();}
867 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
868 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
869 bool greater(const cytnx_double &c){return this->_elem > c;}
870 bool greater(const cytnx_float &c){return this->_elem > c;}
871 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
872 bool greater(const cytnx_int64 &c){return this->_elem > c;}
873 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
874 bool greater(const cytnx_int32 &c){return this->_elem > c;}
875 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
876 bool greater(const cytnx_int16 &c){return this->_elem > c;}
877 bool greater(const cytnx_bool &c){return this->_elem > c;}
878
879 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_int64();}
880
881 void conj_(){return;}
882 Scalar_base* get_real(){return this->copy();}
883 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
884
885 void set_maxval(){this->_elem = std::numeric_limits<cytnx_int64>::max();}
886 void set_minval(){this->_elem = std::numeric_limits<cytnx_int64>::min();}
887
888 void* get_raw_address() const{return (void*)(&this->_elem);}
889 Scalar_base* astype(const unsigned int &dtype){
890 Scalar_base *tmp = __ScII.UScIInit[dtype]();
891 tmp->assign_selftype(this->_elem);
892 return tmp;
893 }
894 Scalar_base* copy() const{
895 Int64Scalar *tmp = new Int64Scalar(this->_elem);
896 return tmp;
897 };
898 void print(std::ostream& os) const{
899 os << "< " << this->_elem << " >";
900 };
901 };
902 class Uint64Scalar: public Scalar_base{
903
904 public:
905 cytnx_uint64 _elem;
906
907 Uint64Scalar(): _elem(0){this->_dtype = Type.Uint64;};
908 Uint64Scalar(const cytnx_uint64 &in): _elem(0){
909 this->_dtype = Type.Uint64;
910 this->_elem = in;
911 }
912
913 cytnx_float to_cytnx_float() const{return this->_elem;};
914 cytnx_double to_cytnx_double() const{return this->_elem;};
915 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
916 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
917 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
918 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
919 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
920 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
921 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
922 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
923 cytnx_bool to_cytnx_bool() const{return this->_elem;};
924
925 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
926 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
927 void assign_selftype(const cytnx_double &c){this->_elem = c;}
928 void assign_selftype(const cytnx_float &c){this->_elem = c;}
929 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
930 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
931 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
932 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
933 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
934 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
935 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
936
937 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_uint64();}
938 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
939 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
940 void iadd(const cytnx_double &c){this->_elem += c;}
941 void iadd(const cytnx_float &c){this->_elem += c;}
942 void iadd(const cytnx_uint64 &c){this->_elem += c;}
943 void iadd(const cytnx_int64 &c){this->_elem += c;}
944 void iadd(const cytnx_uint32 &c){this->_elem += c;}
945 void iadd(const cytnx_int32 &c){this->_elem += c;}
946 void iadd(const cytnx_uint16 &c){this->_elem += c;}
947 void iadd(const cytnx_int16 &c){this->_elem += c;}
948 void iadd(const cytnx_bool &c){this->_elem += c;}
949
950 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_uint64();}
951 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
952 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
953 void isub(const cytnx_double &c){this->_elem -= c;}
954 void isub(const cytnx_float &c){this->_elem -= c;}
955 void isub(const cytnx_uint64 &c){this->_elem -= c;}
956 void isub(const cytnx_int64 &c){this->_elem -= c;}
957 void isub(const cytnx_uint32 &c){this->_elem -= c;}
958 void isub(const cytnx_int32 &c){this->_elem -= c;}
959 void isub(const cytnx_uint16 &c){this->_elem -= c;}
960 void isub(const cytnx_int16 &c){this->_elem -= c;}
961 void isub(const cytnx_bool &c){this->_elem -= c;}
962
963 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_uint64();}
964 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
965 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
966 void imul(const cytnx_double &c){this->_elem *= c;}
967 void imul(const cytnx_float &c){this->_elem *= c;}
968 void imul(const cytnx_uint64 &c){this->_elem *= c;}
969 void imul(const cytnx_int64 &c){this->_elem *= c;}
970 void imul(const cytnx_uint32 &c){this->_elem *= c;}
971 void imul(const cytnx_int32 &c){this->_elem *= c;}
972 void imul(const cytnx_uint16 &c){this->_elem *= c;}
973 void imul(const cytnx_int16 &c){this->_elem *= c;}
974 void imul(const cytnx_bool &c){this->_elem *= c;}
975
976 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_uint64();}
977 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
978 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
979 void idiv(const cytnx_double &c){this->_elem /= c;}
980 void idiv(const cytnx_float &c){this->_elem /= c;}
981 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
982 void idiv(const cytnx_int64 &c){this->_elem /= c;}
983 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
984 void idiv(const cytnx_int32 &c){this->_elem /= c;}
985 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
986 void idiv(const cytnx_int16 &c){this->_elem /= c;}
987 void idiv(const cytnx_bool &c){this->_elem /= c;}
988
989 void iabs(){this->_elem=std::abs(cytnx_double(this->_elem));}
990 void isqrt(){this->_elem=std::sqrt(this->_elem);}
991
992 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_uint64();}
993 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
994 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
995 bool less(const cytnx_double &c){return this->_elem < c;}
996 bool less(const cytnx_float &c){return this->_elem < c;}
997 bool less(const cytnx_uint64 &c){return this->_elem < c;}
998 bool less(const cytnx_int64 &c){return this->_elem < c;}
999 bool less(const cytnx_uint32 &c){return this->_elem < c;}
1000 bool less(const cytnx_int32 &c){return this->_elem < c;}
1001 bool less(const cytnx_uint16 &c){return this->_elem < c;}
1002 bool less(const cytnx_int16 &c){return this->_elem < c;}
1003 bool less(const cytnx_bool &c){return this->_elem < c;}
1004
1005 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_uint64();}
1006 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1007 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1008 bool greater(const cytnx_double &c){return this->_elem > c;}
1009 bool greater(const cytnx_float &c){return this->_elem > c;}
1010 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
1011 bool greater(const cytnx_int64 &c){return this->_elem > c;}
1012 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
1013 bool greater(const cytnx_int32 &c){return this->_elem > c;}
1014 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
1015 bool greater(const cytnx_int16 &c){return this->_elem > c;}
1016 bool greater(const cytnx_bool &c){return this->_elem > c;}
1017
1018 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_uint64();}
1019
1020 void conj_(){return;}
1021 Scalar_base* get_real(){return this->copy();}
1022 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
1023
1024 void set_maxval(){this->_elem = std::numeric_limits<cytnx_uint64>::max();}
1025 void set_minval(){this->_elem = std::numeric_limits<cytnx_uint64>::min();}
1026
1027
1028 void* get_raw_address() const{return (void*)(&this->_elem);}
1029 Scalar_base* astype(const unsigned int &dtype){
1030 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1031 tmp->assign_selftype(this->_elem);
1032 return tmp;
1033 }
1034 Scalar_base* copy() const{
1035 Uint64Scalar *tmp = new Uint64Scalar(this->_elem);
1036 return tmp;
1037 };
1038 void print(std::ostream& os) const{
1039 os << "< " << this->_elem << " >";
1040 };
1041 };
1042 class Int32Scalar: public Scalar_base{
1043
1044 public:
1045 cytnx_int32 _elem;
1046
1047 Int32Scalar(): _elem(0){this->_dtype = Type.Int32;};
1048 Int32Scalar(const cytnx_int32 &in): _elem(0){
1049 this->_dtype = Type.Int32;
1050 this->_elem = in;
1051 }
1052
1053 cytnx_float to_cytnx_float() const{return this->_elem;};
1054 cytnx_double to_cytnx_double() const{return this->_elem;};
1055 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
1056 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
1057 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
1058 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
1059 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
1060 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
1061 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
1062 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
1063 cytnx_bool to_cytnx_bool() const{return this->_elem;};
1064
1065
1066 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1067 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1068 void assign_selftype(const cytnx_double &c){this->_elem = c;}
1069 void assign_selftype(const cytnx_float &c){this->_elem = c;}
1070 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
1071 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
1072 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
1073 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
1074 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
1075 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
1076 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
1077
1078 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_int32();}
1079 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1080 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1081 void iadd(const cytnx_double &c){this->_elem += c;}
1082 void iadd(const cytnx_float &c){this->_elem += c;}
1083 void iadd(const cytnx_uint64 &c){this->_elem += c;}
1084 void iadd(const cytnx_int64 &c){this->_elem += c;}
1085 void iadd(const cytnx_uint32 &c){this->_elem += c;}
1086 void iadd(const cytnx_int32 &c){this->_elem += c;}
1087 void iadd(const cytnx_uint16 &c){this->_elem += c;}
1088 void iadd(const cytnx_int16 &c){this->_elem += c;}
1089 void iadd(const cytnx_bool &c){this->_elem += c;}
1090
1091 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_int32();}
1092 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1093 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1094 void isub(const cytnx_double &c){this->_elem -= c;}
1095 void isub(const cytnx_float &c){this->_elem -= c;}
1096 void isub(const cytnx_uint64 &c){this->_elem -= c;}
1097 void isub(const cytnx_int64 &c){this->_elem -= c;}
1098 void isub(const cytnx_uint32 &c){this->_elem -= c;}
1099 void isub(const cytnx_int32 &c){this->_elem -= c;}
1100 void isub(const cytnx_uint16 &c){this->_elem -= c;}
1101 void isub(const cytnx_int16 &c){this->_elem -= c;}
1102 void isub(const cytnx_bool &c){this->_elem -= c;}
1103
1104 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_int32();}
1105 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1106 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1107 void imul(const cytnx_double &c){this->_elem *= c;}
1108 void imul(const cytnx_float &c){this->_elem *= c;}
1109 void imul(const cytnx_uint64 &c){this->_elem *= c;}
1110 void imul(const cytnx_int64 &c){this->_elem *= c;}
1111 void imul(const cytnx_uint32 &c){this->_elem *= c;}
1112 void imul(const cytnx_int32 &c){this->_elem *= c;}
1113 void imul(const cytnx_uint16 &c){this->_elem *= c;}
1114 void imul(const cytnx_int16 &c){this->_elem *= c;}
1115 void imul(const cytnx_bool &c){this->_elem *= c;}
1116
1117 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_int32();}
1118 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1119 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1120 void idiv(const cytnx_double &c){this->_elem /= c;}
1121 void idiv(const cytnx_float &c){this->_elem /= c;}
1122 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
1123 void idiv(const cytnx_int64 &c){this->_elem /= c;}
1124 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
1125 void idiv(const cytnx_int32 &c){this->_elem /= c;}
1126 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
1127 void idiv(const cytnx_int16 &c){this->_elem /= c;}
1128 void idiv(const cytnx_bool &c){this->_elem /= c;}
1129
1130 void iabs(){this->_elem=std::abs(this->_elem);}
1131 void isqrt(){this->_elem=std::sqrt(this->_elem);}
1132
1133 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_int32();}
1134 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1135 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1136 bool less(const cytnx_double &c){return this->_elem < c;}
1137 bool less(const cytnx_float &c){return this->_elem < c;}
1138 bool less(const cytnx_uint64 &c){return this->_elem < c;}
1139 bool less(const cytnx_int64 &c){return this->_elem < c;}
1140 bool less(const cytnx_uint32 &c){return this->_elem < c;}
1141 bool less(const cytnx_int32 &c){return this->_elem < c;}
1142 bool less(const cytnx_uint16 &c){return this->_elem < c;}
1143 bool less(const cytnx_int16 &c){return this->_elem < c;}
1144 bool less(const cytnx_bool &c){return this->_elem < c;}
1145
1146
1147 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_int32();}
1148 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1149 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1150 bool greater(const cytnx_double &c){return this->_elem > c;}
1151 bool greater(const cytnx_float &c){return this->_elem > c;}
1152 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
1153 bool greater(const cytnx_int64 &c){return this->_elem > c;}
1154 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
1155 bool greater(const cytnx_int32 &c){return this->_elem > c;}
1156 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
1157 bool greater(const cytnx_int16 &c){return this->_elem > c;}
1158 bool greater(const cytnx_bool &c){return this->_elem > c;}
1159
1160 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_int32();}
1161
1162 void conj_(){return;}
1163 Scalar_base* get_real(){return this->copy();}
1164 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
1165
1166 void set_maxval(){this->_elem = std::numeric_limits<cytnx_int32>::max();}
1167 void set_minval(){this->_elem = std::numeric_limits<cytnx_int32>::min();}
1168
1169 void* get_raw_address() const{return (void*)(&this->_elem);}
1170
1171 Scalar_base* astype(const unsigned int &dtype){
1172 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1173 tmp->assign_selftype(this->_elem);
1174 return tmp;
1175 }
1176 Scalar_base* copy() const{
1177 Int32Scalar *tmp = new Int32Scalar(this->_elem);
1178 return tmp;
1179 };
1180 void print(std::ostream& os) const{
1181 os << "< " << this->_elem << " >";
1182 };
1183 };
1184 class Uint32Scalar: public Scalar_base{
1185
1186 public:
1187 cytnx_uint32 _elem;
1188
1189 Uint32Scalar(): _elem(0){this->_dtype = Type.Uint32;};
1190 Uint32Scalar(const cytnx_uint32 &in): _elem(0){
1191 this->_dtype = Type.Uint32;
1192 this->_elem = in;
1193 }
1194
1195 cytnx_float to_cytnx_float() const{return this->_elem;};
1196 cytnx_double to_cytnx_double() const{return this->_elem;};
1197 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
1198 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
1199 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
1200 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
1201 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
1202 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
1203 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
1204 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
1205 cytnx_bool to_cytnx_bool() const{return this->_elem;};
1206
1207 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1208 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1209 void assign_selftype(const cytnx_double &c){this->_elem = c;}
1210 void assign_selftype(const cytnx_float &c){this->_elem = c;}
1211 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
1212 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
1213 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
1214 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
1215 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
1216 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
1217 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
1218
1219 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_uint32();}
1220 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1221 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1222 void iadd(const cytnx_double &c){this->_elem += c;}
1223 void iadd(const cytnx_float &c){this->_elem += c;}
1224 void iadd(const cytnx_uint64 &c){this->_elem += c;}
1225 void iadd(const cytnx_int64 &c){this->_elem += c;}
1226 void iadd(const cytnx_uint32 &c){this->_elem += c;}
1227 void iadd(const cytnx_int32 &c){this->_elem += c;}
1228 void iadd(const cytnx_uint16 &c){this->_elem += c;}
1229 void iadd(const cytnx_int16 &c){this->_elem += c;}
1230 void iadd(const cytnx_bool &c){this->_elem += c;}
1231
1232 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_uint32();}
1233 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1234 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1235 void isub(const cytnx_double &c){this->_elem -= c;}
1236 void isub(const cytnx_float &c){this->_elem -= c;}
1237 void isub(const cytnx_uint64 &c){this->_elem -= c;}
1238 void isub(const cytnx_int64 &c){this->_elem -= c;}
1239 void isub(const cytnx_uint32 &c){this->_elem -= c;}
1240 void isub(const cytnx_int32 &c){this->_elem -= c;}
1241 void isub(const cytnx_uint16 &c){this->_elem -= c;}
1242 void isub(const cytnx_int16 &c){this->_elem -= c;}
1243 void isub(const cytnx_bool &c){this->_elem -= c;}
1244
1245 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_uint32();}
1246 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1247 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1248 void imul(const cytnx_double &c){this->_elem *= c;}
1249 void imul(const cytnx_float &c){this->_elem *= c;}
1250 void imul(const cytnx_uint64 &c){this->_elem *= c;}
1251 void imul(const cytnx_int64 &c){this->_elem *= c;}
1252 void imul(const cytnx_uint32 &c){this->_elem *= c;}
1253 void imul(const cytnx_int32 &c){this->_elem *= c;}
1254 void imul(const cytnx_uint16 &c){this->_elem *= c;}
1255 void imul(const cytnx_int16 &c){this->_elem *= c;}
1256 void imul(const cytnx_bool &c){this->_elem *= c;}
1257
1258 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_uint32();}
1259 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1260 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1261 void idiv(const cytnx_double &c){this->_elem /= c;}
1262 void idiv(const cytnx_float &c){this->_elem /= c;}
1263 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
1264 void idiv(const cytnx_int64 &c){this->_elem /= c;}
1265 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
1266 void idiv(const cytnx_int32 &c){this->_elem /= c;}
1267 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
1268 void idiv(const cytnx_int16 &c){this->_elem /= c;}
1269 void idiv(const cytnx_bool &c){this->_elem /= c;}
1270
1271 void iabs(){this->_elem=std::abs(cytnx_double(this->_elem));}
1272 void isqrt(){this->_elem=std::sqrt(this->_elem);}
1273
1274 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_uint32();}
1275 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1276 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1277 bool less(const cytnx_double &c){return this->_elem < c;}
1278 bool less(const cytnx_float &c){return this->_elem < c;}
1279 bool less(const cytnx_uint64 &c){return this->_elem < c;}
1280 bool less(const cytnx_int64 &c){return this->_elem < c;}
1281 bool less(const cytnx_uint32 &c){return this->_elem < c;}
1282 bool less(const cytnx_int32 &c){return this->_elem < c;}
1283 bool less(const cytnx_uint16 &c){return this->_elem < c;}
1284 bool less(const cytnx_int16 &c){return this->_elem < c;}
1285 bool less(const cytnx_bool &c){return this->_elem < c;}
1286
1287 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_uint32();}
1288 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1289 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1290 bool greater(const cytnx_double &c){return this->_elem > c;}
1291 bool greater(const cytnx_float &c){return this->_elem > c;}
1292 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
1293 bool greater(const cytnx_int64 &c){return this->_elem > c;}
1294 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
1295 bool greater(const cytnx_int32 &c){return this->_elem > c;}
1296 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
1297 bool greater(const cytnx_int16 &c){return this->_elem > c;}
1298 bool greater(const cytnx_bool &c){return this->_elem > c;}
1299
1300 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_uint32();}
1301
1302 void conj_(){return;}
1303 Scalar_base* get_real(){return this->copy();}
1304 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
1305
1306 void set_maxval(){this->_elem = std::numeric_limits<cytnx_uint32>::max();}
1307 void set_minval(){this->_elem = std::numeric_limits<cytnx_uint32>::min();}
1308
1309
1310 void* get_raw_address() const{return (void*)(&this->_elem);}
1311 Scalar_base* astype(const unsigned int &dtype){
1312 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1313 tmp->assign_selftype(this->_elem);
1314 return tmp;
1315 }
1316 Scalar_base* copy() const{
1317 Uint32Scalar *tmp = new Uint32Scalar(this->_elem);
1318 return tmp;
1319 };
1320 void print(std::ostream& os) const{
1321 os << "< " << this->_elem << " >";
1322 };
1323 };
1324 class Int16Scalar: public Scalar_base{
1325
1326 public:
1327 cytnx_int16 _elem;
1328
1329 Int16Scalar(): _elem(0){this->_dtype = Type.Int16;};
1330 Int16Scalar(const cytnx_int16 &in): _elem(0){
1331 this->_dtype = Type.Int16;
1332 this->_elem = in;
1333 }
1334
1335 cytnx_float to_cytnx_float() const{return this->_elem;};
1336 cytnx_double to_cytnx_double() const{return this->_elem;};
1337 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
1338 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
1339 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
1340 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
1341 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
1342 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
1343 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
1344 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
1345 cytnx_bool to_cytnx_bool() const{return this->_elem;};
1346
1347 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1348 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1349 void assign_selftype(const cytnx_double &c){this->_elem = c;}
1350 void assign_selftype(const cytnx_float &c){this->_elem = c;}
1351 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
1352 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
1353 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
1354 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
1355 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
1356 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
1357 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
1358
1359
1360 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_int16();}
1361 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1362 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1363 void iadd(const cytnx_double &c){this->_elem += c;}
1364 void iadd(const cytnx_float &c){this->_elem += c;}
1365 void iadd(const cytnx_uint64 &c){this->_elem += c;}
1366 void iadd(const cytnx_int64 &c){this->_elem += c;}
1367 void iadd(const cytnx_uint32 &c){this->_elem += c;}
1368 void iadd(const cytnx_int32 &c){this->_elem += c;}
1369 void iadd(const cytnx_uint16 &c){this->_elem += c;}
1370 void iadd(const cytnx_int16 &c){this->_elem += c;}
1371 void iadd(const cytnx_bool &c){this->_elem += c;}
1372
1373 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_int16();}
1374 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1375 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1376 void isub(const cytnx_double &c){this->_elem -= c;}
1377 void isub(const cytnx_float &c){this->_elem -= c;}
1378 void isub(const cytnx_uint64 &c){this->_elem -= c;}
1379 void isub(const cytnx_int64 &c){this->_elem -= c;}
1380 void isub(const cytnx_uint32 &c){this->_elem -= c;}
1381 void isub(const cytnx_int32 &c){this->_elem -= c;}
1382 void isub(const cytnx_uint16 &c){this->_elem -= c;}
1383 void isub(const cytnx_int16 &c){this->_elem -= c;}
1384 void isub(const cytnx_bool &c){this->_elem -= c;}
1385
1386 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_int16();}
1387 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1388 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1389 void imul(const cytnx_double &c){this->_elem *= c;}
1390 void imul(const cytnx_float &c){this->_elem *= c;}
1391 void imul(const cytnx_uint64 &c){this->_elem *= c;}
1392 void imul(const cytnx_int64 &c){this->_elem *= c;}
1393 void imul(const cytnx_uint32 &c){this->_elem *= c;}
1394 void imul(const cytnx_int32 &c){this->_elem *= c;}
1395 void imul(const cytnx_uint16 &c){this->_elem *= c;}
1396 void imul(const cytnx_int16 &c){this->_elem *= c;}
1397 void imul(const cytnx_bool &c){this->_elem *= c;}
1398
1399 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_int16();}
1400 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1401 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1402 void idiv(const cytnx_double &c){this->_elem /= c;}
1403 void idiv(const cytnx_float &c){this->_elem /= c;}
1404 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
1405 void idiv(const cytnx_int64 &c){this->_elem /= c;}
1406 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
1407 void idiv(const cytnx_int32 &c){this->_elem /= c;}
1408 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
1409 void idiv(const cytnx_int16 &c){this->_elem /= c;}
1410 void idiv(const cytnx_bool &c){this->_elem /= c;}
1411
1412 void iabs(){this->_elem=std::abs(this->_elem);}
1413 void isqrt(){this->_elem=std::sqrt(this->_elem);}
1414
1415 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_int16();}
1416 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1417 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1418 bool less(const cytnx_double &c){return this->_elem < c;}
1419 bool less(const cytnx_float &c){return this->_elem < c;}
1420 bool less(const cytnx_uint64 &c){return this->_elem < c;}
1421 bool less(const cytnx_int64 &c){return this->_elem < c;}
1422 bool less(const cytnx_uint32 &c){return this->_elem < c;}
1423 bool less(const cytnx_int32 &c){return this->_elem < c;}
1424 bool less(const cytnx_uint16 &c){return this->_elem < c;}
1425 bool less(const cytnx_int16 &c){return this->_elem < c;}
1426 bool less(const cytnx_bool &c){return this->_elem < c;}
1427
1428 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_int16();}
1429 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1430 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1431 bool greater(const cytnx_double &c){return this->_elem > c;}
1432 bool greater(const cytnx_float &c){return this->_elem > c;}
1433 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
1434 bool greater(const cytnx_int64 &c){return this->_elem > c;}
1435 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
1436 bool greater(const cytnx_int32 &c){return this->_elem > c;}
1437 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
1438 bool greater(const cytnx_int16 &c){return this->_elem > c;}
1439 bool greater(const cytnx_bool &c){return this->_elem > c;}
1440
1441 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_int16();}
1442
1443 void conj_(){return;}
1444 Scalar_base* get_real(){return this->copy();}
1445 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
1446
1447 void set_maxval(){this->_elem = std::numeric_limits<cytnx_int16>::max();}
1448 void set_minval(){this->_elem = std::numeric_limits<cytnx_int16>::min();}
1449
1450 void* get_raw_address() const{return (void*)(&this->_elem);}
1451 Scalar_base* astype(const unsigned int &dtype){
1452 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1453 tmp->assign_selftype(this->_elem);
1454 return tmp;
1455 }
1456 Scalar_base* copy() const{
1457 Int16Scalar *tmp = new Int16Scalar(this->_elem);
1458 return tmp;
1459 };
1460 void print(std::ostream& os) const{
1461 os << "< " << this->_elem << " >";
1462 };
1463 };
1464 class Uint16Scalar: public Scalar_base{
1465
1466 public:
1467 cytnx_uint16 _elem;
1468
1469 Uint16Scalar(): _elem(0){this->_dtype = Type.Uint16;};
1470 Uint16Scalar(const cytnx_uint16 &in): _elem(0){
1471 this->_dtype = Type.Uint16;
1472 this->_elem = in;
1473 }
1474
1475 cytnx_float to_cytnx_float() const{return this->_elem;};
1476 cytnx_double to_cytnx_double() const{return this->_elem;};
1477 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
1478 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
1479 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
1480 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
1481 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
1482 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
1483 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
1484 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
1485 cytnx_bool to_cytnx_bool() const{return this->_elem;};
1486
1487 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1488 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1489 void assign_selftype(const cytnx_double &c){this->_elem = c;}
1490 void assign_selftype(const cytnx_float &c){this->_elem = c;}
1491 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
1492 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
1493 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
1494 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
1495 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
1496 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
1497 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
1498
1499 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_uint16();}
1500 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1501 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1502 void iadd(const cytnx_double &c){this->_elem += c;}
1503 void iadd(const cytnx_float &c){this->_elem += c;}
1504 void iadd(const cytnx_uint64 &c){this->_elem += c;}
1505 void iadd(const cytnx_int64 &c){this->_elem += c;}
1506 void iadd(const cytnx_uint32 &c){this->_elem += c;}
1507 void iadd(const cytnx_int32 &c){this->_elem += c;}
1508 void iadd(const cytnx_uint16 &c){this->_elem += c;}
1509 void iadd(const cytnx_int16 &c){this->_elem += c;}
1510 void iadd(const cytnx_bool &c){this->_elem += c;}
1511
1512 void isub(const Scalar_base* c){this->_elem += c->to_cytnx_uint16();}
1513 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1514 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1515 void isub(const cytnx_double &c){this->_elem += c;}
1516 void isub(const cytnx_float &c){this->_elem += c;}
1517 void isub(const cytnx_uint64 &c){this->_elem += c;}
1518 void isub(const cytnx_int64 &c){this->_elem += c;}
1519 void isub(const cytnx_uint32 &c){this->_elem += c;}
1520 void isub(const cytnx_int32 &c){this->_elem += c;}
1521 void isub(const cytnx_uint16 &c){this->_elem += c;}
1522 void isub(const cytnx_int16 &c){this->_elem += c;}
1523 void isub(const cytnx_bool &c){this->_elem += c;}
1524
1525 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_uint16();}
1526 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1527 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1528 void imul(const cytnx_double &c){this->_elem *= c;}
1529 void imul(const cytnx_float &c){this->_elem *= c;}
1530 void imul(const cytnx_uint64 &c){this->_elem *= c;}
1531 void imul(const cytnx_int64 &c){this->_elem *= c;}
1532 void imul(const cytnx_uint32 &c){this->_elem *= c;}
1533 void imul(const cytnx_int32 &c){this->_elem *= c;}
1534 void imul(const cytnx_uint16 &c){this->_elem *= c;}
1535 void imul(const cytnx_int16 &c){this->_elem *= c;}
1536 void imul(const cytnx_bool &c){this->_elem *= c;}
1537
1538
1539 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_uint16();}
1540 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1541 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1542 void idiv(const cytnx_double &c){this->_elem /= c;}
1543 void idiv(const cytnx_float &c){this->_elem /= c;}
1544 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
1545 void idiv(const cytnx_int64 &c){this->_elem /= c;}
1546 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
1547 void idiv(const cytnx_int32 &c){this->_elem /= c;}
1548 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
1549 void idiv(const cytnx_int16 &c){this->_elem /= c;}
1550 void idiv(const cytnx_bool &c){this->_elem /= c;}
1551
1552 void iabs(){this->_elem=std::abs(this->_elem);}
1553 void isqrt(){this->_elem=std::sqrt(this->_elem);}
1554
1555 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_uint16();}
1556 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1557 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1558 bool less(const cytnx_double &c){return this->_elem < c;}
1559 bool less(const cytnx_float &c){return this->_elem < c;}
1560 bool less(const cytnx_uint64 &c){return this->_elem < c;}
1561 bool less(const cytnx_int64 &c){return this->_elem < c;}
1562 bool less(const cytnx_uint32 &c){return this->_elem < c;}
1563 bool less(const cytnx_int32 &c){return this->_elem < c;}
1564 bool less(const cytnx_uint16 &c){return this->_elem < c;}
1565 bool less(const cytnx_int16 &c){return this->_elem < c;}
1566 bool less(const cytnx_bool &c){return this->_elem < c;}
1567
1568 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_uint16();}
1569 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1570 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1571 bool greater(const cytnx_double &c){return this->_elem > c;}
1572 bool greater(const cytnx_float &c){return this->_elem > c;}
1573 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
1574 bool greater(const cytnx_int64 &c){return this->_elem > c;}
1575 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
1576 bool greater(const cytnx_int32 &c){return this->_elem > c;}
1577 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
1578 bool greater(const cytnx_int16 &c){return this->_elem > c;}
1579 bool greater(const cytnx_bool &c){return this->_elem > c;}
1580
1581 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_uint16();}
1582
1583 void conj_(){return;}
1584 Scalar_base* get_real(){return this->copy();}
1585 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
1586
1587 void set_maxval(){this->_elem = std::numeric_limits<cytnx_uint16>::max();}
1588 void set_minval(){this->_elem = std::numeric_limits<cytnx_uint16>::min();}
1589
1590 void* get_raw_address() const{return (void*)(&this->_elem);}
1591 Scalar_base* astype(const unsigned int &dtype){
1592 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1593 tmp->assign_selftype(this->_elem);
1594 return tmp;
1595 }
1596 Scalar_base* copy() const{
1597 Uint16Scalar *tmp = new Uint16Scalar(this->_elem);
1598 return tmp;
1599 };
1600 void print(std::ostream& os) const{
1601 os << "< " << this->_elem << " >";
1602 };
1603 };
1604 class BoolScalar: public Scalar_base{
1605
1606 public:
1607 cytnx_bool _elem;
1608
1609 BoolScalar(): _elem(0){this->_dtype = Type.Bool;};
1610 BoolScalar(const cytnx_bool &in): _elem(0){
1611 this->_dtype = Type.Bool;
1612 this->_elem = in;
1613 }
1614
1615 cytnx_float to_cytnx_float() const{return this->_elem;};
1616 cytnx_double to_cytnx_double() const{return this->_elem;};
1617 cytnx_complex64 to_cytnx_complex64() const{return this->_elem;};
1618 cytnx_complex128 to_cytnx_complex128() const{return this->_elem;};
1619 cytnx_int64 to_cytnx_int64() const{return this->_elem;};
1620 cytnx_uint64 to_cytnx_uint64() const{return this->_elem;};
1621 cytnx_int32 to_cytnx_int32() const{return this->_elem;};
1622 cytnx_uint32 to_cytnx_uint32() const{return this->_elem;};
1623 cytnx_int16 to_cytnx_int16() const{return this->_elem;};
1624 cytnx_uint16 to_cytnx_uint16() const{return this->_elem;};
1625 cytnx_bool to_cytnx_bool() const{return this->_elem;};
1626
1627 void assign_selftype(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1628 void assign_selftype(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot convert complex to real%s","\n");}
1629 void assign_selftype(const cytnx_double &c){this->_elem = c;}
1630 void assign_selftype(const cytnx_float &c){this->_elem = c;}
1631 void assign_selftype(const cytnx_uint64 &c){this->_elem = c;}
1632 void assign_selftype(const cytnx_int64 &c){this->_elem = c;}
1633 void assign_selftype(const cytnx_uint32 &c){this->_elem = c;}
1634 void assign_selftype(const cytnx_int32 &c){this->_elem = c;}
1635 void assign_selftype(const cytnx_uint16 &c){this->_elem = c;}
1636 void assign_selftype(const cytnx_int16 &c){this->_elem = c;}
1637 void assign_selftype(const cytnx_bool &c){this->_elem = c;}
1638
1639 void iadd(const Scalar_base* c){this->_elem += c->to_cytnx_bool();}
1640 void iadd(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1641 void iadd(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1642 void iadd(const cytnx_double &c){this->_elem += c;}
1643 void iadd(const cytnx_float &c){this->_elem += c;}
1644 void iadd(const cytnx_uint64 &c){this->_elem += c;}
1645 void iadd(const cytnx_int64 &c){this->_elem += c;}
1646 void iadd(const cytnx_uint32 &c){this->_elem += c;}
1647 void iadd(const cytnx_int32 &c){this->_elem += c;}
1648 void iadd(const cytnx_uint16 &c){this->_elem += c;}
1649 void iadd(const cytnx_int16 &c){this->_elem += c;}
1650 void iadd(const cytnx_bool &c){this->_elem += c;}
1651
1652 void isub(const Scalar_base* c){this->_elem -= c->to_cytnx_bool();}
1653 void isub(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1654 void isub(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1655 void isub(const cytnx_double &c){this->_elem -= c;}
1656 void isub(const cytnx_float &c){this->_elem -= c;}
1657 void isub(const cytnx_uint64 &c){this->_elem -= c;}
1658 void isub(const cytnx_int64 &c){this->_elem -= c;}
1659 void isub(const cytnx_uint32 &c){this->_elem -= c;}
1660 void isub(const cytnx_int32 &c){this->_elem -= c;}
1661 void isub(const cytnx_uint16 &c){this->_elem -= c;}
1662 void isub(const cytnx_int16 &c){this->_elem -= c;}
1663 void isub(const cytnx_bool &c){this->_elem -= c;}
1664
1665 void imul(const Scalar_base* c){this->_elem *= c->to_cytnx_bool();}
1666 void imul(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1667 void imul(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1668 void imul(const cytnx_double &c){this->_elem *= c;}
1669 void imul(const cytnx_float &c){this->_elem *= c;}
1670 void imul(const cytnx_uint64 &c){this->_elem *= c;}
1671 void imul(const cytnx_int64 &c){this->_elem *= c;}
1672 void imul(const cytnx_uint32 &c){this->_elem *= c;}
1673 void imul(const cytnx_int32 &c){this->_elem *= c;}
1674 void imul(const cytnx_uint16 &c){this->_elem *= c;}
1675 void imul(const cytnx_int16 &c){this->_elem *= c;}
1676 void imul(const cytnx_bool &c){this->_elem *= c;}
1677
1678
1679 void idiv(const Scalar_base* c){this->_elem /= c->to_cytnx_bool();}
1680 void idiv(const cytnx_complex128 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1681 void idiv(const cytnx_complex64 &c){cytnx_error_msg(true,"[ERROR] cannot operate real and complex values%s","\n");}
1682 void idiv(const cytnx_double &c){this->_elem /= c;}
1683 void idiv(const cytnx_float &c){this->_elem /= c;}
1684 void idiv(const cytnx_uint64 &c){this->_elem /= c;}
1685 void idiv(const cytnx_int64 &c){this->_elem /= c;}
1686 void idiv(const cytnx_uint32 &c){this->_elem /= c;}
1687 void idiv(const cytnx_int32 &c){this->_elem /= c;}
1688 void idiv(const cytnx_uint16 &c){this->_elem /= c;}
1689 void idiv(const cytnx_int16 &c){this->_elem /= c;}
1690 void idiv(const cytnx_bool &c){this->_elem /= c;}
1691
1692 void iabs(){this->_elem=std::abs(this->_elem);}
1693 void isqrt(){this->_elem=std::sqrt(this->_elem);}
1694
1695 bool less(const Scalar_base* c){return this->_elem < c->to_cytnx_bool();}
1696 bool less(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1697 bool less(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1698 bool less(const cytnx_double &c){return this->_elem < c;}
1699 bool less(const cytnx_float &c){return this->_elem < c;}
1700 bool less(const cytnx_uint64 &c){return this->_elem < c;}
1701 bool less(const cytnx_int64 &c){return this->_elem < c;}
1702 bool less(const cytnx_uint32 &c){return this->_elem < c;}
1703 bool less(const cytnx_int32 &c){return this->_elem < c;}
1704 bool less(const cytnx_uint16 &c){return this->_elem < c;}
1705 bool less(const cytnx_int16 &c){return this->_elem < c;}
1706 bool less(const cytnx_bool &c){return this->_elem < c;}
1707
1708 bool greater(const Scalar_base* c){return this->_elem > c->to_cytnx_bool();}
1709 bool greater(const cytnx_complex128 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1710 bool greater(const cytnx_complex64 &c){cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s","\n"); return 0;}
1711 bool greater(const cytnx_double &c){return this->_elem > c;}
1712 bool greater(const cytnx_float &c){return this->_elem > c;}
1713 bool greater(const cytnx_uint64 &c){return this->_elem > c;}
1714 bool greater(const cytnx_int64 &c){return this->_elem > c;}
1715 bool greater(const cytnx_uint32 &c){return this->_elem > c;}
1716 bool greater(const cytnx_int32 &c){return this->_elem > c;}
1717 bool greater(const cytnx_uint16 &c){return this->_elem > c;}
1718 bool greater(const cytnx_int16 &c){return this->_elem > c;}
1719 bool greater(const cytnx_bool &c){return this->_elem > c;}
1720
1721
1722 bool eq(const Scalar_base* c){return this->_elem == c->to_cytnx_bool();}
1723
1724 void conj_(){return;}
1725 Scalar_base* get_real(){return this->copy();}
1726 Scalar_base* get_imag(){cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s","\n"); return nullptr;}
1727
1728 void set_maxval(){this->_elem = true;}
1729 void set_minval(){this->_elem = false;}
1730
1731
1732 void* get_raw_address() const{return (void*)(&this->_elem);}
1733 Scalar_base* astype(const unsigned int &dtype){
1734 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1735 tmp->assign_selftype(this->_elem);
1736 return tmp;
1737 }
1738 Scalar_base* copy() const{
1739 BoolScalar *tmp = new BoolScalar(this->_elem);
1740 return tmp;
1741 };
1742 void print(std::ostream& os) const{
1743 os << "< " << this->_elem << " >";
1744 };
1745 };
1746
1748
1749
1750
1751 class Scalar{
1752 public:
1753
1755 struct Sproxy{
1756 boost::intrusive_ptr<Storage_base> _insimpl;
1757 cytnx_uint64 _loc;
1758
1759 Sproxy(boost::intrusive_ptr<Storage_base> _ptr,const cytnx_uint64 &idx) : _insimpl(_ptr), _loc(idx){}
1760
1761 //When used to set elems:
1762 const Sproxy& operator=(const Scalar &rc);
1763 const Sproxy& operator=(const cytnx_complex128 &rc);
1764 const Sproxy& operator=(const cytnx_complex64 &rc);
1765 const Sproxy& operator=(const cytnx_double &rc);
1766 const Sproxy& operator=(const cytnx_float &rc);
1767 const Sproxy& operator=(const cytnx_uint64 &rc);
1768 const Sproxy& operator=(const cytnx_int64 &rc);
1769 const Sproxy& operator=(const cytnx_uint32 &rc);
1770 const Sproxy& operator=(const cytnx_int32 &rc);
1771 const Sproxy& operator=(const cytnx_uint16 &rc);
1772 const Sproxy& operator=(const cytnx_int16 &rc);
1773 const Sproxy& operator=(const cytnx_bool &rc);
1774
1775 const Sproxy& operator=(const Sproxy &rc);
1776
1777 Scalar real();
1778 Scalar imag();
1779 //When used to get elements:
1780 //operator Scalar() const;
1781
1782 };
1783
1785
1786 Scalar_base* _impl;
1787
1788 Scalar(): _impl(new Scalar_base()){};
1789
1790 // init!!
1791 Scalar(const cytnx_complex128 &in): _impl(new Scalar_base()){
1792 this->Init_by_number(in);
1793 }
1794 Scalar(const cytnx_complex64 &in): _impl(new Scalar_base()){
1795 this->Init_by_number(in);
1796 }
1797 Scalar(const cytnx_double &in): _impl(new Scalar_base()){
1798 this->Init_by_number(in);
1799 }
1800 Scalar(const cytnx_float &in): _impl(new Scalar_base()){
1801 this->Init_by_number(in);
1802 }
1803 Scalar(const cytnx_uint64 &in): _impl(new Scalar_base()){
1804 this->Init_by_number(in);
1805 }
1806 Scalar(const cytnx_int64 &in): _impl(new Scalar_base()){
1807 this->Init_by_number(in);
1808 }
1809 Scalar(const cytnx_uint32 &in): _impl(new Scalar_base()){
1810 this->Init_by_number(in);
1811 }
1812 Scalar(const cytnx_int32 &in): _impl(new Scalar_base()){
1813 this->Init_by_number(in);
1814 }
1815 Scalar(const cytnx_uint16 &in): _impl(new Scalar_base()){
1816 this->Init_by_number(in);
1817 }
1818 Scalar(const cytnx_int16 &in): _impl(new Scalar_base()){
1819 this->Init_by_number(in);
1820 }
1821 Scalar(const cytnx_bool &in): _impl(new Scalar_base()){
1822 this->Init_by_number(in);
1823 }
1824
1825
1826 static Scalar maxval(const unsigned int &dtype){
1827 Scalar out(0,dtype);
1828 out._impl->set_maxval();
1829 return out;
1830 }
1831 static Scalar minval(const unsigned int &dtype){
1832 Scalar out(0,dtype);
1833 out._impl->set_minval();
1834 return out;
1835 }
1836
1837
1838
1839 template<class T>
1840 Scalar(const T&in, const unsigned int &dtype): _impl(new Scalar_base()){
1841 if(this->_impl!=nullptr) delete this->_impl;
1842 this->_impl = __ScII.UScIInit[dtype]();
1843 this->_impl->assign_selftype(in);
1844 };
1845
1846 // move sproxy when use to get elements here.
1847 Scalar(const Sproxy &prox);
1848
1849
1850 //[Internal!!]
1851 Scalar(Scalar_base* in){
1852 this->_impl = in;
1853 }
1854
1855 //specialization of init:
1857 void Init_by_number(const cytnx_complex128 &in){
1858 if(this->_impl!=nullptr) delete this->_impl;
1859 this->_impl = new ComplexDoubleScalar(in);
1860 };
1861 void Init_by_number(const cytnx_complex64 &in){
1862 if(this->_impl!=nullptr) delete this->_impl;
1863 this->_impl = new ComplexFloatScalar(in);
1864 };
1865 void Init_by_number(const cytnx_double &in){
1866 if(this->_impl!=nullptr) delete this->_impl;
1867 this->_impl = new DoubleScalar(in);
1868 }
1869 void Init_by_number(const cytnx_float &in){
1870 if(this->_impl!=nullptr) delete this->_impl;
1871 this->_impl = new FloatScalar(in);
1872 }
1873 void Init_by_number(const cytnx_int64 &in){
1874 if(this->_impl!=nullptr) delete this->_impl;
1875 this->_impl = new Int64Scalar(in);
1876 }
1877 void Init_by_number(const cytnx_uint64 &in){
1878 if(this->_impl!=nullptr) delete this->_impl;
1879 this->_impl = new Uint64Scalar(in);
1880 }
1881 void Init_by_number(const cytnx_int32 &in){
1882 if(this->_impl!=nullptr) delete this->_impl;
1883 this->_impl = new Int32Scalar(in);
1884 }
1885 void Init_by_number(const cytnx_uint32 &in){
1886 if(this->_impl!=nullptr) delete this->_impl;
1887 this->_impl = new Uint32Scalar(in);
1888 }
1889 void Init_by_number(const cytnx_int16 &in){
1890 if(this->_impl!=nullptr) delete this->_impl;
1891 this->_impl = new Int16Scalar(in);
1892 }
1893 void Init_by_number(const cytnx_uint16 &in){
1894 if(this->_impl!=nullptr) delete this->_impl;
1895 this->_impl = new Uint16Scalar(in);
1896 }
1897 void Init_by_number(const cytnx_bool &in){
1898 if(this->_impl!=nullptr) delete this->_impl;
1899 this->_impl = new BoolScalar(in);
1900 }
1902
1903
1904 // copy constructor [Scalar]:
1905 Scalar(const Scalar &rhs): _impl(new Scalar_base()){
1906 if(this->_impl!=nullptr)
1907 delete this->_impl;
1908
1909 this->_impl = rhs._impl->copy();
1910 }
1911
1912 // copy assignment [Scalar]:
1914 if(this->_impl!=nullptr)
1915 delete this->_impl;
1916
1917 this->_impl = rhs._impl->copy();
1918 return *this;
1919 };
1920
1921 // copy assignment [Number]:
1922
1924 this->Init_by_number(rhs);
1925 return *this;
1926 }
1928 this->Init_by_number(rhs);
1929 return *this;
1930 }
1932 this->Init_by_number(rhs);
1933 return *this;
1934 }
1936 this->Init_by_number(rhs);
1937 return *this;
1938 }
1940 this->Init_by_number(rhs);
1941 return *this;
1942 }
1944 this->Init_by_number(rhs);
1945 return *this;
1946 }
1948 this->Init_by_number(rhs);
1949 return *this;
1950 }
1952 this->Init_by_number(rhs);
1953 return *this;
1954 }
1956 this->Init_by_number(rhs);
1957 return *this;
1958 }
1960 this->Init_by_number(rhs);
1961 return *this;
1962 }
1964 this->Init_by_number(rhs);
1965 return *this;
1966 }
1967
1968 // type conversion:
1969 Scalar astype(const unsigned int &dtype) const{
1970 Scalar out(this->_impl->astype(dtype));
1971 return out;
1972 }
1973
1974 Scalar conj() const{
1975 Scalar out = *this;
1976 out._impl->conj_();
1977 return out;
1978 }
1979
1980 Scalar imag() const{ return Scalar(this->_impl->get_imag());}
1981 Scalar real() const{ return Scalar(this->_impl->get_real());}
1982 //Scalar& set_imag(const Scalar &in){ return *this;}
1983 //Scalar& set_real(const Scalar &in){ return *this;}
1984
1985
1986
1987 int dtype() const{
1988 return this->_impl->_dtype;
1989 }
1990
1991 // print()
1992 void print() const{
1993 this->_impl->print(std::cout);
1994 std::cout << std::string(" Scalar dtype: [") << Type.getname(this->_impl->_dtype) << std::string("]") << std::endl;
1995 }
1996
1997 //casting
1998 explicit operator cytnx_double() const{
1999 return this->_impl->to_cytnx_double();
2000 }
2001 explicit operator cytnx_float() const{
2002 return this->_impl->to_cytnx_float();
2003 }
2004 explicit operator cytnx_uint64() const{
2005 return this->_impl->to_cytnx_uint64();
2006 }
2007 explicit operator cytnx_int64() const{
2008 return this->_impl->to_cytnx_int64();
2009 }
2010 explicit operator cytnx_uint32() const{
2011 return this->_impl->to_cytnx_uint32();
2012 }
2013 explicit operator cytnx_int32() const{
2014 return this->_impl->to_cytnx_int32();
2015 }
2016 explicit operator cytnx_uint16() const{
2017 return this->_impl->to_cytnx_uint16();
2018 }
2019 explicit operator cytnx_int16() const{
2020 return this->_impl->to_cytnx_int16();
2021 }
2022 explicit operator cytnx_bool() const{
2023 return this->_impl->to_cytnx_bool();
2024 }
2026 if(this->_impl!=nullptr)
2027 delete this->_impl;
2028 };
2029
2030 //arithmetic:
2031 template<class T>
2032 void operator+=(const T &rc){
2033 this->_impl->iadd(rc);
2034 }
2035 void operator+=(const Scalar &rhs){
2036 this->_impl->iadd(rhs._impl);
2037 }
2038 template<class T>
2039 void operator-=(const T &rc){
2040 this->_impl->isub(rc);
2041 }
2042 void operator-=(const Scalar &rhs){
2043 this->_impl->isub(rhs._impl);
2044 }
2045 template<class T>
2046 void operator*=(const T &rc){
2047 this->_impl->imul(rc);
2048 }
2049 void operator*=(const Scalar &rhs){
2050 this->_impl->imul(rhs._impl);
2051 }
2052 template<class T>
2053 void operator/=(const T &rc){
2054 this->_impl->idiv(rc);
2055 }
2056 void operator/=(const Scalar &rhs){
2057 this->_impl->idiv(rhs._impl);
2058 }
2059
2060
2061 void iabs(){
2062 this->_impl->iabs();
2063 }
2064
2065 void isqrt(){
2066 this->_impl->isqrt();
2067 }
2068
2069 Scalar abs() const{
2070 Scalar out = *this;
2071 out._impl->iabs();
2072 return out.real();
2073 }
2074
2075 Scalar sqrt() const{
2076 Scalar out = *this;
2077 out._impl->isqrt();
2078 return out;
2079 }
2080
2081
2082 //comparison <
2083 template<class T>
2084 bool less(const T &rc) const{
2085 Scalar tmp;
2086 int rid = Type.cy_typeid(rc);
2087 if( rid < this->dtype()){
2088 tmp = this->astype(rid);
2089 return tmp._impl->less(rc);
2090 }else{
2091 return this->_impl->less(rc);
2092 }
2093 }
2094 bool less(const Scalar &rhs) const{
2095 Scalar tmp;
2096 if(rhs.dtype() < this->dtype()){
2097 tmp = this->astype(rhs.dtype());
2098 return tmp._impl->less(rhs._impl);
2099 }else{
2100 return this->_impl->less(rhs._impl);
2101 }
2102 }
2103
2104 //comparison <=
2105 template<class T>
2106 bool leq(const T &rc) const{
2107 Scalar tmp;
2108 int rid = Type.cy_typeid(rc);
2109 if( rid < this->dtype()){
2110 tmp = this->astype(rid);
2111 return !(tmp._impl->greater(rc));
2112 }else{
2113 return !(this->_impl->greater(rc));
2114 }
2115 }
2116 bool leq(const Scalar &rhs) const{
2117 Scalar tmp;
2118 if(rhs.dtype() < this->dtype()){
2119 tmp = this->astype(rhs.dtype());
2120 return !(tmp._impl->greater(rhs._impl));
2121 }else{
2122 return !(this->_impl->greater(rhs._impl));
2123 }
2124 }
2125
2126
2127 //comparison >
2128 template<class T>
2129 bool greater(const T &rc) const{
2130 Scalar tmp;
2131 int rid = Type.cy_typeid(rc);
2132 if( rid < this->dtype()){
2133 tmp = this->astype(rid);
2134 return tmp._impl->greater(rc);
2135 }else{
2136 return this->_impl->greater(rc);
2137 }
2138 }
2139 bool greater(const Scalar &rhs) const{
2140 Scalar tmp;
2141 if(rhs.dtype() < this->dtype()){
2142 tmp = this->astype(rhs.dtype());
2143 return tmp._impl->greater(rhs._impl);
2144 }else{
2145 return this->_impl->greater(rhs._impl);
2146 }
2147 }
2148
2149 //comparison >=
2150 template<class T>
2151 bool geq(const T &rc) const{
2152 Scalar tmp;
2153 int rid = Type.cy_typeid(rc);
2154 if( rid < this->dtype()){
2155 tmp = this->astype(rid);
2156 return !(tmp._impl->less(rc));
2157 }else{
2158 return !(this->_impl->less(rc));
2159 }
2160 }
2161 bool geq(const Scalar &rhs) const{
2162 Scalar tmp;
2163 if(rhs.dtype() < this->dtype()){
2164 tmp = this->astype(rhs.dtype());
2165 return !(tmp._impl->less(rhs._impl));
2166 }else{
2167 return !(this->_impl->less(rhs._impl));
2168 }
2169 }
2170
2171 // radd: Scalar + c
2172 template<class T>
2173 Scalar radd(const T &rc) const{
2174 Scalar out;
2175 int rid = Type.cy_typeid(rc);
2176 if( this->dtype() < rid){
2177 out = *this;
2178 }else{
2179 out = this->astype(rid);
2180 }
2181 out._impl->iadd(rc);
2182 return out;
2183 }
2184 Scalar radd(const Scalar &rhs) const{
2185 Scalar out;
2186 if( this->dtype() < rhs.dtype() ){
2187 out = *this;
2188 }else{
2189 out = this->astype(rhs.dtype());
2190 }
2191 out._impl->iadd(rhs._impl);
2192 return out;
2193 }
2194
2195 // rmul: Scalar * c
2196 template<class T>
2197 Scalar rmul(const T &rc) const{
2198 Scalar out;
2199 int rid = Type.cy_typeid(rc);
2200 if( this->dtype() < rid){
2201 out = *this;
2202 }else{
2203 out = this->astype(rid);
2204 }
2205 out._impl->imul(rc);
2206 return out;
2207 }
2208 Scalar rmul(const Scalar &rhs) const{
2209 Scalar out;
2210 if( this->dtype() < rhs.dtype() ){
2211 out = *this;
2212 }else{
2213 out = this->astype(rhs.dtype());
2214 }
2215 out._impl->imul(rhs._impl);
2216 return out;
2217 }
2218
2219 // rsub: Scalar - c
2220 template<class T>
2221 Scalar rsub(const T &rc) const{
2222 Scalar out;
2223 int rid = Type.cy_typeid(rc);
2224 if( this->dtype() < rid){
2225 out = *this;
2226 }else{
2227 out = this->astype(rid);
2228 }
2229 out._impl->isub(rc);
2230 return out;
2231 }
2232 Scalar rsub(const Scalar &rhs) const{
2233 Scalar out;
2234 if( this->dtype() < rhs.dtype() ){
2235 out = *this;
2236 }else{
2237 out = this->astype(rhs.dtype());
2238 }
2239 out._impl->isub(rhs._impl);
2240 return out;
2241 }
2242
2243 // rdiv: Scalar / c
2244 template<class T>
2245 Scalar rdiv(const T &rc) const{
2246 Scalar out;
2247 int rid = Type.cy_typeid(rc);
2248 if( this->dtype() < rid){
2249 out = *this;
2250 }else{
2251 out = this->astype(rid);
2252 }
2253 out._impl->idiv(rc);
2254 return out;
2255 }
2256 Scalar rdiv(const Scalar &rhs) const{
2257 Scalar out;
2258 if( this->dtype() < rhs.dtype() ){
2259 out = *this;
2260 }else{
2261 out = this->astype(rhs.dtype());
2262 }
2263 out._impl->idiv(rhs._impl);
2264 return out;
2265 }
2266
2267
2268
2269
2270 /*
2271 //operator:
2272 template<class T>
2273 Scalar operator+(const T &rc){
2274 return this->radd(rc);
2275 }
2276 template<class T>
2277 Scalar operator*(const T &rc){
2278 return this->rmul(rc);
2279 }
2280 template<class T>
2281 Scalar operator-(const T &rc){
2282 return this->rsub(rc);
2283 }
2284 template<class T>
2285 Scalar operator/(const T &rc){
2286 return this->rdiv(rc);
2287 }
2288
2289 template<class T>
2290 bool operator<(const T &rc){
2291 return this->less(rc);
2292 }
2293
2294 template<class T>
2295 bool operator>(const T &rc){
2296 return this->greater(rc);
2297 }
2298
2299
2300 template<class T>
2301 bool operator<=(const T &rc){
2302 return this->leq(rc);
2303 }
2304
2305 template<class T>
2306 bool operator>=(const T &rc){
2307 return this->geq(rc);
2308 }
2309 */
2310 };
2311
2312
2313 //ladd: c + Scalar:
2314
2315
2316 Scalar operator+( const Scalar &lc, const Scalar &rs);//{return rs.radd(lc);};
2317
2318
2319 //lmul c * Scalar;
2320 Scalar operator*( const Scalar &lc, const Scalar &rs);//{return rs.rmul(lc);};
2321
2322 //lsub c * Scalar;
2323 Scalar operator-( const Scalar &lc, const Scalar &rs);//{return Scalar(lc).rsub(rs);};
2324
2325 //ldiv c / Scalar;
2326 Scalar operator/( const Scalar &lc, const Scalar &rs);//{return Scalar(lc).rdiv(rs);};
2327
2328
2329 // lless c < Scalar;
2330 bool operator<( const Scalar &lc, const Scalar &rs);
2331
2332
2333 // lgreater c > Scalar;
2334 bool operator>( const Scalar &lc, const Scalar &rs);
2335
2336
2337 // lless c <= Scalar;
2338 bool operator<=( const Scalar &lc, const Scalar &rs);
2339
2340 // lgreater c >= Scalar;
2341 bool operator>=( const Scalar &lc, const Scalar &rs);
2342
2343 // eq c == Scalar;
2344 bool operator==( const Scalar &lc, const Scalar &rs);
2345
2346 //abs:
2347
2348 Scalar abs(const Scalar &c);
2349 Scalar sqrt(const Scalar &c);
2350
2351
2352
2353 // complex conversion:
2354 cytnx_complex128 complex128(const Scalar &in);
2355 cytnx_complex64 complex64(const Scalar &in);
2356
2357 std::ostream& operator<<(std::ostream& os, const Scalar &in);
2358
2359}
2360
2361#endif
Definition Scalar.hpp:1751
void operator-=(const T &rc)
Definition Scalar.hpp:2039
Scalar & operator=(const Scalar &rhs)
Definition Scalar.hpp:1913
bool less(const Scalar &rhs) const
Definition Scalar.hpp:2094
Scalar_base * _impl
Definition Scalar.hpp:1786
bool leq(const T &rc) const
Definition Scalar.hpp:2106
Scalar(const cytnx_int64 &in)
Definition Scalar.hpp:1806
Scalar & operator=(const cytnx_bool &rhs)
Definition Scalar.hpp:1963
Scalar(const cytnx_double &in)
Definition Scalar.hpp:1797
Scalar(const T &in, const unsigned int &dtype)
Definition Scalar.hpp:1840
Scalar & operator=(const cytnx_float &rhs)
Definition Scalar.hpp:1935
~Scalar()
Definition Scalar.hpp:2025
Scalar(const cytnx_int16 &in)
Definition Scalar.hpp:1818
Scalar rmul(const T &rc) const
Definition Scalar.hpp:2197
static Scalar minval(const unsigned int &dtype)
Definition Scalar.hpp:1831
Scalar & operator=(const cytnx_uint16 &rhs)
Definition Scalar.hpp:1955
void operator+=(const T &rc)
Definition Scalar.hpp:2032
static Scalar maxval(const unsigned int &dtype)
Definition Scalar.hpp:1826
Scalar & operator=(const cytnx_int64 &rhs)
Definition Scalar.hpp:1943
Scalar()
Definition Scalar.hpp:1788
Scalar rsub(const T &rc) const
Definition Scalar.hpp:2221
Scalar(const cytnx_int32 &in)
Definition Scalar.hpp:1812
Scalar & operator=(const cytnx_int16 &rhs)
Definition Scalar.hpp:1959
Scalar(const cytnx_uint32 &in)
Definition Scalar.hpp:1809
bool less(const T &rc) const
Definition Scalar.hpp:2084
Scalar(const cytnx_uint16 &in)
Definition Scalar.hpp:1815
Scalar & operator=(const cytnx_uint64 &rhs)
Definition Scalar.hpp:1939
Scalar real() const
Definition Scalar.hpp:1981
int dtype() const
Definition Scalar.hpp:1987
void operator/=(const T &rc)
Definition Scalar.hpp:2053
Scalar(const cytnx_float &in)
Definition Scalar.hpp:1800
Scalar & operator=(const cytnx_double &rhs)
Definition Scalar.hpp:1931
Scalar sqrt() const
Definition Scalar.hpp:2075
Scalar(const cytnx_complex64 &in)
Definition Scalar.hpp:1794
void operator*=(const T &rc)
Definition Scalar.hpp:2046
bool geq(const Scalar &rhs) const
Definition Scalar.hpp:2161
Scalar & operator=(const cytnx_int32 &rhs)
Definition Scalar.hpp:1951
Scalar(Scalar_base *in)
Definition Scalar.hpp:1851
bool greater(const T &rc) const
Definition Scalar.hpp:2129
Scalar(const cytnx_uint64 &in)
Definition Scalar.hpp:1803
Scalar conj() const
Definition Scalar.hpp:1974
void operator-=(const Scalar &rhs)
Definition Scalar.hpp:2042
Scalar imag() const
Definition Scalar.hpp:1980
bool leq(const Scalar &rhs) const
Definition Scalar.hpp:2116
void iabs()
Definition Scalar.hpp:2061
Scalar abs() const
Definition Scalar.hpp:2069
Scalar rdiv(const T &rc) const
Definition Scalar.hpp:2245
void print() const
Definition Scalar.hpp:1992
bool greater(const Scalar &rhs) const
Definition Scalar.hpp:2139
bool geq(const T &rc) const
Definition Scalar.hpp:2151
void isqrt()
Definition Scalar.hpp:2065
Scalar rmul(const Scalar &rhs) const
Definition Scalar.hpp:2208
Scalar & operator=(const cytnx_uint32 &rhs)
Definition Scalar.hpp:1947
Scalar & operator=(const cytnx_complex128 &rhs)
Definition Scalar.hpp:1923
Scalar(const cytnx_bool &in)
Definition Scalar.hpp:1821
Scalar rdiv(const Scalar &rhs) const
Definition Scalar.hpp:2256
Scalar(const Scalar &rhs)
Definition Scalar.hpp:1905
void operator+=(const Scalar &rhs)
Definition Scalar.hpp:2035
void operator*=(const Scalar &rhs)
Definition Scalar.hpp:2049
void operator/=(const Scalar &rhs)
Definition Scalar.hpp:2056
Scalar(const cytnx_complex128 &in)
Definition Scalar.hpp:1791
Scalar & operator=(const cytnx_complex64 &rhs)
Definition Scalar.hpp:1927
Scalar rsub(const Scalar &rhs) const
Definition Scalar.hpp:2232
Scalar radd(const Scalar &rhs) const
Definition Scalar.hpp:2184
Scalar radd(const T &rc) const
Definition Scalar.hpp:2173
Scalar astype(const unsigned int &dtype) const
Definition Scalar.hpp:1969
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
Definition Accessor.hpp:12
cytnx_complex128 complex128(const Scalar &in)
Definition Scalar.cpp:6
cytnx::UniTensor operator*(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
bool operator<=(const Scalar &lc, const Scalar &rs)
Definition Scalar.cpp:43
double cytnx_double
Definition Type.hpp:20
uint32_t cytnx_uint32
Definition Type.hpp:23
bool cytnx_bool
Definition Type.hpp:31
std::complex< double > cytnx_complex128
Definition Type.hpp:30
float cytnx_float
Definition Type.hpp:21
std::ostream & operator<<(std::ostream &os, const Scalar &in)
Definition Scalar.cpp:14
int16_t cytnx_int16
Definition Type.hpp:27
Scalar abs(const Scalar &c)
Definition Scalar.cpp:60
std::complex< float > cytnx_complex64
Definition Type.hpp:29
cytnx::UniTensor operator-(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
int32_t cytnx_int32
Definition Type.hpp:26
Tensor operator==(const Tensor &Lt, const Tensor &Rt)
uint16_t cytnx_uint16
Definition Type.hpp:24
uint64_t cytnx_uint64
Definition Type.hpp:22
cytnx_complex64 complex64(const Scalar &in)
Definition Scalar.cpp:10
int64_t cytnx_int64
Definition Type.hpp:25
Type_class Type
Definition Type.cpp:143
Scalar sqrt(const Scalar &c)
Definition Scalar.cpp:62
cytnx::UniTensor operator+(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
bool operator>(const Scalar &lc, const Scalar &rs)
Definition Scalar.cpp:40
Scalar_init_interface __ScII
Definition Scalar.cpp:201
cytnx::UniTensor operator/(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
bool operator>=(const Scalar &lc, const Scalar &rs)
Definition Scalar.cpp:46
bool operator<(const Scalar &lc, const Scalar &rs)
Definition Scalar.cpp:36