Cytnx v0.9.1
Loading...
Searching...
No Matches
Scalar.hpp
Go to the documentation of this file.
1#ifndef _H_Scalar_
2#define _H_Scalar_
3
4#include "Type.hpp"
5#include "cytnx_error.hpp"
6//#include "lapack_wrapper.hpp"
8#include <vector>
9#include <initializer_list>
10#include <string>
11#include <iostream>
12#include <cmath>
13#include <type_traits>
14#include <limits>
15namespace cytnx {
16
18 class Storage_base;
19 class Tensor_base;
20
21 // real implementation
22 class Scalar_base {
23 private:
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 {
32 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
33 return 0;
34 };
35 virtual cytnx_double to_cytnx_double() const {
36 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
37 return 0;
38 };
39 virtual cytnx_complex64 to_cytnx_complex64() const {
40 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
41 return cytnx_complex64(0, 0);
42 };
43 virtual cytnx_complex128 to_cytnx_complex128() const {
44 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
45 return cytnx_complex128(0, 0);
46 };
47 virtual cytnx_int64 to_cytnx_int64() const {
48 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
49 return 0;
50 };
51 virtual cytnx_uint64 to_cytnx_uint64() const {
52 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
53 return 0;
54 };
55 virtual cytnx_int32 to_cytnx_int32() const {
56 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
57 return 0;
58 };
59 virtual cytnx_uint32 to_cytnx_uint32() const {
60 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
61 return 0;
62 };
63 virtual cytnx_int16 to_cytnx_int16() const {
64 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
65 return 0;
66 };
67 virtual cytnx_uint16 to_cytnx_uint16() const {
68 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
69 return 0;
70 };
71 virtual cytnx_bool to_cytnx_bool() const {
72 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot cast to anytype!!%s", "\n");
73 return 0;
74 }
75
76 virtual void iadd(const Scalar_base *c) {
77 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
78 }
79 virtual void iadd(const cytnx_complex128 &c) {
80 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
81 }
82 virtual void iadd(const cytnx_complex64 &c) {
83 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
84 }
85 virtual void iadd(const cytnx_double &c) {
86 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
87 }
88 virtual void iadd(const cytnx_float &c) {
89 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
90 }
91 virtual void iadd(const cytnx_uint64 &c) {
92 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
93 }
94 virtual void iadd(const cytnx_int64 &c) {
95 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
96 }
97 virtual void iadd(const cytnx_uint32 &c) {
98 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
99 }
100 virtual void iadd(const cytnx_int32 &c) {
101 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
102 }
103 virtual void iadd(const cytnx_uint16 &c) {
104 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
105 }
106 virtual void iadd(const cytnx_int16 &c) {
107 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
108 }
109 virtual void iadd(const cytnx_bool &c) {
110 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
111 }
112
113 virtual void isub(const Scalar_base *c) {
114 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
115 }
116 virtual void isub(const cytnx_complex128 &c) {
117 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
118 }
119 virtual void isub(const cytnx_complex64 &c) {
120 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
121 }
122 virtual void isub(const cytnx_double &c) {
123 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
124 }
125 virtual void isub(const cytnx_float &c) {
126 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
127 }
128 virtual void isub(const cytnx_uint64 &c) {
129 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
130 }
131 virtual void isub(const cytnx_int64 &c) {
132 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
133 }
134 virtual void isub(const cytnx_uint32 &c) {
135 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
136 }
137 virtual void isub(const cytnx_int32 &c) {
138 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
139 }
140 virtual void isub(const cytnx_uint16 &c) {
141 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
142 }
143 virtual void isub(const cytnx_int16 &c) {
144 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
145 }
146 virtual void isub(const cytnx_bool &c) {
147 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
148 }
149
150 virtual void imul(const Scalar_base *c) {
151 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
152 }
153 virtual void imul(const cytnx_complex128 &c) {
154 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
155 }
156 virtual void imul(const cytnx_complex64 &c) {
157 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
158 }
159 virtual void imul(const cytnx_double &c) {
160 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
161 }
162 virtual void imul(const cytnx_float &c) {
163 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
164 }
165 virtual void imul(const cytnx_uint64 &c) {
166 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
167 }
168 virtual void imul(const cytnx_int64 &c) {
169 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
170 }
171 virtual void imul(const cytnx_uint32 &c) {
172 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
173 }
174 virtual void imul(const cytnx_int32 &c) {
175 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
176 }
177 virtual void imul(const cytnx_uint16 &c) {
178 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
179 }
180 virtual void imul(const cytnx_int16 &c) {
181 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
182 }
183 virtual void imul(const cytnx_bool &c) {
184 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
185 }
186
187 virtual void idiv(const Scalar_base *c) {
188 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
189 }
190 virtual void idiv(const cytnx_complex128 &c) {
191 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
192 }
193 virtual void idiv(const cytnx_complex64 &c) {
194 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
195 }
196 virtual void idiv(const cytnx_double &c) {
197 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
198 }
199 virtual void idiv(const cytnx_float &c) {
200 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
201 }
202 virtual void idiv(const cytnx_uint64 &c) {
203 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
204 }
205 virtual void idiv(const cytnx_int64 &c) {
206 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
207 }
208 virtual void idiv(const cytnx_uint32 &c) {
209 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
210 }
211 virtual void idiv(const cytnx_int32 &c) {
212 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
213 }
214 virtual void idiv(const cytnx_uint16 &c) {
215 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
216 }
217 virtual void idiv(const cytnx_int16 &c) {
218 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
219 }
220 virtual void idiv(const cytnx_bool &c) {
221 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
222 }
223
224 virtual bool less(const Scalar_base *c) {
225 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
226 return 0;
227 }
228 virtual bool less(const cytnx_complex128 &c) {
229 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
230 return 0;
231 }
232 virtual bool less(const cytnx_complex64 &c) {
233 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
234 return 0;
235 }
236 virtual bool less(const cytnx_double &c) {
237 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
238 return 0;
239 }
240 virtual bool less(const cytnx_float &c) {
241 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
242 return 0;
243 }
244 virtual bool less(const cytnx_uint64 &c) {
245 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
246 return 0;
247 }
248 virtual bool less(const cytnx_int64 &c) {
249 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
250 return 0;
251 }
252 virtual bool less(const cytnx_uint32 &c) {
253 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
254 return 0;
255 }
256 virtual bool less(const cytnx_int32 &c) {
257 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
258 return 0;
259 }
260 virtual bool less(const cytnx_uint16 &c) {
261 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
262 return 0;
263 }
264 virtual bool less(const cytnx_int16 &c) {
265 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
266 return 0;
267 }
268 virtual bool less(const cytnx_bool &c) {
269 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
270 return 0;
271 }
272
273 virtual bool greater(const Scalar_base *c) {
274 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
275 return 0;
276 }
277 virtual bool greater(const cytnx_complex128 &c) {
278 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
279 return 0;
280 }
281 virtual bool greater(const cytnx_complex64 &c) {
282 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
283 return 0;
284 }
285 virtual bool greater(const cytnx_double &c) {
286 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
287 return 0;
288 }
289 virtual bool greater(const cytnx_float &c) {
290 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
291 return 0;
292 }
293 virtual bool greater(const cytnx_uint64 &c) {
294 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
295 return 0;
296 }
297 virtual bool greater(const cytnx_int64 &c) {
298 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
299 return 0;
300 }
301 virtual bool greater(const cytnx_uint32 &c) {
302 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
303 return 0;
304 }
305 virtual bool greater(const cytnx_int32 &c) {
306 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
307 return 0;
308 }
309 virtual bool greater(const cytnx_uint16 &c) {
310 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
311 return 0;
312 }
313 virtual bool greater(const cytnx_int16 &c) {
314 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
315 return 0;
316 }
317 virtual bool greater(const cytnx_bool &c) {
318 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
319 return 0;
320 }
321
322 virtual bool eq(const Scalar_base *c) {
323 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
324 return 0;
325 }
326
327 virtual void set_maxval() {
328 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
329 };
330 virtual void set_minval() {
331 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
332 };
333
334 virtual void conj_() {
335 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
336 }
337 virtual Scalar_base *get_real() {
338 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
339 return nullptr;
340 }
341 virtual Scalar_base *get_imag() {
342 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
343 return nullptr;
344 }
345
346 virtual void iabs() {
347 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
348 }
349 virtual void isqrt() {
350 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
351 }
352
353 virtual void assign_selftype(const cytnx_complex128 &c) {
354 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
355 }
356 virtual void assign_selftype(const cytnx_complex64 &c) {
357 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
358 }
359 virtual void assign_selftype(const cytnx_double &c) {
360 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
361 }
362 virtual void assign_selftype(const cytnx_float &c) {
363 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
364 }
365 virtual void assign_selftype(const cytnx_uint64 &c) {
366 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
367 }
368 virtual void assign_selftype(const cytnx_int64 &c) {
369 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
370 }
371 virtual void assign_selftype(const cytnx_uint32 &c) {
372 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
373 }
374 virtual void assign_selftype(const cytnx_int32 &c) {
375 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
376 }
377 virtual void assign_selftype(const cytnx_uint16 &c) {
378 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
379 }
380 virtual void assign_selftype(const cytnx_int16 &c) {
381 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
382 }
383 virtual void assign_selftype(const cytnx_bool &c) {
384 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
385 }
386
387 virtual Scalar_base *astype(const unsigned int &dtype) {
388 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
389 return nullptr;
390 }
391
392 virtual void *get_raw_address() const {
393 cytnx_error_msg(true, "[ERROR] Void Type Scalar cannot have operation!!%s", "\n");
394 return nullptr;
395 }
396
397 virtual void print(std::ostream &os) const {};
398 virtual Scalar_base *copy() const {
399 Scalar_base *tmp = new Scalar_base();
400 return tmp;
401 };
402
403 // virtual ~Scalar_base(){};
404 };
405
406 typedef Scalar_base *(*pScalar_init)();
408
410 class Scalar_init_interface : public Type_class {
411 public:
412 // std::vector<pScalar_init> UScIInit;
413 inline static pScalar_init UScIInit[N_Type];
414 inline static bool inited = false;
415 Scalar_init_interface();
416 };
417 extern Scalar_init_interface __ScII;
419
421 class ComplexDoubleScalar : public Scalar_base {
422 public:
423 cytnx_complex128 _elem;
424
425 ComplexDoubleScalar() : _elem(0) { this->_dtype = Type.ComplexDouble; };
426 ComplexDoubleScalar(const cytnx_complex128 &in) : _elem(0) {
427 this->_dtype = Type.ComplexDouble;
428 this->_elem = in;
429 }
430
431 cytnx_float to_cytnx_float() const {
432 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
433 return 0;
434 };
435 cytnx_double to_cytnx_double() const {
436 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
437 return 0;
438 };
439 cytnx_complex64 to_cytnx_complex64() const { return cytnx_complex64(this->_elem); };
440 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
441 cytnx_int64 to_cytnx_int64() const {
442 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
443 return 0;
444 };
445 cytnx_uint64 to_cytnx_uint64() const {
446 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
447 return 0;
448 };
449 cytnx_int32 to_cytnx_int32() const {
450 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
451 return 0;
452 };
453 cytnx_uint32 to_cytnx_uint32() const {
454 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
455 return 0;
456 };
457 cytnx_int16 to_cytnx_int16() const {
458 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
459 return 0;
460 };
461 cytnx_uint16 to_cytnx_uint16() const {
462 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
463 return 0;
464 };
465 cytnx_bool to_cytnx_bool() const {
466 cytnx_error_msg(true, "[ERROR] cannot cast complex128 to real%s", "\n");
467 return 0;
468 };
469
470 void assign_selftype(const cytnx_complex128 &c) { this->_elem = c; }
471 void assign_selftype(const cytnx_complex64 &c) { this->_elem = c; }
472 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
473 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
474 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
475 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
476 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
477 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
478 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
479 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
480 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
481
482 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_complex128(); }
483 void iadd(const cytnx_complex128 &c) { this->_elem += c; }
484 void iadd(const cytnx_complex64 &c) { this->_elem += c; }
485 void iadd(const cytnx_double &c) { this->_elem += c; }
486 void iadd(const cytnx_float &c) { this->_elem += c; }
487 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
488 void iadd(const cytnx_int64 &c) { this->_elem += c; }
489 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
490 void iadd(const cytnx_int32 &c) { this->_elem += c; }
491 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
492 void iadd(const cytnx_int16 &c) { this->_elem += c; }
493 void iadd(const cytnx_bool &c) { this->_elem += c; }
494
495 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_complex128(); }
496 void isub(const cytnx_complex128 &c) { this->_elem -= c; }
497 void isub(const cytnx_complex64 &c) { this->_elem -= c; }
498 void isub(const cytnx_double &c) { this->_elem -= c; }
499 void isub(const cytnx_float &c) { this->_elem -= c; }
500 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
501 void isub(const cytnx_int64 &c) { this->_elem -= c; }
502 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
503 void isub(const cytnx_int32 &c) { this->_elem -= c; }
504 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
505 void isub(const cytnx_int16 &c) { this->_elem -= c; }
506 void isub(const cytnx_bool &c) { this->_elem -= c; }
507
508 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_complex128(); }
509 void imul(const cytnx_complex128 &c) { this->_elem *= c; }
510 void imul(const cytnx_complex64 &c) { this->_elem *= c; }
511 void imul(const cytnx_double &c) { this->_elem *= c; }
512 void imul(const cytnx_float &c) { this->_elem *= c; }
513 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
514 void imul(const cytnx_int64 &c) { this->_elem *= c; }
515 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
516 void imul(const cytnx_int32 &c) { this->_elem *= c; }
517 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
518 void imul(const cytnx_int16 &c) { this->_elem *= c; }
519 void imul(const cytnx_bool &c) { this->_elem *= c; }
520
521 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_complex128(); }
522 void idiv(const cytnx_complex128 &c) { this->_elem /= c; }
523 void idiv(const cytnx_complex64 &c) { this->_elem /= c; }
524 void idiv(const cytnx_double &c) { this->_elem /= c; }
525 void idiv(const cytnx_float &c) { this->_elem /= c; }
526 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
527 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
528 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
529 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
530 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
531 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
532 void idiv(const cytnx_bool &c) { this->_elem /= c; }
533
534 void iabs() { this->_elem = std::abs(cytnx_complex128(this->_elem)); }
535 void isqrt() { this->_elem = std::sqrt(this->_elem); }
536
537 bool less(const Scalar_base *c) {
538 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
539 return 0;
540 }
541 bool less(const cytnx_complex128 &c) {
542 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
543 return 0;
544 }
545 bool less(const cytnx_complex64 &c) {
546 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
547 return 0;
548 }
549 bool less(const cytnx_double &c) {
550 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
551 return 0;
552 }
553 bool less(const cytnx_float &c) {
554 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
555 return 0;
556 }
557 bool less(const cytnx_uint64 &c) {
558 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
559 return 0;
560 }
561 bool less(const cytnx_int64 &c) {
562 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
563 return 0;
564 }
565 bool less(const cytnx_uint32 &c) {
566 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
567 return 0;
568 }
569 bool less(const cytnx_int32 &c) {
570 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
571 return 0;
572 }
573 bool less(const cytnx_uint16 &c) {
574 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
575 return 0;
576 }
577 bool less(const cytnx_int16 &c) {
578 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
579 return 0;
580 }
581 bool less(const cytnx_bool &c) {
582 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
583 return 0;
584 }
585
586 bool greater(const Scalar_base *c) {
587 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
588 return 0;
589 }
590 bool greater(const cytnx_complex128 &c) {
591 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
592 return 0;
593 }
594 bool greater(const cytnx_complex64 &c) {
595 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
596 return 0;
597 }
598 bool greater(const cytnx_double &c) {
599 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
600 return 0;
601 }
602 bool greater(const cytnx_float &c) {
603 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
604 return 0;
605 }
606 bool greater(const cytnx_uint64 &c) {
607 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
608 return 0;
609 }
610 bool greater(const cytnx_int64 &c) {
611 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
612 return 0;
613 }
614 bool greater(const cytnx_uint32 &c) {
615 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
616 return 0;
617 }
618 bool greater(const cytnx_int32 &c) {
619 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
620 return 0;
621 }
622 bool greater(const cytnx_uint16 &c) {
623 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
624 return 0;
625 }
626 bool greater(const cytnx_int16 &c) {
627 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
628 return 0;
629 }
630 bool greater(const cytnx_bool &c) {
631 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
632 return 0;
633 }
634
635 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_complex128(); }
636
637 void set_maxval() {
638 cytnx_error_msg(true, "[ERROR] maxval not supported for complex type%s", "\n");
639 }
640 void set_minval() {
641 cytnx_error_msg(true, "[ERROR] minval not supported for complex type%s", "\n");
642 }
643
644 void conj_() { this->_elem = std::conj(this->_elem); }
645 Scalar_base *get_real() {
646 Scalar_base *tmp = __ScII.UScIInit[Type.Double]();
647 tmp->assign_selftype(this->_elem.real());
648 return tmp;
649 }
650 Scalar_base *get_imag() {
651 Scalar_base *tmp = __ScII.UScIInit[Type.Double]();
652 tmp->assign_selftype(this->_elem.imag());
653 return tmp;
654 }
655
656 void *get_raw_address() const { return (void *)(&this->_elem); }
657
658 Scalar_base *astype(const unsigned int &dtype) {
659 Scalar_base *tmp = __ScII.UScIInit[dtype]();
660 tmp->assign_selftype(this->_elem);
661 return tmp;
662 }
663
664 Scalar_base *copy() const {
665 ComplexDoubleScalar *tmp = new ComplexDoubleScalar(this->_elem);
666 return tmp;
667 };
668 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
669 };
670
671 class ComplexFloatScalar : public Scalar_base {
672 public:
673 cytnx_complex64 _elem;
674
675 ComplexFloatScalar() : _elem(0) { this->_dtype = Type.ComplexFloat; };
676 ComplexFloatScalar(const cytnx_complex64 &in) : _elem(0) {
677 this->_dtype = Type.ComplexFloat;
678 this->_elem = in;
679 }
680
681 cytnx_float to_cytnx_float() const {
682 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
683 return 0;
684 };
685 cytnx_double to_cytnx_double() const {
686 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
687 return 0;
688 };
689 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
690 cytnx_complex128 to_cytnx_complex128() const { return cytnx_complex128(this->_elem); };
691 cytnx_int64 to_cytnx_int64() const {
692 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
693 return 0;
694 };
695 cytnx_uint64 to_cytnx_uint64() const {
696 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
697 return 0;
698 };
699 cytnx_int32 to_cytnx_int32() const {
700 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
701 return 0;
702 };
703 cytnx_uint32 to_cytnx_uint32() const {
704 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
705 return 0;
706 };
707 cytnx_int16 to_cytnx_int16() const {
708 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
709 return 0;
710 };
711 cytnx_uint16 to_cytnx_uint16() const {
712 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
713 return 0;
714 };
715 cytnx_bool to_cytnx_bool() const {
716 cytnx_error_msg(true, "[ERROR] cannot cast complex64 to real%s", "\n");
717 return 0;
718 };
719
720 void assign_selftype(const cytnx_complex128 &c) { this->_elem = c; }
721 void assign_selftype(const cytnx_complex64 &c) { this->_elem = c; }
722 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
723 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
724 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
725 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
726 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
727 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
728 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
729 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
730 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
731
732 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_complex64(); }
733 void iadd(const cytnx_complex128 &c) { this->_elem += c; }
734 void iadd(const cytnx_complex64 &c) { this->_elem += c; }
735 void iadd(const cytnx_double &c) { this->_elem += c; }
736 void iadd(const cytnx_float &c) { this->_elem += c; }
737 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
738 void iadd(const cytnx_int64 &c) { this->_elem += c; }
739 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
740 void iadd(const cytnx_int32 &c) { this->_elem += c; }
741 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
742 void iadd(const cytnx_int16 &c) { this->_elem += c; }
743 void iadd(const cytnx_bool &c) { this->_elem += c; }
744
745 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_complex64(); }
746 void isub(const cytnx_complex128 &c) { this->_elem -= c; }
747 void isub(const cytnx_complex64 &c) { this->_elem -= c; }
748 void isub(const cytnx_double &c) { this->_elem -= c; }
749 void isub(const cytnx_float &c) { this->_elem -= c; }
750 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
751 void isub(const cytnx_int64 &c) { this->_elem -= c; }
752 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
753 void isub(const cytnx_int32 &c) { this->_elem -= c; }
754 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
755 void isub(const cytnx_int16 &c) { this->_elem -= c; }
756 void isub(const cytnx_bool &c) { this->_elem -= c; }
757
758 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_complex64(); }
759 void imul(const cytnx_complex128 &c) { this->_elem *= c; }
760 void imul(const cytnx_complex64 &c) { this->_elem *= c; }
761 void imul(const cytnx_double &c) { this->_elem *= c; }
762 void imul(const cytnx_float &c) { this->_elem *= c; }
763 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
764 void imul(const cytnx_int64 &c) { this->_elem *= c; }
765 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
766 void imul(const cytnx_int32 &c) { this->_elem *= c; }
767 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
768 void imul(const cytnx_int16 &c) { this->_elem *= c; }
769 void imul(const cytnx_bool &c) { this->_elem *= c; }
770
771 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_complex64(); }
772 void idiv(const cytnx_complex128 &c) { this->_elem /= c; }
773 void idiv(const cytnx_complex64 &c) { this->_elem /= c; }
774 void idiv(const cytnx_double &c) { this->_elem /= c; }
775 void idiv(const cytnx_float &c) { this->_elem /= c; }
776 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
777 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
778 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
779 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
780 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
781 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
782 void idiv(const cytnx_bool &c) { this->_elem /= c; }
783
784 bool less(const Scalar_base *c) {
785 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
786 return 0;
787 }
788 bool less(const cytnx_complex128 &c) {
789 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
790 return 0;
791 }
792 bool less(const cytnx_complex64 &c) {
793 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
794 return 0;
795 }
796 bool less(const cytnx_double &c) {
797 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
798 return 0;
799 }
800 bool less(const cytnx_float &c) {
801 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
802 return 0;
803 }
804 bool less(const cytnx_uint64 &c) {
805 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
806 return 0;
807 }
808 bool less(const cytnx_int64 &c) {
809 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
810 return 0;
811 }
812 bool less(const cytnx_uint32 &c) {
813 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
814 return 0;
815 }
816 bool less(const cytnx_int32 &c) {
817 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
818 return 0;
819 }
820 bool less(const cytnx_uint16 &c) {
821 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
822 return 0;
823 }
824 bool less(const cytnx_int16 &c) {
825 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
826 return 0;
827 }
828 bool less(const cytnx_bool &c) {
829 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
830 return 0;
831 }
832
833 bool greater(const Scalar_base *c) {
834 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
835 return 0;
836 }
837 bool greater(const cytnx_complex128 &c) {
838 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
839 return 0;
840 }
841 bool greater(const cytnx_complex64 &c) {
842 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
843 return 0;
844 }
845 bool greater(const cytnx_double &c) {
846 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
847 return 0;
848 }
849 bool greater(const cytnx_float &c) {
850 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
851 return 0;
852 }
853 bool greater(const cytnx_uint64 &c) {
854 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
855 return 0;
856 }
857 bool greater(const cytnx_int64 &c) {
858 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
859 return 0;
860 }
861 bool greater(const cytnx_uint32 &c) {
862 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
863 return 0;
864 }
865 bool greater(const cytnx_int32 &c) {
866 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
867 return 0;
868 }
869 bool greater(const cytnx_uint16 &c) {
870 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
871 return 0;
872 }
873 bool greater(const cytnx_int16 &c) {
874 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
875 return 0;
876 }
877 bool greater(const cytnx_bool &c) {
878 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
879 return 0;
880 }
881
882 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_complex64(); }
883
884 void set_maxval() {
885 cytnx_error_msg(true, "[ERROR] maxval not supported for complex type%s", "\n");
886 }
887 void set_minval() {
888 cytnx_error_msg(true, "[ERROR] minval not supported for complex type%s", "\n");
889 }
890
891 void conj_() { this->_elem = std::conj(this->_elem); }
892 Scalar_base *get_real() {
893 Scalar_base *tmp = __ScII.UScIInit[Type.Float]();
894 tmp->assign_selftype(this->_elem.real());
895 return tmp;
896 }
897 Scalar_base *get_imag() {
898 Scalar_base *tmp = __ScII.UScIInit[Type.Float]();
899 tmp->assign_selftype(this->_elem.imag());
900 return tmp;
901 }
902
903 void iabs() { this->_elem = std::abs(this->_elem); }
904 void isqrt() { this->_elem = std::sqrt(this->_elem); }
905
906 void *get_raw_address() const { return (void *)(&this->_elem); }
907 Scalar_base *astype(const unsigned int &dtype) {
908 Scalar_base *tmp = __ScII.UScIInit[dtype]();
909 tmp->assign_selftype(this->_elem);
910 return tmp;
911 }
912
913 Scalar_base *copy() const {
914 ComplexFloatScalar *tmp = new ComplexFloatScalar(this->_elem);
915 return tmp;
916 };
917 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
918 };
919
920 class DoubleScalar : public Scalar_base {
921 public:
922 cytnx_double _elem;
923
924 DoubleScalar() : _elem(0) { this->_dtype = Type.Double; };
925 DoubleScalar(const cytnx_double &in) : _elem(0) {
926 this->_dtype = Type.Double;
927 this->_elem = in;
928 }
929
930 cytnx_float to_cytnx_float() const { return this->_elem; };
931 cytnx_double to_cytnx_double() const { return this->_elem; };
932 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
933 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
934 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
935 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
936 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
937 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
938 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
939 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
940 cytnx_bool to_cytnx_bool() const { return this->_elem; };
941
942 void assign_selftype(const cytnx_complex128 &c) {
943 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
944 }
945 void assign_selftype(const cytnx_complex64 &c) {
946 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
947 }
948 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
949 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
950 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
951 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
952 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
953 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
954 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
955 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
956 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
957
958 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_double(); }
959 void iadd(const cytnx_complex128 &c) {
960 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
961 }
962 void iadd(const cytnx_complex64 &c) {
963 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
964 }
965 void iadd(const cytnx_double &c) { this->_elem += c; }
966 void iadd(const cytnx_float &c) { this->_elem += c; }
967 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
968 void iadd(const cytnx_int64 &c) { this->_elem += c; }
969 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
970 void iadd(const cytnx_int32 &c) { this->_elem += c; }
971 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
972 void iadd(const cytnx_int16 &c) { this->_elem += c; }
973 void iadd(const cytnx_bool &c) { this->_elem += c; }
974
975 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_double(); }
976 void isub(const cytnx_complex128 &c) {
977 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
978 }
979 void isub(const cytnx_complex64 &c) {
980 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
981 }
982 void isub(const cytnx_double &c) { this->_elem -= c; }
983 void isub(const cytnx_float &c) { this->_elem -= c; }
984 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
985 void isub(const cytnx_int64 &c) { this->_elem -= c; }
986 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
987 void isub(const cytnx_int32 &c) { this->_elem -= c; }
988 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
989 void isub(const cytnx_int16 &c) { this->_elem -= c; }
990 void isub(const cytnx_bool &c) { this->_elem -= c; }
991
992 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_double(); }
993 void imul(const cytnx_complex128 &c) {
994 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
995 }
996 void imul(const cytnx_complex64 &c) {
997 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
998 }
999 void imul(const cytnx_double &c) { this->_elem *= c; }
1000 void imul(const cytnx_float &c) { this->_elem *= c; }
1001 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
1002 void imul(const cytnx_int64 &c) { this->_elem *= c; }
1003 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
1004 void imul(const cytnx_int32 &c) { this->_elem *= c; }
1005 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
1006 void imul(const cytnx_int16 &c) { this->_elem *= c; }
1007 void imul(const cytnx_bool &c) { this->_elem *= c; }
1008
1009 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_double(); }
1010 void idiv(const cytnx_complex128 &c) {
1011 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1012 }
1013 void idiv(const cytnx_complex64 &c) {
1014 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1015 }
1016 void idiv(const cytnx_double &c) { this->_elem /= c; }
1017 void idiv(const cytnx_float &c) { this->_elem /= c; }
1018 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
1019 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
1020 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
1021 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
1022 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
1023 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
1024 void idiv(const cytnx_bool &c) { this->_elem /= c; }
1025
1026 void iabs() { this->_elem = std::abs(this->_elem); }
1027 void isqrt() { this->_elem = std::sqrt(this->_elem); }
1028
1029 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_double(); }
1030 bool less(const cytnx_complex128 &c) {
1031 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1032 return 0;
1033 }
1034 bool less(const cytnx_complex64 &c) {
1035 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1036 return 0;
1037 }
1038 bool less(const cytnx_double &c) { return this->_elem < c; }
1039 bool less(const cytnx_float &c) { return this->_elem < c; }
1040 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
1041 bool less(const cytnx_int64 &c) { return this->_elem < c; }
1042 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
1043 bool less(const cytnx_int32 &c) { return this->_elem < c; }
1044 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
1045 bool less(const cytnx_int16 &c) { return this->_elem < c; }
1046 bool less(const cytnx_bool &c) { return this->_elem < c; }
1047
1048 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_double(); }
1049 bool greater(const cytnx_complex128 &c) {
1050 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1051 return 0;
1052 }
1053 bool greater(const cytnx_complex64 &c) {
1054 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1055 return 0;
1056 }
1057 bool greater(const cytnx_double &c) { return this->_elem > c; }
1058 bool greater(const cytnx_float &c) { return this->_elem > c; }
1059 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
1060 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
1061 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
1062 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
1063 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
1064 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
1065 bool greater(const cytnx_bool &c) { return this->_elem > c; }
1066
1067 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_double(); }
1068
1069 void set_maxval() { this->_elem = std::numeric_limits<double>::max(); }
1070 void set_minval() { this->_elem = std::numeric_limits<double>::min(); }
1071
1072 void conj_() { return; }
1073 Scalar_base *get_real() { return this->copy(); }
1074 Scalar_base *get_imag() {
1075 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
1076 return nullptr;
1077 }
1078
1079 void *get_raw_address() const { return (void *)(&this->_elem); }
1080 Scalar_base *astype(const unsigned int &dtype) {
1081 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1082 tmp->assign_selftype(this->_elem);
1083 return tmp;
1084 }
1085 Scalar_base *copy() const {
1086 DoubleScalar *tmp = new DoubleScalar(this->_elem);
1087 return tmp;
1088 };
1089 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
1090 };
1091
1092 class FloatScalar : public Scalar_base {
1093 public:
1094 cytnx_float _elem;
1095
1096 FloatScalar() : _elem(0) { this->_dtype = Type.Float; };
1097 FloatScalar(const cytnx_float &in) : _elem(0) {
1098 this->_dtype = Type.Float;
1099 this->_elem = in;
1100 }
1101
1102 cytnx_float to_cytnx_float() const { return this->_elem; };
1103 cytnx_double to_cytnx_double() const { return this->_elem; };
1104 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
1105 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
1106 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
1107 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
1108 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
1109 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
1110 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
1111 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
1112 cytnx_bool to_cytnx_bool() const { return this->_elem; };
1113
1114 void assign_selftype(const cytnx_complex128 &c) {
1115 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1116 }
1117 void assign_selftype(const cytnx_complex64 &c) {
1118 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1119 }
1120 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
1121 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
1122 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
1123 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
1124 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
1125 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
1126 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
1127 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
1128 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
1129
1130 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_float(); }
1131 void iadd(const cytnx_complex128 &c) {
1132 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1133 }
1134 void iadd(const cytnx_complex64 &c) {
1135 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1136 }
1137 void iadd(const cytnx_double &c) { this->_elem += c; }
1138 void iadd(const cytnx_float &c) { this->_elem += c; }
1139 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
1140 void iadd(const cytnx_int64 &c) { this->_elem += c; }
1141 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
1142 void iadd(const cytnx_int32 &c) { this->_elem += c; }
1143 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
1144 void iadd(const cytnx_int16 &c) { this->_elem += c; }
1145 void iadd(const cytnx_bool &c) { this->_elem += c; }
1146
1147 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_float(); }
1148 void isub(const cytnx_complex128 &c) {
1149 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1150 }
1151 void isub(const cytnx_complex64 &c) {
1152 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1153 }
1154 void isub(const cytnx_double &c) { this->_elem -= c; }
1155 void isub(const cytnx_float &c) { this->_elem -= c; }
1156 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
1157 void isub(const cytnx_int64 &c) { this->_elem -= c; }
1158 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
1159 void isub(const cytnx_int32 &c) { this->_elem -= c; }
1160 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
1161 void isub(const cytnx_int16 &c) { this->_elem -= c; }
1162 void isub(const cytnx_bool &c) { this->_elem -= c; }
1163
1164 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_float(); }
1165 void imul(const cytnx_complex128 &c) {
1166 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1167 }
1168 void imul(const cytnx_complex64 &c) {
1169 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1170 }
1171 void imul(const cytnx_double &c) { this->_elem *= c; }
1172 void imul(const cytnx_float &c) { this->_elem *= c; }
1173 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
1174 void imul(const cytnx_int64 &c) { this->_elem *= c; }
1175 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
1176 void imul(const cytnx_int32 &c) { this->_elem *= c; }
1177 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
1178 void imul(const cytnx_int16 &c) { this->_elem *= c; }
1179 void imul(const cytnx_bool &c) { this->_elem *= c; }
1180
1181 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_float(); }
1182 void idiv(const cytnx_complex128 &c) {
1183 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1184 }
1185 void idiv(const cytnx_complex64 &c) {
1186 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1187 }
1188 void idiv(const cytnx_double &c) { this->_elem /= c; }
1189 void idiv(const cytnx_float &c) { this->_elem /= c; }
1190 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
1191 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
1192 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
1193 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
1194 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
1195 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
1196 void idiv(const cytnx_bool &c) { this->_elem /= c; }
1197
1198 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_float(); }
1199 bool less(const cytnx_complex128 &c) {
1200 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1201 return 0;
1202 }
1203 bool less(const cytnx_complex64 &c) {
1204 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1205 return 0;
1206 }
1207 bool less(const cytnx_double &c) { return this->_elem < c; }
1208 bool less(const cytnx_float &c) { return this->_elem < c; }
1209 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
1210 bool less(const cytnx_int64 &c) { return this->_elem < c; }
1211 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
1212 bool less(const cytnx_int32 &c) { return this->_elem < c; }
1213 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
1214 bool less(const cytnx_int16 &c) { return this->_elem < c; }
1215 bool less(const cytnx_bool &c) { return this->_elem < c; }
1216
1217 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_float(); }
1218 bool greater(const cytnx_complex128 &c) {
1219 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1220 return 0;
1221 }
1222 bool greater(const cytnx_complex64 &c) {
1223 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1224 return 0;
1225 }
1226 bool greater(const cytnx_double &c) { return this->_elem > c; }
1227 bool greater(const cytnx_float &c) { return this->_elem > c; }
1228 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
1229 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
1230 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
1231 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
1232 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
1233 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
1234 bool greater(const cytnx_bool &c) { return this->_elem > c; }
1235
1236 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_float(); }
1237 void isqrt() { this->_elem = std::sqrt(this->_elem); }
1238
1239 void conj_() { return; }
1240 Scalar_base *get_real() { return this->copy(); }
1241 Scalar_base *get_imag() {
1242 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
1243 return nullptr;
1244 }
1245
1246 void set_maxval() { this->_elem = std::numeric_limits<float>::max(); }
1247 void set_minval() { this->_elem = std::numeric_limits<float>::min(); }
1248
1249 void iabs() { this->_elem = std::abs(this->_elem); }
1250
1251 void *get_raw_address() const { return (void *)(&this->_elem); }
1252 Scalar_base *astype(const unsigned int &dtype) {
1253 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1254 tmp->assign_selftype(this->_elem);
1255 return tmp;
1256 }
1257 Scalar_base *copy() const {
1258 FloatScalar *tmp = new FloatScalar(this->_elem);
1259 return tmp;
1260 };
1261 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
1262 };
1263
1264 class Int64Scalar : public Scalar_base {
1265 public:
1266 cytnx_int64 _elem;
1267
1268 Int64Scalar() : _elem(0) { this->_dtype = Type.Int64; };
1269 Int64Scalar(const cytnx_int64 &in) : _elem(0) {
1270 this->_dtype = Type.Int64;
1271 this->_elem = in;
1272 }
1273
1274 cytnx_float to_cytnx_float() const { return this->_elem; };
1275 cytnx_double to_cytnx_double() const { return this->_elem; };
1276 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
1277 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
1278 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
1279 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
1280 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
1281 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
1282 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
1283 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
1284 cytnx_bool to_cytnx_bool() const { return this->_elem; };
1285
1286 void assign_selftype(const cytnx_complex128 &c) {
1287 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1288 }
1289 void assign_selftype(const cytnx_complex64 &c) {
1290 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1291 }
1292 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
1293 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
1294 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
1295 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
1296 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
1297 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
1298 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
1299 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
1300 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
1301
1302 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_int64(); }
1303 void iadd(const cytnx_complex128 &c) {
1304 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1305 }
1306 void iadd(const cytnx_complex64 &c) {
1307 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1308 }
1309 void iadd(const cytnx_double &c) { this->_elem += c; }
1310 void iadd(const cytnx_float &c) { this->_elem += c; }
1311 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
1312 void iadd(const cytnx_int64 &c) { this->_elem += c; }
1313 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
1314 void iadd(const cytnx_int32 &c) { this->_elem += c; }
1315 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
1316 void iadd(const cytnx_int16 &c) { this->_elem += c; }
1317 void iadd(const cytnx_bool &c) { this->_elem += c; }
1318
1319 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_int64(); }
1320 void isub(const cytnx_complex128 &c) {
1321 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1322 }
1323 void isub(const cytnx_complex64 &c) {
1324 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1325 }
1326 void isub(const cytnx_double &c) { this->_elem -= c; }
1327 void isub(const cytnx_float &c) { this->_elem -= c; }
1328 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
1329 void isub(const cytnx_int64 &c) { this->_elem -= c; }
1330 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
1331 void isub(const cytnx_int32 &c) { this->_elem -= c; }
1332 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
1333 void isub(const cytnx_int16 &c) { this->_elem -= c; }
1334 void isub(const cytnx_bool &c) { this->_elem -= c; }
1335
1336 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_int64(); }
1337 void imul(const cytnx_complex128 &c) {
1338 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1339 }
1340 void imul(const cytnx_complex64 &c) {
1341 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1342 }
1343 void imul(const cytnx_double &c) { this->_elem *= c; }
1344 void imul(const cytnx_float &c) { this->_elem *= c; }
1345 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
1346 void imul(const cytnx_int64 &c) { this->_elem *= c; }
1347 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
1348 void imul(const cytnx_int32 &c) { this->_elem *= c; }
1349 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
1350 void imul(const cytnx_int16 &c) { this->_elem *= c; }
1351 void imul(const cytnx_bool &c) { this->_elem *= c; }
1352
1353 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_int64(); }
1354 void idiv(const cytnx_complex128 &c) {
1355 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1356 }
1357 void idiv(const cytnx_complex64 &c) {
1358 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1359 }
1360 void idiv(const cytnx_double &c) { this->_elem /= c; }
1361 void idiv(const cytnx_float &c) { this->_elem /= c; }
1362 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
1363 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
1364 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
1365 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
1366 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
1367 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
1368 void idiv(const cytnx_bool &c) { this->_elem /= c; }
1369
1370 void iabs() { this->_elem = std::abs(this->_elem); }
1371 void isqrt() { this->_elem = std::sqrt(this->_elem); }
1372
1373 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_int64(); }
1374 bool less(const cytnx_complex128 &c) {
1375 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1376 return 0;
1377 }
1378 bool less(const cytnx_complex64 &c) {
1379 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1380 return 0;
1381 }
1382 bool less(const cytnx_double &c) { return this->_elem < c; }
1383 bool less(const cytnx_float &c) { return this->_elem < c; }
1384 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
1385 bool less(const cytnx_int64 &c) { return this->_elem < c; }
1386 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
1387 bool less(const cytnx_int32 &c) { return this->_elem < c; }
1388 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
1389 bool less(const cytnx_int16 &c) { return this->_elem < c; }
1390 bool less(const cytnx_bool &c) { return this->_elem < c; }
1391
1392 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_int64(); }
1393 bool greater(const cytnx_complex128 &c) {
1394 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1395 return 0;
1396 }
1397 bool greater(const cytnx_complex64 &c) {
1398 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1399 return 0;
1400 }
1401 bool greater(const cytnx_double &c) { return this->_elem > c; }
1402 bool greater(const cytnx_float &c) { return this->_elem > c; }
1403 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
1404 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
1405 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
1406 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
1407 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
1408 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
1409 bool greater(const cytnx_bool &c) { return this->_elem > c; }
1410
1411 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_int64(); }
1412
1413 void conj_() { return; }
1414 Scalar_base *get_real() { return this->copy(); }
1415 Scalar_base *get_imag() {
1416 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
1417 return nullptr;
1418 }
1419
1420 void set_maxval() { this->_elem = std::numeric_limits<cytnx_int64>::max(); }
1421 void set_minval() { this->_elem = std::numeric_limits<cytnx_int64>::min(); }
1422
1423 void *get_raw_address() const { return (void *)(&this->_elem); }
1424 Scalar_base *astype(const unsigned int &dtype) {
1425 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1426 tmp->assign_selftype(this->_elem);
1427 return tmp;
1428 }
1429 Scalar_base *copy() const {
1430 Int64Scalar *tmp = new Int64Scalar(this->_elem);
1431 return tmp;
1432 };
1433 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
1434 };
1435 class Uint64Scalar : public Scalar_base {
1436 public:
1437 cytnx_uint64 _elem;
1438
1439 Uint64Scalar() : _elem(0) { this->_dtype = Type.Uint64; };
1440 Uint64Scalar(const cytnx_uint64 &in) : _elem(0) {
1441 this->_dtype = Type.Uint64;
1442 this->_elem = in;
1443 }
1444
1445 cytnx_float to_cytnx_float() const { return this->_elem; };
1446 cytnx_double to_cytnx_double() const { return this->_elem; };
1447 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
1448 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
1449 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
1450 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
1451 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
1452 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
1453 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
1454 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
1455 cytnx_bool to_cytnx_bool() const { return this->_elem; };
1456
1457 void assign_selftype(const cytnx_complex128 &c) {
1458 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1459 }
1460 void assign_selftype(const cytnx_complex64 &c) {
1461 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1462 }
1463 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
1464 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
1465 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
1466 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
1467 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
1468 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
1469 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
1470 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
1471 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
1472
1473 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_uint64(); }
1474 void iadd(const cytnx_complex128 &c) {
1475 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1476 }
1477 void iadd(const cytnx_complex64 &c) {
1478 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1479 }
1480 void iadd(const cytnx_double &c) { this->_elem += c; }
1481 void iadd(const cytnx_float &c) { this->_elem += c; }
1482 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
1483 void iadd(const cytnx_int64 &c) { this->_elem += c; }
1484 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
1485 void iadd(const cytnx_int32 &c) { this->_elem += c; }
1486 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
1487 void iadd(const cytnx_int16 &c) { this->_elem += c; }
1488 void iadd(const cytnx_bool &c) { this->_elem += c; }
1489
1490 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_uint64(); }
1491 void isub(const cytnx_complex128 &c) {
1492 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1493 }
1494 void isub(const cytnx_complex64 &c) {
1495 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1496 }
1497 void isub(const cytnx_double &c) { this->_elem -= c; }
1498 void isub(const cytnx_float &c) { this->_elem -= c; }
1499 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
1500 void isub(const cytnx_int64 &c) { this->_elem -= c; }
1501 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
1502 void isub(const cytnx_int32 &c) { this->_elem -= c; }
1503 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
1504 void isub(const cytnx_int16 &c) { this->_elem -= c; }
1505 void isub(const cytnx_bool &c) { this->_elem -= c; }
1506
1507 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_uint64(); }
1508 void imul(const cytnx_complex128 &c) {
1509 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1510 }
1511 void imul(const cytnx_complex64 &c) {
1512 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1513 }
1514 void imul(const cytnx_double &c) { this->_elem *= c; }
1515 void imul(const cytnx_float &c) { this->_elem *= c; }
1516 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
1517 void imul(const cytnx_int64 &c) { this->_elem *= c; }
1518 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
1519 void imul(const cytnx_int32 &c) { this->_elem *= c; }
1520 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
1521 void imul(const cytnx_int16 &c) { this->_elem *= c; }
1522 void imul(const cytnx_bool &c) { this->_elem *= c; }
1523
1524 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_uint64(); }
1525 void idiv(const cytnx_complex128 &c) {
1526 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1527 }
1528 void idiv(const cytnx_complex64 &c) {
1529 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1530 }
1531 void idiv(const cytnx_double &c) { this->_elem /= c; }
1532 void idiv(const cytnx_float &c) { this->_elem /= c; }
1533 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
1534 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
1535 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
1536 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
1537 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
1538 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
1539 void idiv(const cytnx_bool &c) { this->_elem /= c; }
1540
1541 void iabs() { this->_elem = std::abs(cytnx_double(this->_elem)); }
1542 void isqrt() { this->_elem = std::sqrt(this->_elem); }
1543
1544 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_uint64(); }
1545 bool less(const cytnx_complex128 &c) {
1546 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1547 return 0;
1548 }
1549 bool less(const cytnx_complex64 &c) {
1550 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1551 return 0;
1552 }
1553 bool less(const cytnx_double &c) { return this->_elem < c; }
1554 bool less(const cytnx_float &c) { return this->_elem < c; }
1555 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
1556 bool less(const cytnx_int64 &c) { return this->_elem < c; }
1557 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
1558 bool less(const cytnx_int32 &c) { return this->_elem < c; }
1559 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
1560 bool less(const cytnx_int16 &c) { return this->_elem < c; }
1561 bool less(const cytnx_bool &c) { return this->_elem < c; }
1562
1563 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_uint64(); }
1564 bool greater(const cytnx_complex128 &c) {
1565 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1566 return 0;
1567 }
1568 bool greater(const cytnx_complex64 &c) {
1569 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1570 return 0;
1571 }
1572 bool greater(const cytnx_double &c) { return this->_elem > c; }
1573 bool greater(const cytnx_float &c) { return this->_elem > c; }
1574 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
1575 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
1576 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
1577 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
1578 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
1579 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
1580 bool greater(const cytnx_bool &c) { return this->_elem > c; }
1581
1582 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_uint64(); }
1583
1584 void conj_() { return; }
1585 Scalar_base *get_real() { return this->copy(); }
1586 Scalar_base *get_imag() {
1587 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
1588 return nullptr;
1589 }
1590
1591 void set_maxval() { this->_elem = std::numeric_limits<cytnx_uint64>::max(); }
1592 void set_minval() { this->_elem = std::numeric_limits<cytnx_uint64>::min(); }
1593
1594 void *get_raw_address() const { return (void *)(&this->_elem); }
1595 Scalar_base *astype(const unsigned int &dtype) {
1596 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1597 tmp->assign_selftype(this->_elem);
1598 return tmp;
1599 }
1600 Scalar_base *copy() const {
1601 Uint64Scalar *tmp = new Uint64Scalar(this->_elem);
1602 return tmp;
1603 };
1604 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
1605 };
1606 class Int32Scalar : public Scalar_base {
1607 public:
1608 cytnx_int32 _elem;
1609
1610 Int32Scalar() : _elem(0) { this->_dtype = Type.Int32; };
1611 Int32Scalar(const cytnx_int32 &in) : _elem(0) {
1612 this->_dtype = Type.Int32;
1613 this->_elem = in;
1614 }
1615
1616 cytnx_float to_cytnx_float() const { return this->_elem; };
1617 cytnx_double to_cytnx_double() const { return this->_elem; };
1618 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
1619 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
1620 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
1621 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
1622 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
1623 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
1624 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
1625 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
1626 cytnx_bool to_cytnx_bool() const { return this->_elem; };
1627
1628 void assign_selftype(const cytnx_complex128 &c) {
1629 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1630 }
1631 void assign_selftype(const cytnx_complex64 &c) {
1632 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1633 }
1634 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
1635 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
1636 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
1637 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
1638 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
1639 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
1640 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
1641 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
1642 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
1643
1644 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_int32(); }
1645 void iadd(const cytnx_complex128 &c) {
1646 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1647 }
1648 void iadd(const cytnx_complex64 &c) {
1649 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1650 }
1651 void iadd(const cytnx_double &c) { this->_elem += c; }
1652 void iadd(const cytnx_float &c) { this->_elem += c; }
1653 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
1654 void iadd(const cytnx_int64 &c) { this->_elem += c; }
1655 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
1656 void iadd(const cytnx_int32 &c) { this->_elem += c; }
1657 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
1658 void iadd(const cytnx_int16 &c) { this->_elem += c; }
1659 void iadd(const cytnx_bool &c) { this->_elem += c; }
1660
1661 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_int32(); }
1662 void isub(const cytnx_complex128 &c) {
1663 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1664 }
1665 void isub(const cytnx_complex64 &c) {
1666 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1667 }
1668 void isub(const cytnx_double &c) { this->_elem -= c; }
1669 void isub(const cytnx_float &c) { this->_elem -= c; }
1670 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
1671 void isub(const cytnx_int64 &c) { this->_elem -= c; }
1672 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
1673 void isub(const cytnx_int32 &c) { this->_elem -= c; }
1674 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
1675 void isub(const cytnx_int16 &c) { this->_elem -= c; }
1676 void isub(const cytnx_bool &c) { this->_elem -= c; }
1677
1678 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_int32(); }
1679 void imul(const cytnx_complex128 &c) {
1680 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1681 }
1682 void imul(const cytnx_complex64 &c) {
1683 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1684 }
1685 void imul(const cytnx_double &c) { this->_elem *= c; }
1686 void imul(const cytnx_float &c) { this->_elem *= c; }
1687 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
1688 void imul(const cytnx_int64 &c) { this->_elem *= c; }
1689 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
1690 void imul(const cytnx_int32 &c) { this->_elem *= c; }
1691 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
1692 void imul(const cytnx_int16 &c) { this->_elem *= c; }
1693 void imul(const cytnx_bool &c) { this->_elem *= c; }
1694
1695 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_int32(); }
1696 void idiv(const cytnx_complex128 &c) {
1697 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1698 }
1699 void idiv(const cytnx_complex64 &c) {
1700 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1701 }
1702 void idiv(const cytnx_double &c) { this->_elem /= c; }
1703 void idiv(const cytnx_float &c) { this->_elem /= c; }
1704 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
1705 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
1706 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
1707 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
1708 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
1709 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
1710 void idiv(const cytnx_bool &c) { this->_elem /= c; }
1711
1712 void iabs() { this->_elem = std::abs(this->_elem); }
1713 void isqrt() { this->_elem = std::sqrt(this->_elem); }
1714
1715 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_int32(); }
1716 bool less(const cytnx_complex128 &c) {
1717 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1718 return 0;
1719 }
1720 bool less(const cytnx_complex64 &c) {
1721 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1722 return 0;
1723 }
1724 bool less(const cytnx_double &c) { return this->_elem < c; }
1725 bool less(const cytnx_float &c) { return this->_elem < c; }
1726 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
1727 bool less(const cytnx_int64 &c) { return this->_elem < c; }
1728 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
1729 bool less(const cytnx_int32 &c) { return this->_elem < c; }
1730 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
1731 bool less(const cytnx_int16 &c) { return this->_elem < c; }
1732 bool less(const cytnx_bool &c) { return this->_elem < c; }
1733
1734 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_int32(); }
1735 bool greater(const cytnx_complex128 &c) {
1736 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1737 return 0;
1738 }
1739 bool greater(const cytnx_complex64 &c) {
1740 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1741 return 0;
1742 }
1743 bool greater(const cytnx_double &c) { return this->_elem > c; }
1744 bool greater(const cytnx_float &c) { return this->_elem > c; }
1745 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
1746 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
1747 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
1748 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
1749 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
1750 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
1751 bool greater(const cytnx_bool &c) { return this->_elem > c; }
1752
1753 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_int32(); }
1754
1755 void conj_() { return; }
1756 Scalar_base *get_real() { return this->copy(); }
1757 Scalar_base *get_imag() {
1758 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
1759 return nullptr;
1760 }
1761
1762 void set_maxval() { this->_elem = std::numeric_limits<cytnx_int32>::max(); }
1763 void set_minval() { this->_elem = std::numeric_limits<cytnx_int32>::min(); }
1764
1765 void *get_raw_address() const { return (void *)(&this->_elem); }
1766
1767 Scalar_base *astype(const unsigned int &dtype) {
1768 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1769 tmp->assign_selftype(this->_elem);
1770 return tmp;
1771 }
1772 Scalar_base *copy() const {
1773 Int32Scalar *tmp = new Int32Scalar(this->_elem);
1774 return tmp;
1775 };
1776 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
1777 };
1778 class Uint32Scalar : public Scalar_base {
1779 public:
1780 cytnx_uint32 _elem;
1781
1782 Uint32Scalar() : _elem(0) { this->_dtype = Type.Uint32; };
1783 Uint32Scalar(const cytnx_uint32 &in) : _elem(0) {
1784 this->_dtype = Type.Uint32;
1785 this->_elem = in;
1786 }
1787
1788 cytnx_float to_cytnx_float() const { return this->_elem; };
1789 cytnx_double to_cytnx_double() const { return this->_elem; };
1790 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
1791 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
1792 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
1793 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
1794 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
1795 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
1796 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
1797 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
1798 cytnx_bool to_cytnx_bool() const { return this->_elem; };
1799
1800 void assign_selftype(const cytnx_complex128 &c) {
1801 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1802 }
1803 void assign_selftype(const cytnx_complex64 &c) {
1804 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1805 }
1806 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
1807 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
1808 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
1809 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
1810 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
1811 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
1812 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
1813 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
1814 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
1815
1816 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_uint32(); }
1817 void iadd(const cytnx_complex128 &c) {
1818 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1819 }
1820 void iadd(const cytnx_complex64 &c) {
1821 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1822 }
1823 void iadd(const cytnx_double &c) { this->_elem += c; }
1824 void iadd(const cytnx_float &c) { this->_elem += c; }
1825 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
1826 void iadd(const cytnx_int64 &c) { this->_elem += c; }
1827 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
1828 void iadd(const cytnx_int32 &c) { this->_elem += c; }
1829 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
1830 void iadd(const cytnx_int16 &c) { this->_elem += c; }
1831 void iadd(const cytnx_bool &c) { this->_elem += c; }
1832
1833 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_uint32(); }
1834 void isub(const cytnx_complex128 &c) {
1835 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1836 }
1837 void isub(const cytnx_complex64 &c) {
1838 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1839 }
1840 void isub(const cytnx_double &c) { this->_elem -= c; }
1841 void isub(const cytnx_float &c) { this->_elem -= c; }
1842 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
1843 void isub(const cytnx_int64 &c) { this->_elem -= c; }
1844 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
1845 void isub(const cytnx_int32 &c) { this->_elem -= c; }
1846 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
1847 void isub(const cytnx_int16 &c) { this->_elem -= c; }
1848 void isub(const cytnx_bool &c) { this->_elem -= c; }
1849
1850 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_uint32(); }
1851 void imul(const cytnx_complex128 &c) {
1852 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1853 }
1854 void imul(const cytnx_complex64 &c) {
1855 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1856 }
1857 void imul(const cytnx_double &c) { this->_elem *= c; }
1858 void imul(const cytnx_float &c) { this->_elem *= c; }
1859 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
1860 void imul(const cytnx_int64 &c) { this->_elem *= c; }
1861 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
1862 void imul(const cytnx_int32 &c) { this->_elem *= c; }
1863 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
1864 void imul(const cytnx_int16 &c) { this->_elem *= c; }
1865 void imul(const cytnx_bool &c) { this->_elem *= c; }
1866
1867 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_uint32(); }
1868 void idiv(const cytnx_complex128 &c) {
1869 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1870 }
1871 void idiv(const cytnx_complex64 &c) {
1872 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1873 }
1874 void idiv(const cytnx_double &c) { this->_elem /= c; }
1875 void idiv(const cytnx_float &c) { this->_elem /= c; }
1876 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
1877 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
1878 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
1879 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
1880 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
1881 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
1882 void idiv(const cytnx_bool &c) { this->_elem /= c; }
1883
1884 void iabs() { this->_elem = std::abs(cytnx_double(this->_elem)); }
1885 void isqrt() { this->_elem = std::sqrt(this->_elem); }
1886
1887 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_uint32(); }
1888 bool less(const cytnx_complex128 &c) {
1889 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1890 return 0;
1891 }
1892 bool less(const cytnx_complex64 &c) {
1893 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1894 return 0;
1895 }
1896 bool less(const cytnx_double &c) { return this->_elem < c; }
1897 bool less(const cytnx_float &c) { return this->_elem < c; }
1898 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
1899 bool less(const cytnx_int64 &c) { return this->_elem < c; }
1900 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
1901 bool less(const cytnx_int32 &c) { return this->_elem < c; }
1902 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
1903 bool less(const cytnx_int16 &c) { return this->_elem < c; }
1904 bool less(const cytnx_bool &c) { return this->_elem < c; }
1905
1906 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_uint32(); }
1907 bool greater(const cytnx_complex128 &c) {
1908 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1909 return 0;
1910 }
1911 bool greater(const cytnx_complex64 &c) {
1912 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
1913 return 0;
1914 }
1915 bool greater(const cytnx_double &c) { return this->_elem > c; }
1916 bool greater(const cytnx_float &c) { return this->_elem > c; }
1917 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
1918 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
1919 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
1920 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
1921 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
1922 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
1923 bool greater(const cytnx_bool &c) { return this->_elem > c; }
1924
1925 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_uint32(); }
1926
1927 void conj_() { return; }
1928 Scalar_base *get_real() { return this->copy(); }
1929 Scalar_base *get_imag() {
1930 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
1931 return nullptr;
1932 }
1933
1934 void set_maxval() { this->_elem = std::numeric_limits<cytnx_uint32>::max(); }
1935 void set_minval() { this->_elem = std::numeric_limits<cytnx_uint32>::min(); }
1936
1937 void *get_raw_address() const { return (void *)(&this->_elem); }
1938 Scalar_base *astype(const unsigned int &dtype) {
1939 Scalar_base *tmp = __ScII.UScIInit[dtype]();
1940 tmp->assign_selftype(this->_elem);
1941 return tmp;
1942 }
1943 Scalar_base *copy() const {
1944 Uint32Scalar *tmp = new Uint32Scalar(this->_elem);
1945 return tmp;
1946 };
1947 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
1948 };
1949 class Int16Scalar : public Scalar_base {
1950 public:
1951 cytnx_int16 _elem;
1952
1953 Int16Scalar() : _elem(0) { this->_dtype = Type.Int16; };
1954 Int16Scalar(const cytnx_int16 &in) : _elem(0) {
1955 this->_dtype = Type.Int16;
1956 this->_elem = in;
1957 }
1958
1959 cytnx_float to_cytnx_float() const { return this->_elem; };
1960 cytnx_double to_cytnx_double() const { return this->_elem; };
1961 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
1962 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
1963 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
1964 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
1965 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
1966 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
1967 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
1968 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
1969 cytnx_bool to_cytnx_bool() const { return this->_elem; };
1970
1971 void assign_selftype(const cytnx_complex128 &c) {
1972 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1973 }
1974 void assign_selftype(const cytnx_complex64 &c) {
1975 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
1976 }
1977 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
1978 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
1979 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
1980 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
1981 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
1982 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
1983 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
1984 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
1985 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
1986
1987 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_int16(); }
1988 void iadd(const cytnx_complex128 &c) {
1989 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1990 }
1991 void iadd(const cytnx_complex64 &c) {
1992 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
1993 }
1994 void iadd(const cytnx_double &c) { this->_elem += c; }
1995 void iadd(const cytnx_float &c) { this->_elem += c; }
1996 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
1997 void iadd(const cytnx_int64 &c) { this->_elem += c; }
1998 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
1999 void iadd(const cytnx_int32 &c) { this->_elem += c; }
2000 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
2001 void iadd(const cytnx_int16 &c) { this->_elem += c; }
2002 void iadd(const cytnx_bool &c) { this->_elem += c; }
2003
2004 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_int16(); }
2005 void isub(const cytnx_complex128 &c) {
2006 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2007 }
2008 void isub(const cytnx_complex64 &c) {
2009 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2010 }
2011 void isub(const cytnx_double &c) { this->_elem -= c; }
2012 void isub(const cytnx_float &c) { this->_elem -= c; }
2013 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
2014 void isub(const cytnx_int64 &c) { this->_elem -= c; }
2015 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
2016 void isub(const cytnx_int32 &c) { this->_elem -= c; }
2017 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
2018 void isub(const cytnx_int16 &c) { this->_elem -= c; }
2019 void isub(const cytnx_bool &c) { this->_elem -= c; }
2020
2021 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_int16(); }
2022 void imul(const cytnx_complex128 &c) {
2023 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2024 }
2025 void imul(const cytnx_complex64 &c) {
2026 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2027 }
2028 void imul(const cytnx_double &c) { this->_elem *= c; }
2029 void imul(const cytnx_float &c) { this->_elem *= c; }
2030 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
2031 void imul(const cytnx_int64 &c) { this->_elem *= c; }
2032 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
2033 void imul(const cytnx_int32 &c) { this->_elem *= c; }
2034 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
2035 void imul(const cytnx_int16 &c) { this->_elem *= c; }
2036 void imul(const cytnx_bool &c) { this->_elem *= c; }
2037
2038 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_int16(); }
2039 void idiv(const cytnx_complex128 &c) {
2040 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2041 }
2042 void idiv(const cytnx_complex64 &c) {
2043 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2044 }
2045 void idiv(const cytnx_double &c) { this->_elem /= c; }
2046 void idiv(const cytnx_float &c) { this->_elem /= c; }
2047 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
2048 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
2049 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
2050 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
2051 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
2052 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
2053 void idiv(const cytnx_bool &c) { this->_elem /= c; }
2054
2055 void iabs() { this->_elem = std::abs(this->_elem); }
2056 void isqrt() { this->_elem = std::sqrt(this->_elem); }
2057
2058 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_int16(); }
2059 bool less(const cytnx_complex128 &c) {
2060 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2061 return 0;
2062 }
2063 bool less(const cytnx_complex64 &c) {
2064 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2065 return 0;
2066 }
2067 bool less(const cytnx_double &c) { return this->_elem < c; }
2068 bool less(const cytnx_float &c) { return this->_elem < c; }
2069 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
2070 bool less(const cytnx_int64 &c) { return this->_elem < c; }
2071 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
2072 bool less(const cytnx_int32 &c) { return this->_elem < c; }
2073 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
2074 bool less(const cytnx_int16 &c) { return this->_elem < c; }
2075 bool less(const cytnx_bool &c) { return this->_elem < c; }
2076
2077 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_int16(); }
2078 bool greater(const cytnx_complex128 &c) {
2079 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2080 return 0;
2081 }
2082 bool greater(const cytnx_complex64 &c) {
2083 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2084 return 0;
2085 }
2086 bool greater(const cytnx_double &c) { return this->_elem > c; }
2087 bool greater(const cytnx_float &c) { return this->_elem > c; }
2088 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
2089 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
2090 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
2091 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
2092 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
2093 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
2094 bool greater(const cytnx_bool &c) { return this->_elem > c; }
2095
2096 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_int16(); }
2097
2098 void conj_() { return; }
2099 Scalar_base *get_real() { return this->copy(); }
2100 Scalar_base *get_imag() {
2101 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
2102 return nullptr;
2103 }
2104
2105 void set_maxval() { this->_elem = std::numeric_limits<cytnx_int16>::max(); }
2106 void set_minval() { this->_elem = std::numeric_limits<cytnx_int16>::min(); }
2107
2108 void *get_raw_address() const { return (void *)(&this->_elem); }
2109 Scalar_base *astype(const unsigned int &dtype) {
2110 Scalar_base *tmp = __ScII.UScIInit[dtype]();
2111 tmp->assign_selftype(this->_elem);
2112 return tmp;
2113 }
2114 Scalar_base *copy() const {
2115 Int16Scalar *tmp = new Int16Scalar(this->_elem);
2116 return tmp;
2117 };
2118 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
2119 };
2120 class Uint16Scalar : public Scalar_base {
2121 public:
2122 cytnx_uint16 _elem;
2123
2124 Uint16Scalar() : _elem(0) { this->_dtype = Type.Uint16; };
2125 Uint16Scalar(const cytnx_uint16 &in) : _elem(0) {
2126 this->_dtype = Type.Uint16;
2127 this->_elem = in;
2128 }
2129
2130 cytnx_float to_cytnx_float() const { return this->_elem; };
2131 cytnx_double to_cytnx_double() const { return this->_elem; };
2132 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
2133 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
2134 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
2135 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
2136 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
2137 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
2138 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
2139 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
2140 cytnx_bool to_cytnx_bool() const { return this->_elem; };
2141
2142 void assign_selftype(const cytnx_complex128 &c) {
2143 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
2144 }
2145 void assign_selftype(const cytnx_complex64 &c) {
2146 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
2147 }
2148 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
2149 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
2150 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
2151 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
2152 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
2153 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
2154 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
2155 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
2156 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
2157
2158 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_uint16(); }
2159 void iadd(const cytnx_complex128 &c) {
2160 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2161 }
2162 void iadd(const cytnx_complex64 &c) {
2163 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2164 }
2165 void iadd(const cytnx_double &c) { this->_elem += c; }
2166 void iadd(const cytnx_float &c) { this->_elem += c; }
2167 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
2168 void iadd(const cytnx_int64 &c) { this->_elem += c; }
2169 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
2170 void iadd(const cytnx_int32 &c) { this->_elem += c; }
2171 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
2172 void iadd(const cytnx_int16 &c) { this->_elem += c; }
2173 void iadd(const cytnx_bool &c) { this->_elem += c; }
2174
2175 void isub(const Scalar_base *c) { this->_elem += c->to_cytnx_uint16(); }
2176 void isub(const cytnx_complex128 &c) {
2177 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2178 }
2179 void isub(const cytnx_complex64 &c) {
2180 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2181 }
2182 void isub(const cytnx_double &c) { this->_elem += c; }
2183 void isub(const cytnx_float &c) { this->_elem += c; }
2184 void isub(const cytnx_uint64 &c) { this->_elem += c; }
2185 void isub(const cytnx_int64 &c) { this->_elem += c; }
2186 void isub(const cytnx_uint32 &c) { this->_elem += c; }
2187 void isub(const cytnx_int32 &c) { this->_elem += c; }
2188 void isub(const cytnx_uint16 &c) { this->_elem += c; }
2189 void isub(const cytnx_int16 &c) { this->_elem += c; }
2190 void isub(const cytnx_bool &c) { this->_elem += c; }
2191
2192 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_uint16(); }
2193 void imul(const cytnx_complex128 &c) {
2194 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2195 }
2196 void imul(const cytnx_complex64 &c) {
2197 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2198 }
2199 void imul(const cytnx_double &c) { this->_elem *= c; }
2200 void imul(const cytnx_float &c) { this->_elem *= c; }
2201 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
2202 void imul(const cytnx_int64 &c) { this->_elem *= c; }
2203 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
2204 void imul(const cytnx_int32 &c) { this->_elem *= c; }
2205 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
2206 void imul(const cytnx_int16 &c) { this->_elem *= c; }
2207 void imul(const cytnx_bool &c) { this->_elem *= c; }
2208
2209 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_uint16(); }
2210 void idiv(const cytnx_complex128 &c) {
2211 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2212 }
2213 void idiv(const cytnx_complex64 &c) {
2214 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2215 }
2216 void idiv(const cytnx_double &c) { this->_elem /= c; }
2217 void idiv(const cytnx_float &c) { this->_elem /= c; }
2218 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
2219 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
2220 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
2221 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
2222 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
2223 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
2224 void idiv(const cytnx_bool &c) { this->_elem /= c; }
2225
2226 void iabs() { this->_elem = std::abs(this->_elem); }
2227 void isqrt() { this->_elem = std::sqrt(this->_elem); }
2228
2229 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_uint16(); }
2230 bool less(const cytnx_complex128 &c) {
2231 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2232 return 0;
2233 }
2234 bool less(const cytnx_complex64 &c) {
2235 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2236 return 0;
2237 }
2238 bool less(const cytnx_double &c) { return this->_elem < c; }
2239 bool less(const cytnx_float &c) { return this->_elem < c; }
2240 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
2241 bool less(const cytnx_int64 &c) { return this->_elem < c; }
2242 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
2243 bool less(const cytnx_int32 &c) { return this->_elem < c; }
2244 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
2245 bool less(const cytnx_int16 &c) { return this->_elem < c; }
2246 bool less(const cytnx_bool &c) { return this->_elem < c; }
2247
2248 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_uint16(); }
2249 bool greater(const cytnx_complex128 &c) {
2250 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2251 return 0;
2252 }
2253 bool greater(const cytnx_complex64 &c) {
2254 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2255 return 0;
2256 }
2257 bool greater(const cytnx_double &c) { return this->_elem > c; }
2258 bool greater(const cytnx_float &c) { return this->_elem > c; }
2259 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
2260 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
2261 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
2262 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
2263 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
2264 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
2265 bool greater(const cytnx_bool &c) { return this->_elem > c; }
2266
2267 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_uint16(); }
2268
2269 void conj_() { return; }
2270 Scalar_base *get_real() { return this->copy(); }
2271 Scalar_base *get_imag() {
2272 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
2273 return nullptr;
2274 }
2275
2276 void set_maxval() { this->_elem = std::numeric_limits<cytnx_uint16>::max(); }
2277 void set_minval() { this->_elem = std::numeric_limits<cytnx_uint16>::min(); }
2278
2279 void *get_raw_address() const { return (void *)(&this->_elem); }
2280 Scalar_base *astype(const unsigned int &dtype) {
2281 Scalar_base *tmp = __ScII.UScIInit[dtype]();
2282 tmp->assign_selftype(this->_elem);
2283 return tmp;
2284 }
2285 Scalar_base *copy() const {
2286 Uint16Scalar *tmp = new Uint16Scalar(this->_elem);
2287 return tmp;
2288 };
2289 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
2290 };
2291 class BoolScalar : public Scalar_base {
2292 public:
2293 cytnx_bool _elem;
2294
2295 BoolScalar() : _elem(0) { this->_dtype = Type.Bool; };
2296 BoolScalar(const cytnx_bool &in) : _elem(0) {
2297 this->_dtype = Type.Bool;
2298 this->_elem = in;
2299 }
2300
2301 cytnx_float to_cytnx_float() const { return this->_elem; };
2302 cytnx_double to_cytnx_double() const { return this->_elem; };
2303 cytnx_complex64 to_cytnx_complex64() const { return this->_elem; };
2304 cytnx_complex128 to_cytnx_complex128() const { return this->_elem; };
2305 cytnx_int64 to_cytnx_int64() const { return this->_elem; };
2306 cytnx_uint64 to_cytnx_uint64() const { return this->_elem; };
2307 cytnx_int32 to_cytnx_int32() const { return this->_elem; };
2308 cytnx_uint32 to_cytnx_uint32() const { return this->_elem; };
2309 cytnx_int16 to_cytnx_int16() const { return this->_elem; };
2310 cytnx_uint16 to_cytnx_uint16() const { return this->_elem; };
2311 cytnx_bool to_cytnx_bool() const { return this->_elem; };
2312
2313 void assign_selftype(const cytnx_complex128 &c) {
2314 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
2315 }
2316 void assign_selftype(const cytnx_complex64 &c) {
2317 cytnx_error_msg(true, "[ERROR] cannot convert complex to real%s", "\n");
2318 }
2319 void assign_selftype(const cytnx_double &c) { this->_elem = c; }
2320 void assign_selftype(const cytnx_float &c) { this->_elem = c; }
2321 void assign_selftype(const cytnx_uint64 &c) { this->_elem = c; }
2322 void assign_selftype(const cytnx_int64 &c) { this->_elem = c; }
2323 void assign_selftype(const cytnx_uint32 &c) { this->_elem = c; }
2324 void assign_selftype(const cytnx_int32 &c) { this->_elem = c; }
2325 void assign_selftype(const cytnx_uint16 &c) { this->_elem = c; }
2326 void assign_selftype(const cytnx_int16 &c) { this->_elem = c; }
2327 void assign_selftype(const cytnx_bool &c) { this->_elem = c; }
2328
2329 void iadd(const Scalar_base *c) { this->_elem += c->to_cytnx_bool(); }
2330 void iadd(const cytnx_complex128 &c) {
2331 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2332 }
2333 void iadd(const cytnx_complex64 &c) {
2334 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2335 }
2336 void iadd(const cytnx_double &c) { this->_elem += c; }
2337 void iadd(const cytnx_float &c) { this->_elem += c; }
2338 void iadd(const cytnx_uint64 &c) { this->_elem += c; }
2339 void iadd(const cytnx_int64 &c) { this->_elem += c; }
2340 void iadd(const cytnx_uint32 &c) { this->_elem += c; }
2341 void iadd(const cytnx_int32 &c) { this->_elem += c; }
2342 void iadd(const cytnx_uint16 &c) { this->_elem += c; }
2343 void iadd(const cytnx_int16 &c) { this->_elem += c; }
2344 void iadd(const cytnx_bool &c) { this->_elem += c; }
2345
2346 void isub(const Scalar_base *c) { this->_elem -= c->to_cytnx_bool(); }
2347 void isub(const cytnx_complex128 &c) {
2348 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2349 }
2350 void isub(const cytnx_complex64 &c) {
2351 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2352 }
2353 void isub(const cytnx_double &c) { this->_elem -= c; }
2354 void isub(const cytnx_float &c) { this->_elem -= c; }
2355 void isub(const cytnx_uint64 &c) { this->_elem -= c; }
2356 void isub(const cytnx_int64 &c) { this->_elem -= c; }
2357 void isub(const cytnx_uint32 &c) { this->_elem -= c; }
2358 void isub(const cytnx_int32 &c) { this->_elem -= c; }
2359 void isub(const cytnx_uint16 &c) { this->_elem -= c; }
2360 void isub(const cytnx_int16 &c) { this->_elem -= c; }
2361 void isub(const cytnx_bool &c) { this->_elem -= c; }
2362
2363 void imul(const Scalar_base *c) { this->_elem *= c->to_cytnx_bool(); }
2364 void imul(const cytnx_complex128 &c) {
2365 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2366 }
2367 void imul(const cytnx_complex64 &c) {
2368 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2369 }
2370 void imul(const cytnx_double &c) { this->_elem *= c; }
2371 void imul(const cytnx_float &c) { this->_elem *= c; }
2372 void imul(const cytnx_uint64 &c) { this->_elem *= c; }
2373 void imul(const cytnx_int64 &c) { this->_elem *= c; }
2374 void imul(const cytnx_uint32 &c) { this->_elem *= c; }
2375 void imul(const cytnx_int32 &c) { this->_elem *= c; }
2376 void imul(const cytnx_uint16 &c) { this->_elem *= c; }
2377 void imul(const cytnx_int16 &c) { this->_elem *= c; }
2378 void imul(const cytnx_bool &c) { this->_elem *= c; }
2379
2380 void idiv(const Scalar_base *c) { this->_elem /= c->to_cytnx_bool(); }
2381 void idiv(const cytnx_complex128 &c) {
2382 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2383 }
2384 void idiv(const cytnx_complex64 &c) {
2385 cytnx_error_msg(true, "[ERROR] cannot operate real and complex values%s", "\n");
2386 }
2387 void idiv(const cytnx_double &c) { this->_elem /= c; }
2388 void idiv(const cytnx_float &c) { this->_elem /= c; }
2389 void idiv(const cytnx_uint64 &c) { this->_elem /= c; }
2390 void idiv(const cytnx_int64 &c) { this->_elem /= c; }
2391 void idiv(const cytnx_uint32 &c) { this->_elem /= c; }
2392 void idiv(const cytnx_int32 &c) { this->_elem /= c; }
2393 void idiv(const cytnx_uint16 &c) { this->_elem /= c; }
2394 void idiv(const cytnx_int16 &c) { this->_elem /= c; }
2395 void idiv(const cytnx_bool &c) { this->_elem /= c; }
2396
2397 void iabs() { this->_elem = std::abs(this->_elem); }
2398 void isqrt() { this->_elem = std::sqrt(this->_elem); }
2399
2400 bool less(const Scalar_base *c) { return this->_elem < c->to_cytnx_bool(); }
2401 bool less(const cytnx_complex128 &c) {
2402 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2403 return 0;
2404 }
2405 bool less(const cytnx_complex64 &c) {
2406 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2407 return 0;
2408 }
2409 bool less(const cytnx_double &c) { return this->_elem < c; }
2410 bool less(const cytnx_float &c) { return this->_elem < c; }
2411 bool less(const cytnx_uint64 &c) { return this->_elem < c; }
2412 bool less(const cytnx_int64 &c) { return this->_elem < c; }
2413 bool less(const cytnx_uint32 &c) { return this->_elem < c; }
2414 bool less(const cytnx_int32 &c) { return this->_elem < c; }
2415 bool less(const cytnx_uint16 &c) { return this->_elem < c; }
2416 bool less(const cytnx_int16 &c) { return this->_elem < c; }
2417 bool less(const cytnx_bool &c) { return this->_elem < c; }
2418
2419 bool greater(const Scalar_base *c) { return this->_elem > c->to_cytnx_bool(); }
2420 bool greater(const cytnx_complex128 &c) {
2421 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2422 return 0;
2423 }
2424 bool greater(const cytnx_complex64 &c) {
2425 cytnx_error_msg(true, "[ERROR] comparison not supported for complex type%s", "\n");
2426 return 0;
2427 }
2428 bool greater(const cytnx_double &c) { return this->_elem > c; }
2429 bool greater(const cytnx_float &c) { return this->_elem > c; }
2430 bool greater(const cytnx_uint64 &c) { return this->_elem > c; }
2431 bool greater(const cytnx_int64 &c) { return this->_elem > c; }
2432 bool greater(const cytnx_uint32 &c) { return this->_elem > c; }
2433 bool greater(const cytnx_int32 &c) { return this->_elem > c; }
2434 bool greater(const cytnx_uint16 &c) { return this->_elem > c; }
2435 bool greater(const cytnx_int16 &c) { return this->_elem > c; }
2436 bool greater(const cytnx_bool &c) { return this->_elem > c; }
2437
2438 bool eq(const Scalar_base *c) { return this->_elem == c->to_cytnx_bool(); }
2439
2440 void conj_() { return; }
2441 Scalar_base *get_real() { return this->copy(); }
2442 Scalar_base *get_imag() {
2443 cytnx_error_msg(true, "[ERROR] real type Scalar does not have imag part!%s", "\n");
2444 return nullptr;
2445 }
2446
2447 void set_maxval() { this->_elem = true; }
2448 void set_minval() { this->_elem = false; }
2449
2450 void *get_raw_address() const { return (void *)(&this->_elem); }
2451 Scalar_base *astype(const unsigned int &dtype) {
2452 Scalar_base *tmp = __ScII.UScIInit[dtype]();
2453 tmp->assign_selftype(this->_elem);
2454 return tmp;
2455 }
2456 Scalar_base *copy() const {
2457 BoolScalar *tmp = new BoolScalar(this->_elem);
2458 return tmp;
2459 };
2460 void print(std::ostream &os) const { os << "< " << this->_elem << " >"; };
2461 };
2462
2464
2470 class Scalar {
2471 public:
2473 struct Sproxy {
2474 boost::intrusive_ptr<Storage_base> _insimpl;
2475 cytnx_uint64 _loc;
2476 Sproxy() {}
2477 Sproxy(boost::intrusive_ptr<Storage_base> _ptr, const cytnx_uint64 &idx)
2478 : _insimpl(_ptr), _loc(idx) {}
2479
2480 Sproxy(const Sproxy &rhs) {
2481 this->_insimpl = rhs._insimpl;
2482 this->_loc = rhs._loc;
2483 }
2484
2485 // When used to set elems:
2486 Sproxy &operator=(const Scalar &rc);
2487 Sproxy &operator=(const cytnx_complex128 &rc);
2488 Sproxy &operator=(const cytnx_complex64 &rc);
2489 Sproxy &operator=(const cytnx_double &rc);
2490 Sproxy &operator=(const cytnx_float &rc);
2491 Sproxy &operator=(const cytnx_uint64 &rc);
2492 Sproxy &operator=(const cytnx_int64 &rc);
2493 Sproxy &operator=(const cytnx_uint32 &rc);
2494 Sproxy &operator=(const cytnx_int32 &rc);
2495 Sproxy &operator=(const cytnx_uint16 &rc);
2496 Sproxy &operator=(const cytnx_int16 &rc);
2497 Sproxy &operator=(const cytnx_bool &rc);
2498
2499 Sproxy &operator=(const Sproxy &rc);
2500
2501 Sproxy copy() const {
2502 Sproxy out = *this;
2503 return out;
2504 }
2505
2506 Scalar real();
2507 Scalar imag();
2508 bool exists() const;
2509
2510 // When used to get elements:
2511 // operator Scalar() const;
2512 };
2513
2514 Scalar_base *_impl;
2516
2518 Scalar() : _impl(new Scalar_base()){};
2519
2520 // init!!
2522 Scalar(const cytnx_complex128 &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2523
2525 Scalar(const cytnx_complex64 &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2526
2528 Scalar(const cytnx_double &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2529
2531 Scalar(const cytnx_float &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2532
2534 Scalar(const cytnx_uint64 &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2535
2537 Scalar(const cytnx_int64 &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2538
2540 Scalar(const cytnx_uint32 &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2541
2543 Scalar(const cytnx_int32 &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2544
2546 Scalar(const cytnx_uint16 &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2547
2549 Scalar(const cytnx_int16 &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2550
2552 Scalar(const cytnx_bool &in) : _impl(new Scalar_base()) { this->Init_by_number(in); }
2553
2562 static Scalar maxval(const unsigned int &dtype) {
2563 Scalar out(0, dtype);
2564 out._impl->set_maxval();
2565 return out;
2566 }
2567
2576 static Scalar minval(const unsigned int &dtype) {
2577 Scalar out(0, dtype);
2578 out._impl->set_minval();
2579 return out;
2580 }
2581
2591 template <class T>
2592 Scalar(const T &in, const unsigned int &dtype) : _impl(new Scalar_base()) {
2593 if (this->_impl != nullptr) delete this->_impl;
2594 this->_impl = __ScII.UScIInit[dtype]();
2595 this->_impl->assign_selftype(in);
2596 };
2597
2599 // move sproxy when use to get elements here.
2600 Scalar(const Sproxy &prox);
2601
2602 //[Internal!!]
2603 Scalar(Scalar_base *in) { this->_impl = in; }
2605
2606 // specialization of init:
2608 void Init_by_number(const cytnx_complex128 &in) {
2609 if (this->_impl != nullptr) delete this->_impl;
2610 this->_impl = new ComplexDoubleScalar(in);
2611 };
2612 void Init_by_number(const cytnx_complex64 &in) {
2613 if (this->_impl != nullptr) delete this->_impl;
2614 this->_impl = new ComplexFloatScalar(in);
2615 };
2616 void Init_by_number(const cytnx_double &in) {
2617 if (this->_impl != nullptr) delete this->_impl;
2618 this->_impl = new DoubleScalar(in);
2619 }
2620 void Init_by_number(const cytnx_float &in) {
2621 if (this->_impl != nullptr) delete this->_impl;
2622 this->_impl = new FloatScalar(in);
2623 }
2624 void Init_by_number(const cytnx_int64 &in) {
2625 if (this->_impl != nullptr) delete this->_impl;
2626 this->_impl = new Int64Scalar(in);
2627 }
2628 void Init_by_number(const cytnx_uint64 &in) {
2629 if (this->_impl != nullptr) delete this->_impl;
2630 this->_impl = new Uint64Scalar(in);
2631 }
2632 void Init_by_number(const cytnx_int32 &in) {
2633 if (this->_impl != nullptr) delete this->_impl;
2634 this->_impl = new Int32Scalar(in);
2635 }
2636 void Init_by_number(const cytnx_uint32 &in) {
2637 if (this->_impl != nullptr) delete this->_impl;
2638 this->_impl = new Uint32Scalar(in);
2639 }
2640 void Init_by_number(const cytnx_int16 &in) {
2641 if (this->_impl != nullptr) delete this->_impl;
2642 this->_impl = new Int16Scalar(in);
2643 }
2644 void Init_by_number(const cytnx_uint16 &in) {
2645 if (this->_impl != nullptr) delete this->_impl;
2646 this->_impl = new Uint16Scalar(in);
2647 }
2648 void Init_by_number(const cytnx_bool &in) {
2649 if (this->_impl != nullptr) delete this->_impl;
2650 this->_impl = new BoolScalar(in);
2651 }
2652
2653 // The copy constructor
2654 Scalar(const Scalar &rhs) : _impl(new Scalar_base()) {
2655 if (this->_impl != nullptr) delete this->_impl;
2656
2657 this->_impl = rhs._impl->copy();
2658 }
2660
2662 Scalar &operator=(const Scalar &rhs) {
2663 if (this->_impl != nullptr) delete this->_impl;
2664
2665 this->_impl = rhs._impl->copy();
2666 return *this;
2667 };
2668
2669 // copy assignment [Number]:
2674 this->Init_by_number(rhs);
2675 return *this;
2676 }
2677
2682 this->Init_by_number(rhs);
2683 return *this;
2684 }
2685
2690 this->Init_by_number(rhs);
2691 return *this;
2692 }
2693
2698 this->Init_by_number(rhs);
2699 return *this;
2700 }
2701
2706 this->Init_by_number(rhs);
2707 return *this;
2708 }
2709
2714 this->Init_by_number(rhs);
2715 return *this;
2716 }
2717
2722 this->Init_by_number(rhs);
2723 return *this;
2724 }
2725
2730 this->Init_by_number(rhs);
2731 return *this;
2732 }
2733
2738 this->Init_by_number(rhs);
2739 return *this;
2740 }
2741
2746 this->Init_by_number(rhs);
2747 return *this;
2748 }
2749
2754 this->Init_by_number(rhs);
2755 return *this;
2756 }
2757
2766 Scalar astype(const unsigned int &dtype) const {
2767 Scalar out(this->_impl->astype(dtype));
2768 return out;
2769 }
2770
2776 Scalar conj() const {
2777 Scalar out = *this;
2778 out._impl->conj_();
2779 return out;
2780 }
2781
2787 Scalar imag() const { return Scalar(this->_impl->get_imag()); }
2788
2794 Scalar real() const { return Scalar(this->_impl->get_real()); }
2795 // Scalar& set_imag(const Scalar &in){ return *this;}
2796 // Scalar& set_real(const Scalar &in){ return *this;}
2797
2801 int dtype() const { return this->_impl->_dtype; }
2802
2803 // print()
2807 void print() const {
2808 this->_impl->print(std::cout);
2809 std::cout << std::string(" Scalar dtype: [") << Type.getname(this->_impl->_dtype)
2810 << std::string("]") << std::endl;
2811 }
2812
2813 // casting
2815 explicit operator cytnx_double() const { return this->_impl->to_cytnx_double(); }
2816
2818 explicit operator cytnx_float() const { return this->_impl->to_cytnx_float(); }
2819
2821 explicit operator cytnx_uint64() const { return this->_impl->to_cytnx_uint64(); }
2822
2824 explicit operator cytnx_int64() const { return this->_impl->to_cytnx_int64(); }
2825
2827 explicit operator cytnx_uint32() const { return this->_impl->to_cytnx_uint32(); }
2828
2830 explicit operator cytnx_int32() const { return this->_impl->to_cytnx_int32(); }
2831
2833 explicit operator cytnx_uint16() const { return this->_impl->to_cytnx_uint16(); }
2834
2836 explicit operator cytnx_int16() const { return this->_impl->to_cytnx_int16(); }
2837
2839 explicit operator cytnx_bool() const { return this->_impl->to_cytnx_bool(); }
2840
2842 // destructor
2843 ~Scalar() {
2844 if (this->_impl != nullptr) delete this->_impl;
2845 };
2847
2848 // arithmetic:
2850 template <class T>
2851 void operator+=(const T &rc) {
2852 this->_impl->iadd(rc);
2853 }
2854
2856 void operator+=(const Scalar &rhs) { this->_impl->iadd(rhs._impl); }
2857
2860 template <class T>
2861 void operator-=(const T &rc) {
2862 this->_impl->isub(rc);
2863 }
2864
2866 void operator-=(const Scalar &rhs) { this->_impl->isub(rhs._impl); }
2867 template <class T>
2868
2871 void operator*=(const T &rc) {
2872 this->_impl->imul(rc);
2873 }
2874
2876 void operator*=(const Scalar &rhs) { this->_impl->imul(rhs._impl); }
2877 template <class T>
2878
2882 void operator/=(const T &rc) {
2883 this->_impl->idiv(rc);
2884 }
2885
2889 void operator/=(const Scalar &rhs) { this->_impl->idiv(rhs._impl); }
2890
2892 void iabs() { this->_impl->iabs(); }
2893
2895 void isqrt() { this->_impl->isqrt(); }
2896
2903 Scalar abs() const {
2904 Scalar out = *this;
2905 out._impl->iabs();
2906 return out.real();
2907 }
2908
2915 Scalar sqrt() const {
2916 Scalar out = *this;
2917 out._impl->isqrt();
2918 return out;
2919 }
2920
2921 // comparison <
2928 template <class T>
2929 bool less(const T &rc) const {
2930 Scalar tmp;
2931 int rid = Type.cy_typeid(rc);
2932 if (rid < this->dtype()) {
2933 tmp = this->astype(rid);
2934 return tmp._impl->less(rc);
2935 } else {
2936 return this->_impl->less(rc);
2937 }
2938 }
2939
2946 bool less(const Scalar &rhs) const {
2947 Scalar tmp;
2948 if (rhs.dtype() < this->dtype()) {
2949 tmp = this->astype(rhs.dtype());
2950 return tmp._impl->less(rhs._impl);
2951 } else {
2952 return this->_impl->less(rhs._impl);
2953 }
2954 }
2955
2956 // comparison <=
2957
2965 template <class T>
2966 bool leq(const T &rc) const {
2967 Scalar tmp;
2968 int rid = Type.cy_typeid(rc);
2969 if (rid < this->dtype()) {
2970 tmp = this->astype(rid);
2971 return !(tmp._impl->greater(rc));
2972 } else {
2973 return !(this->_impl->greater(rc));
2974 }
2975 }
2976
2983 bool leq(const Scalar &rhs) const {
2984 Scalar tmp;
2985 if (rhs.dtype() < this->dtype()) {
2986 tmp = this->astype(rhs.dtype());
2987 return !(tmp._impl->greater(rhs._impl));
2988 } else {
2989 return !(this->_impl->greater(rhs._impl));
2990 }
2991 }
2992
2993 // comparison >
3000 template <class T>
3001 bool greater(const T &rc) const {
3002 Scalar tmp;
3003 int rid = Type.cy_typeid(rc);
3004 if (rid < this->dtype()) {
3005 tmp = this->astype(rid);
3006 return tmp._impl->greater(rc);
3007 } else {
3008 return this->_impl->greater(rc);
3009 }
3010 }
3011
3018 bool greater(const Scalar &rhs) const {
3019 Scalar tmp;
3020 if (rhs.dtype() < this->dtype()) {
3021 tmp = this->astype(rhs.dtype());
3022 return tmp._impl->greater(rhs._impl);
3023 } else {
3024 return this->_impl->greater(rhs._impl);
3025 }
3026 }
3027
3028 // comparison >=
3029
3037 template <class T>
3038 bool geq(const T &rc) const {
3039 Scalar tmp;
3040 int rid = Type.cy_typeid(rc);
3041 if (rid < this->dtype()) {
3042 tmp = this->astype(rid);
3043 return !(tmp._impl->less(rc));
3044 } else {
3045 return !(this->_impl->less(rc));
3046 }
3047 }
3048
3055 bool geq(const Scalar &rhs) const {
3056 Scalar tmp;
3057 if (rhs.dtype() < this->dtype()) {
3058 tmp = this->astype(rhs.dtype());
3059 return !(tmp._impl->less(rhs._impl));
3060 } else {
3061 return !(this->_impl->less(rhs._impl));
3062 }
3063 }
3064
3065 // comparison ==
3066
3073 template <class T>
3074 bool eq(const T &rc) const {
3075 Scalar tmp;
3076 int rid = Type.cy_typeid(rc);
3077 if (rid < this->dtype()) {
3078 tmp = this->astype(rid);
3079 return tmp._impl->eq(rc);
3080 } else {
3081 return this->_impl->eq(rc);
3082 }
3083 }
3084
3091 bool eq(const Scalar &rhs) const {
3092 Scalar tmp;
3093 if (rhs.dtype() < this->dtype()) {
3094 tmp = this->astype(rhs.dtype());
3095 return tmp._impl->eq(rhs._impl);
3096 } else {
3097 return this->_impl->eq(rhs._impl);
3098 }
3099 }
3100
3101 // radd: Scalar + c
3102
3107 template <class T>
3108 Scalar radd(const T &rc) const {
3109 Scalar out;
3110 int rid = Type.cy_typeid(rc);
3111 if (this->dtype() < rid) {
3112 out = *this;
3113 } else {
3114 out = this->astype(rid);
3115 }
3116 out._impl->iadd(rc);
3117 return out;
3118 }
3119
3124 Scalar radd(const Scalar &rhs) const {
3125 Scalar out;
3126 if (this->dtype() < rhs.dtype()) {
3127 out = *this;
3128 } else {
3129 out = this->astype(rhs.dtype());
3130 }
3131 out._impl->iadd(rhs._impl);
3132 return out;
3133 }
3134
3135 // rmul: Scalar * c
3136
3141 template <class T>
3142 Scalar rmul(const T &rc) const {
3143 Scalar out;
3144 int rid = Type.cy_typeid(rc);
3145 if (this->dtype() < rid) {
3146 out = *this;
3147 } else {
3148 out = this->astype(rid);
3149 }
3150 out._impl->imul(rc);
3151 return out;
3152 }
3153
3158 Scalar rmul(const Scalar &rhs) const {
3159 Scalar out;
3160 if (this->dtype() < rhs.dtype()) {
3161 out = *this;
3162 } else {
3163 out = this->astype(rhs.dtype());
3164 }
3165 out._impl->imul(rhs._impl);
3166 return out;
3167 }
3168
3169 // rsub: Scalar - c
3170
3175 template <class T>
3176 Scalar rsub(const T &rc) const {
3177 Scalar out;
3178 int rid = Type.cy_typeid(rc);
3179 if (this->dtype() < rid) {
3180 out = *this;
3181 } else {
3182 out = this->astype(rid);
3183 }
3184 out._impl->isub(rc);
3185 return out;
3186 }
3187
3192 Scalar rsub(const Scalar &rhs) const {
3193 Scalar out;
3194 if (this->dtype() < rhs.dtype()) {
3195 out = *this;
3196 } else {
3197 out = this->astype(rhs.dtype());
3198 }
3199 out._impl->isub(rhs._impl);
3200 return out;
3201 }
3202
3203 // rdiv: Scalar / c
3204
3209 template <class T>
3210 Scalar rdiv(const T &rc) const {
3211 Scalar out;
3212 int rid = Type.cy_typeid(rc);
3213 if (this->dtype() < rid) {
3214 out = *this;
3215 } else {
3216 out = this->astype(rid);
3217 }
3218 out._impl->idiv(rc);
3219 return out;
3220 }
3221
3226 Scalar rdiv(const Scalar &rhs) const {
3227 Scalar out;
3228 if (this->dtype() < rhs.dtype()) {
3229 out = *this;
3230 } else {
3231 out = this->astype(rhs.dtype());
3232 }
3233 out._impl->idiv(rhs._impl);
3234 return out;
3235 }
3236
3237 /*
3238 //operator:
3239 template<class T>
3240 Scalar operator+(const T &rc){
3241 return this->radd(rc);
3242 }
3243 template<class T>
3244 Scalar operator*(const T &rc){
3245 return this->rmul(rc);
3246 }
3247 template<class T>
3248 Scalar operator-(const T &rc){
3249 return this->rsub(rc);
3250 }
3251 template<class T>
3252 Scalar operator/(const T &rc){
3253 return this->rdiv(rc);
3254 }
3255
3256 template<class T>
3257 bool operator<(const T &rc){
3258 return this->less(rc);
3259 }
3260
3261 template<class T>
3262 bool operator>(const T &rc){
3263 return this->greater(rc);
3264 }
3265
3266
3267 template<class T>
3268 bool operator<=(const T &rc){
3269 return this->leq(rc);
3270 }
3271
3272 template<class T>
3273 bool operator>=(const T &rc){
3274 return this->geq(rc);
3275 }
3276 */
3277 };
3278
3279 // ladd: c + Scalar:
3280
3287 Scalar operator+(const Scalar &lc, const Scalar &rs); //{return rs.radd(lc);};
3288
3289 // lmul c * Scalar;
3296 Scalar operator*(const Scalar &lc, const Scalar &rs); //{return rs.rmul(lc);};
3297
3298 // lsub c * Scalar;
3305 Scalar operator-(const Scalar &lc, const Scalar &rs); //{return Scalar(lc).rsub(rs);};
3306
3307 // ldiv c / Scalar;
3314 Scalar operator/(const Scalar &lc, const Scalar &rs); //{return Scalar(lc).rdiv(rs);};
3315
3316 // lless c < Scalar;
3323 bool operator<(const Scalar &lc, const Scalar &rs);
3324
3325 // lgreater c > Scalar;
3332 bool operator>(const Scalar &lc, const Scalar &rs);
3333
3334 // lless c <= Scalar;
3341 bool operator<=(const Scalar &lc, const Scalar &rs);
3342
3343 // lgreater c >= Scalar;
3350 bool operator>=(const Scalar &lc, const Scalar &rs);
3351
3352 // eq c == Scalar;
3359 bool operator==(const Scalar &lc, const Scalar &rs);
3360
3361 // abs:
3362
3369 Scalar abs(const Scalar &c);
3370
3371 // sqrt:
3378 Scalar sqrt(const Scalar &c);
3379
3380 // complex conversion:
3383
3386
3388 std::ostream &operator<<(std::ostream &os, const Scalar &in);
3390
3391} // namespace cytnx
3392
3393#endif
A class to represent a scalar.
Definition Scalar.hpp:2470
void operator-=(const T &rc)
The subtraction assignment operator of the Scalar class with a given number (template).
Definition Scalar.hpp:2861
Scalar & operator=(const Scalar &rhs)
The copy assignment of the Scalar class.
Definition Scalar.hpp:2662
bool less(const Scalar &rhs) const
Return whether the current Scalar is less than a given Scalar rhs.
Definition Scalar.hpp:2946
bool leq(const T &rc) const
Return whether the current Scalar is less than or equal to a given template number rc.
Definition Scalar.hpp:2966
Scalar(const cytnx_int64 &in)
init a Scalar with a cytnx::cytnx_int64
Definition Scalar.hpp:2537
Scalar & operator=(const cytnx_bool &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_bool rhs.
Definition Scalar.hpp:2753
Scalar(const cytnx_double &in)
init a Scalar with a cytnx::cytnx_double
Definition Scalar.hpp:2528
Scalar(const T &in, const unsigned int &dtype)
The constructor of the Scalar class.
Definition Scalar.hpp:2592
Scalar & operator=(const cytnx_float &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_float rhs.
Definition Scalar.hpp:2697
Scalar(const cytnx_int16 &in)
init a Scalar with a cytnx::cytnx_int16
Definition Scalar.hpp:2549
Scalar rmul(const T &rc) const
Return the multiplication of the current Scalar and a given template number rc.
Definition Scalar.hpp:3142
static Scalar minval(const unsigned int &dtype)
Get the min value of the Scalar with the given dtype.
Definition Scalar.hpp:2576
Scalar & operator=(const cytnx_uint16 &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_uint16 rhs.
Definition Scalar.hpp:2737
void operator+=(const T &rc)
The addition assignment operator of the Scalar class with a given number (template).
Definition Scalar.hpp:2851
static Scalar maxval(const unsigned int &dtype)
Get the max value of the Scalar with the given dtype.
Definition Scalar.hpp:2562
Scalar & operator=(const cytnx_int64 &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_int64 rhs.
Definition Scalar.hpp:2713
Scalar()
default constructor
Definition Scalar.hpp:2518
Scalar rsub(const T &rc) const
Return the subtraction of the current Scalar and a given template number rc.
Definition Scalar.hpp:3176
Scalar(const cytnx_int32 &in)
init a Scalar with a cytnx::cytnx_int32
Definition Scalar.hpp:2543
Scalar & operator=(const cytnx_int16 &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_int16 rhs.
Definition Scalar.hpp:2745
Scalar(const cytnx_uint32 &in)
init a Scalar with a cytnx::cytnx_uint32
Definition Scalar.hpp:2540
bool less(const T &rc) const
Return whether the current Scalar is less than a given template number rc.
Definition Scalar.hpp:2929
Scalar(const cytnx_uint16 &in)
init a Scalar with a cytnx::cytnx_uint16
Definition Scalar.hpp:2546
Scalar & operator=(const cytnx_uint64 &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_uint64 rhs.
Definition Scalar.hpp:2705
Scalar real() const
Get the real part of the Scalar. That means return if the Scalar is .
Definition Scalar.hpp:2794
int dtype() const
Get the dtype of the Scalar (see cytnx::Type for more details).
Definition Scalar.hpp:2801
void operator/=(const T &rc)
The division assignment operator of the Scalar class with a given number (template).
Definition Scalar.hpp:2882
Scalar(const cytnx_float &in)
init a Scalar with a cytnx::cytnx_float
Definition Scalar.hpp:2531
Scalar & operator=(const cytnx_double &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_double rhs.
Definition Scalar.hpp:2689
Scalar sqrt() const
The member function to get the square root of the Scalar.
Definition Scalar.hpp:2915
Scalar(const cytnx_complex64 &in)
init a Scalar with a cytnx::cytnx_complex64
Definition Scalar.hpp:2525
void operator*=(const T &rc)
The multiplication assignment operator of the Scalar class with a given number (template).
Definition Scalar.hpp:2871
bool geq(const Scalar &rhs) const
Return whether the current Scalar is greater than or equal to a given Scalar rhs.
Definition Scalar.hpp:3055
Scalar & operator=(const cytnx_int32 &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_int32 rhs.
Definition Scalar.hpp:2729
bool greater(const T &rc) const
Return whether the current Scalar is greater than a given template number rc.
Definition Scalar.hpp:3001
Scalar(const cytnx_uint64 &in)
init a Scalar with a cytnx::cytnx_uint64
Definition Scalar.hpp:2534
Scalar conj() const
Get the conjugate of the Scalar. That means return if the Scalar is .
Definition Scalar.hpp:2776
void operator-=(const Scalar &rhs)
The subtraction assignment operator of the Scalar class with a given Scalar.
Definition Scalar.hpp:2866
Scalar imag() const
Get the imaginary part of the Scalar. That means return if the Scalar is .
Definition Scalar.hpp:2787
bool leq(const Scalar &rhs) const
Return whether the current Scalar is less than or equal to a given Scalar rhs.
Definition Scalar.hpp:2983
void iabs()
Set the Scalar to absolute value. (inplace)
Definition Scalar.hpp:2892
Scalar abs() const
The member function to get the absolute value of the Scalar.
Definition Scalar.hpp:2903
Scalar rdiv(const T &rc) const
Return the division of the current Scalar and a given template number rc.
Definition Scalar.hpp:3210
bool eq(const T &rc) const
Return whether the current Scalar is equal to a given template number rc.
Definition Scalar.hpp:3074
void print() const
Print the Scalar to the standard output.
Definition Scalar.hpp:2807
bool greater(const Scalar &rhs) const
Return whether the current Scalar is greater than a given Scalar rhs.
Definition Scalar.hpp:3018
bool geq(const T &rc) const
Return whether the current Scalar is greater than or equal to a given template number rc.
Definition Scalar.hpp:3038
void isqrt()
Set the Scalar to square root. (inplace)
Definition Scalar.hpp:2895
Scalar rmul(const Scalar &rhs) const
Return the multiplication of the current Scalar and a given Scalar rhs.
Definition Scalar.hpp:3158
Scalar & operator=(const cytnx_uint32 &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_uint32 rhs.
Definition Scalar.hpp:2721
Scalar & operator=(const cytnx_complex128 &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_complex128 rhs.
Definition Scalar.hpp:2673
Scalar(const cytnx_bool &in)
init a Scalar with a cytnx::cytnx_bool
Definition Scalar.hpp:2552
bool eq(const Scalar &rhs) const
Return whether the current Scalar is equal to a given Scalar rhs.
Definition Scalar.hpp:3091
Scalar rdiv(const Scalar &rhs) const
Return the division of the current Scalar and a given Scalar rhs.
Definition Scalar.hpp:3226
void operator+=(const Scalar &rhs)
The addition assignment operator of the Scalar class with a given Scalar.
Definition Scalar.hpp:2856
void operator*=(const Scalar &rhs)
The multiplication assignment operator of the Scalar class with a given Scalar.
Definition Scalar.hpp:2876
void operator/=(const Scalar &rhs)
The division assignment operator of the Scalar class with a given Scalar.
Definition Scalar.hpp:2889
Scalar(const cytnx_complex128 &in)
init a Scalar with a cytnx::cytnx_complex128
Definition Scalar.hpp:2522
Scalar & operator=(const cytnx_complex64 &rhs)
The copy assignment operator of the Scalar class with a given number cytnx::cytnx_complex64 rhs.
Definition Scalar.hpp:2681
Scalar rsub(const Scalar &rhs) const
Return the subtraction of the current Scalar and a given Scalar rhs.
Definition Scalar.hpp:3192
Scalar radd(const Scalar &rhs) const
Return the addition of the current Scalar and a given Scalar rhs.
Definition Scalar.hpp:3124
Scalar radd(const T &rc) const
Return the addition of the current Scalar and a given template number rc.
Definition Scalar.hpp:3108
Scalar astype(const unsigned int &dtype) const
Type conversion function.
Definition Scalar.hpp:2766
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:16
Definition Accessor.hpp:12
cytnx_complex128 complex128(const Scalar &in)
Convert a Scalar object to a cytnx::complex128.
cytnx::UniTensor operator*(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The multiplication operator between two UniTensor.
bool operator<=(const Scalar &lc, const Scalar &rs)
The less-than-or-equal operator between two Scalar objects.
double cytnx_double
Definition Type.hpp:43
uint32_t cytnx_uint32
Definition Type.hpp:46
bool cytnx_bool
Definition Type.hpp:54
std::complex< double > cytnx_complex128
Definition Type.hpp:53
float cytnx_float
Definition Type.hpp:44
int16_t cytnx_int16
Definition Type.hpp:50
Scalar abs(const Scalar &c)
Return the absolute value of a Scalar object.
std::complex< float > cytnx_complex64
Definition Type.hpp:52
cytnx::UniTensor operator-(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The subtraction operator between two UniTensor.
int32_t cytnx_int32
Definition Type.hpp:49
Tensor operator==(const Tensor &Lt, const Tensor &Rt)
The comparison operator for Tensor.
uint16_t cytnx_uint16
Definition Type.hpp:47
uint64_t cytnx_uint64
Definition Type.hpp:45
cytnx_complex64 complex64(const Scalar &in)
Convert a Scalar object to a cytnx::complex64.
int64_t cytnx_int64
Definition Type.hpp:48
Type_class Type
data type
Scalar sqrt(const Scalar &c)
Return the square root of a Scalar object.
cytnx::UniTensor operator+(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The addtion operator between two UniTensor.
bool operator>(const Scalar &lc, const Scalar &rs)
The greater-than operator between two Scalar objects.
cytnx::UniTensor operator/(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The division operator between two UniTensor.
bool operator>=(const Scalar &lc, const Scalar &rs)
The greater-than-or-equal operator between two Scalar objects.
bool operator<(const Scalar &lc, const Scalar &rs)
The less-than operator between two Scalar objects.
tmp
Definition sp.py:8