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