9#include <initializer_list>
20#define STORAGE_DEFT_SZ 2
25 class Storage_base :
public intrusive_ptr_base<Storage_base> {
30 unsigned long long len;
31 unsigned long long cap;
35 Storage_base() : cap(0), len(0), Mem(NULL), dtype(0), device(-1){};
38 Storage_base(
const unsigned long long &len_in,
const int &device,
const bool &init_zero=
true);
40 Storage_base(Storage_base &Rhs);
41 Storage_base &operator=(Storage_base &Rhs);
42 boost::intrusive_ptr<Storage_base> astype(
const unsigned int &dtype);
45 std::string dtype_str()
const;
46 std::string device_str()
const;
47 const unsigned long long &capacity()
const {
return this->cap; }
48 const unsigned long long &size()
const {
return this->len; }
52 T &at(
const cytnx_uint64 &idx)
const;
60 void *data()
const {
return this->Mem; }
62 void _cpy_bool(
void *ptr,
const std::vector<cytnx_bool> &vin);
86 void _Init_byptr_safe(T *rawptr,
const unsigned long long &len_in) {
88 if (this->dtype == Type.Float) {
90 "[ERROR _Init_byptr_safe type not match]");
91 }
else if (this->dtype == Type.Double) {
93 "[ERROR _Init_byptr_safe type not match]");
94 }
else if (this->dtype == Type.Uint64) {
96 "[ERROR _Init_byptr_safe type not match]");
97 }
else if (this->dtype == Type.Uint32) {
99 "[ERROR _Init_byptr_safe type not match]");
100 }
else if (this->dtype == Type.Int64) {
102 "[ERROR _Init_byptr_safe type not match]");
103 }
else if (this->dtype == Type.Int32) {
105 "[ERROR _Init_byptr_safe type not match]");
106 }
else if (this->dtype == Type.ComplexDouble) {
108 "[ERROR _Init_byptr_safe type not match]");
109 }
else if (this->dtype == Type.ComplexFloat) {
111 "[ERROR _Init_byptr_safe type not match]");
112 }
else if (this->dtype == Type.Int16) {
114 "[ERROR _Init_byptr_safe type not match]");
115 }
else if (this->dtype == Type.Uint16) {
117 "[ERROR _Init_byptr_safe type not match]");
118 }
else if (this->dtype == Type.Bool) {
120 "[ERROR _Init_byptr_safe type not match]");
125 this->_Init_byptr((
void *)rawptr, len_in);
128 void GetElem_byShape_v2(boost::intrusive_ptr<Storage_base> &out,
129 const std::vector<cytnx_uint64> &shape,
130 const std::vector<std::vector<cytnx_uint64>> &locators,
131 const cytnx_uint64 &Nunit);
132 void GetElem_byShape(boost::intrusive_ptr<Storage_base> &out,
133 const std::vector<cytnx_uint64> &shape,
134 const std::vector<cytnx_uint64> &mapper,
135 const std::vector<cytnx_uint64> &len,
136 const std::vector<std::vector<cytnx_uint64>> &locators);
137 void SetElem_byShape(boost::intrusive_ptr<Storage_base> &in,
138 const std::vector<cytnx_uint64> &shape,
139 const std::vector<cytnx_uint64> &mapper,
140 const std::vector<cytnx_uint64> &len,
141 const std::vector<std::vector<cytnx_uint64>> &locators,
142 const bool &is_scalar);
143 void SetElem_byShape_v2(boost::intrusive_ptr<Storage_base> &in,
144 const std::vector<cytnx_uint64> &shape,
145 const std::vector<std::vector<cytnx_uint64>> &locators,
146 const cytnx_uint64 &Nunit,
const bool &is_scalar);
149 virtual void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero =
true);
150 virtual void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
151 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
155 virtual boost::intrusive_ptr<Storage_base> _create_new_sametype();
158 virtual void to_(
const int &device);
159 virtual boost::intrusive_ptr<Storage_base> to(
const int &device);
161 virtual boost::intrusive_ptr<Storage_base> clone();
164 virtual boost::intrusive_ptr<Storage_base> Move_memory(
165 const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
166 const std::vector<cytnx_uint64> &invmapper);
167 virtual void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
168 const std::vector<cytnx_uint64> &mapper,
169 const std::vector<cytnx_uint64> &invmapper);
170 virtual void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
171 const std::vector<cytnx_uint64> &mapper = {});
172 virtual void print_elems();
174 virtual boost::intrusive_ptr<Storage_base> real();
175 virtual boost::intrusive_ptr<Storage_base> imag();
178 virtual void fill(
const cytnx_complex128 &val);
179 virtual void fill(
const cytnx_complex64 &val);
180 virtual void fill(
const cytnx_double &val);
181 virtual void fill(
const cytnx_float &val);
182 virtual void fill(
const cytnx_int64 &val);
183 virtual void fill(
const cytnx_uint64 &val);
184 virtual void fill(
const cytnx_int32 &val);
185 virtual void fill(
const cytnx_uint32 &val);
186 virtual void fill(
const cytnx_int16 &val);
187 virtual void fill(
const cytnx_uint16 &val);
188 virtual void fill(
const cytnx_bool &val);
189 virtual void set_zeros();
190 virtual void resize(
const cytnx_uint64 &newsize);
192 virtual void append(
const Scalar &val);
193 virtual void append(
const cytnx_complex128 &val);
194 virtual void append(
const cytnx_complex64 &val);
195 virtual void append(
const cytnx_double &val);
196 virtual void append(
const cytnx_float &val);
197 virtual void append(
const cytnx_int64 &val);
198 virtual void append(
const cytnx_uint64 &val);
199 virtual void append(
const cytnx_int32 &val);
200 virtual void append(
const cytnx_uint32 &val);
201 virtual void append(
const cytnx_int16 &val);
202 virtual void append(
const cytnx_uint16 &val);
203 virtual void append(
const cytnx_bool &val);
205 virtual Scalar get_item(
const cytnx_uint64 &in)
const;
207 virtual void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
208 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
209 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
210 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
211 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
212 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
213 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
214 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
215 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
216 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
217 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
218 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
223 class FloatStorage :
public Storage_base {
225 FloatStorage() { this->dtype = Type.Float; };
226 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero=
true);
227 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
228 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
229 boost::intrusive_ptr<Storage_base> _create_new_sametype();
230 boost::intrusive_ptr<Storage_base> clone();
231 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
232 const std::vector<cytnx_uint64> &mapper,
233 const std::vector<cytnx_uint64> &invmapper);
234 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
235 const std::vector<cytnx_uint64> &mapper,
236 const std::vector<cytnx_uint64> &invmapper);
237 void to_(
const int &device);
238 boost::intrusive_ptr<Storage_base> to(
const int &device);
239 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
240 const std::vector<cytnx_uint64> &mapper = {});
243 boost::intrusive_ptr<Storage_base> real();
244 boost::intrusive_ptr<Storage_base> imag();
247 void fill(
const cytnx_complex128 &val);
248 void fill(
const cytnx_complex64 &val);
249 void fill(
const cytnx_double &val);
250 void fill(
const cytnx_float &val);
251 void fill(
const cytnx_int64 &val);
252 void fill(
const cytnx_uint64 &val);
253 void fill(
const cytnx_int32 &val);
254 void fill(
const cytnx_uint32 &val);
255 void fill(
const cytnx_int16 &val);
256 void fill(
const cytnx_uint16 &val);
257 void fill(
const cytnx_bool &val);
259 void resize(
const cytnx_uint64 &newsize);
261 void append(
const Scalar &val);
262 void append(
const cytnx_complex128 &val);
263 void append(
const cytnx_complex64 &val);
264 void append(
const cytnx_double &val);
265 void append(
const cytnx_float &val);
266 void append(
const cytnx_int64 &val);
267 void append(
const cytnx_uint64 &val);
268 void append(
const cytnx_int32 &val);
269 void append(
const cytnx_uint32 &val);
270 void append(
const cytnx_int16 &val);
271 void append(
const cytnx_uint16 &val);
272 void append(
const cytnx_bool &val);
273 Scalar get_item(
const cytnx_uint64 &in)
const;
275 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
276 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
277 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
278 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
279 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
280 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
281 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
282 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
283 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
284 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
285 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
286 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
291 class DoubleStorage :
public Storage_base {
293 DoubleStorage() { this->dtype = Type.Double; };
294 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero=
true);
295 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
296 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
297 boost::intrusive_ptr<Storage_base> _create_new_sametype();
298 boost::intrusive_ptr<Storage_base> clone();
299 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
300 const std::vector<cytnx_uint64> &mapper,
301 const std::vector<cytnx_uint64> &invmapper);
302 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
303 const std::vector<cytnx_uint64> &mapper,
304 const std::vector<cytnx_uint64> &invmapper);
305 void to_(
const int &device);
306 boost::intrusive_ptr<Storage_base> to(
const int &device);
307 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
308 const std::vector<cytnx_uint64> &mapper = {});
311 boost::intrusive_ptr<Storage_base> real();
312 boost::intrusive_ptr<Storage_base> imag();
315 void fill(
const cytnx_complex128 &val);
316 void fill(
const cytnx_complex64 &val);
317 void fill(
const cytnx_double &val);
318 void fill(
const cytnx_float &val);
319 void fill(
const cytnx_int64 &val);
320 void fill(
const cytnx_uint64 &val);
321 void fill(
const cytnx_int32 &val);
322 void fill(
const cytnx_uint32 &val);
323 void fill(
const cytnx_int16 &val);
324 void fill(
const cytnx_uint16 &val);
325 void fill(
const cytnx_bool &val);
327 void resize(
const cytnx_uint64 &newsize);
329 void append(
const Scalar &val);
330 void append(
const cytnx_complex128 &val);
331 void append(
const cytnx_complex64 &val);
332 void append(
const cytnx_double &val);
333 void append(
const cytnx_float &val);
334 void append(
const cytnx_int64 &val);
335 void append(
const cytnx_uint64 &val);
336 void append(
const cytnx_int32 &val);
337 void append(
const cytnx_uint32 &val);
338 void append(
const cytnx_int16 &val);
339 void append(
const cytnx_uint16 &val);
340 void append(
const cytnx_bool &val);
341 Scalar get_item(
const cytnx_uint64 &in)
const;
343 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
344 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
345 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
346 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
347 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
348 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
349 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
350 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
351 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
352 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
353 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
354 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
359 class ComplexDoubleStorage :
public Storage_base {
361 ComplexDoubleStorage() { this->dtype = Type.ComplexDouble; };
362 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero =
true);
363 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
364 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
365 boost::intrusive_ptr<Storage_base> _create_new_sametype();
366 boost::intrusive_ptr<Storage_base> clone();
367 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
368 const std::vector<cytnx_uint64> &mapper,
369 const std::vector<cytnx_uint64> &invmapper);
370 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
371 const std::vector<cytnx_uint64> &mapper,
372 const std::vector<cytnx_uint64> &invmapper);
373 void to_(
const int &device);
374 boost::intrusive_ptr<Storage_base> to(
const int &device);
375 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
376 const std::vector<cytnx_uint64> &mapper = {});
379 boost::intrusive_ptr<Storage_base> real();
380 boost::intrusive_ptr<Storage_base> imag();
383 void fill(
const cytnx_complex128 &val);
384 void fill(
const cytnx_complex64 &val);
385 void fill(
const cytnx_double &val);
386 void fill(
const cytnx_float &val);
387 void fill(
const cytnx_int64 &val);
388 void fill(
const cytnx_uint64 &val);
389 void fill(
const cytnx_int32 &val);
390 void fill(
const cytnx_uint32 &val);
391 void fill(
const cytnx_int16 &val);
392 void fill(
const cytnx_uint16 &val);
393 void fill(
const cytnx_bool &val);
395 void resize(
const cytnx_uint64 &newsize);
397 void append(
const Scalar &val);
398 void append(
const cytnx_complex128 &val);
399 void append(
const cytnx_complex64 &val);
400 void append(
const cytnx_double &val);
401 void append(
const cytnx_float &val);
402 void append(
const cytnx_int64 &val);
403 void append(
const cytnx_uint64 &val);
404 void append(
const cytnx_int32 &val);
405 void append(
const cytnx_uint32 &val);
406 void append(
const cytnx_int16 &val);
407 void append(
const cytnx_uint16 &val);
408 void append(
const cytnx_bool &val);
409 Scalar get_item(
const cytnx_uint64 &in)
const;
411 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
412 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
413 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
414 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
415 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
416 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
417 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
418 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
419 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
420 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
421 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
422 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
427 class ComplexFloatStorage :
public Storage_base {
429 ComplexFloatStorage() { this->dtype = Type.ComplexFloat; };
430 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero =
true);
431 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
432 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
433 boost::intrusive_ptr<Storage_base> _create_new_sametype();
434 boost::intrusive_ptr<Storage_base> clone();
435 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
436 const std::vector<cytnx_uint64> &mapper,
437 const std::vector<cytnx_uint64> &invmapper);
438 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
439 const std::vector<cytnx_uint64> &mapper,
440 const std::vector<cytnx_uint64> &invmapper);
441 void to_(
const int &device);
442 boost::intrusive_ptr<Storage_base> to(
const int &device);
443 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
444 const std::vector<cytnx_uint64> &mapper = {});
447 boost::intrusive_ptr<Storage_base> real();
448 boost::intrusive_ptr<Storage_base> imag();
451 void fill(
const cytnx_complex128 &val);
452 void fill(
const cytnx_complex64 &val);
453 void fill(
const cytnx_double &val);
454 void fill(
const cytnx_float &val);
455 void fill(
const cytnx_int64 &val);
456 void fill(
const cytnx_uint64 &val);
457 void fill(
const cytnx_int32 &val);
458 void fill(
const cytnx_uint32 &val);
459 void fill(
const cytnx_int16 &val);
460 void fill(
const cytnx_uint16 &val);
461 void fill(
const cytnx_bool &val);
463 void resize(
const cytnx_uint64 &newsize);
465 void append(
const Scalar &val);
466 void append(
const cytnx_complex128 &val);
467 void append(
const cytnx_complex64 &val);
468 void append(
const cytnx_double &val);
469 void append(
const cytnx_float &val);
470 void append(
const cytnx_int64 &val);
471 void append(
const cytnx_uint64 &val);
472 void append(
const cytnx_int32 &val);
473 void append(
const cytnx_uint32 &val);
474 void append(
const cytnx_int16 &val);
475 void append(
const cytnx_uint16 &val);
476 void append(
const cytnx_bool &val);
477 Scalar get_item(
const cytnx_uint64 &in)
const;
479 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
480 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
481 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
482 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
483 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
484 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
485 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
486 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
487 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
488 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
489 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
490 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
495 class Int64Storage :
public Storage_base {
497 Int64Storage() { this->dtype = Type.Int64; };
498 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero =
true);
499 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
500 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
501 boost::intrusive_ptr<Storage_base> _create_new_sametype();
502 boost::intrusive_ptr<Storage_base> clone();
503 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
504 const std::vector<cytnx_uint64> &mapper,
505 const std::vector<cytnx_uint64> &invmapper);
506 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
507 const std::vector<cytnx_uint64> &mapper,
508 const std::vector<cytnx_uint64> &invmapper);
509 void to_(
const int &device);
510 boost::intrusive_ptr<Storage_base> to(
const int &device);
511 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
512 const std::vector<cytnx_uint64> &mapper = {});
515 boost::intrusive_ptr<Storage_base> real();
516 boost::intrusive_ptr<Storage_base> imag();
519 void fill(
const cytnx_complex128 &val);
520 void fill(
const cytnx_complex64 &val);
521 void fill(
const cytnx_double &val);
522 void fill(
const cytnx_float &val);
523 void fill(
const cytnx_int64 &val);
524 void fill(
const cytnx_uint64 &val);
525 void fill(
const cytnx_int32 &val);
526 void fill(
const cytnx_uint32 &val);
527 void fill(
const cytnx_int16 &val);
528 void fill(
const cytnx_uint16 &val);
529 void fill(
const cytnx_bool &val);
531 void resize(
const cytnx_uint64 &newsize);
533 void append(
const Scalar &val);
534 void append(
const cytnx_complex128 &val);
535 void append(
const cytnx_complex64 &val);
536 void append(
const cytnx_double &val);
537 void append(
const cytnx_float &val);
538 void append(
const cytnx_int64 &val);
539 void append(
const cytnx_uint64 &val);
540 void append(
const cytnx_int32 &val);
541 void append(
const cytnx_uint32 &val);
542 void append(
const cytnx_int16 &val);
543 void append(
const cytnx_uint16 &val);
544 void append(
const cytnx_bool &val);
545 Scalar get_item(
const cytnx_uint64 &in)
const;
547 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
548 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
549 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
550 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
551 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
552 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
553 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
554 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
555 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
556 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
557 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
558 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
563 class Uint64Storage :
public Storage_base {
565 Uint64Storage() { this->dtype = Type.Uint64; };
566 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero =
true);
567 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
568 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
569 boost::intrusive_ptr<Storage_base> _create_new_sametype();
570 boost::intrusive_ptr<Storage_base> clone();
571 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
572 const std::vector<cytnx_uint64> &mapper,
573 const std::vector<cytnx_uint64> &invmapper);
574 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
575 const std::vector<cytnx_uint64> &mapper,
576 const std::vector<cytnx_uint64> &invmapper);
577 void to_(
const int &device);
578 boost::intrusive_ptr<Storage_base> to(
const int &device);
579 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
580 const std::vector<cytnx_uint64> &mapper = {});
583 boost::intrusive_ptr<Storage_base> real();
584 boost::intrusive_ptr<Storage_base> imag();
587 void fill(
const cytnx_complex128 &val);
588 void fill(
const cytnx_complex64 &val);
589 void fill(
const cytnx_double &val);
590 void fill(
const cytnx_float &val);
591 void fill(
const cytnx_int64 &val);
592 void fill(
const cytnx_uint64 &val);
593 void fill(
const cytnx_int32 &val);
594 void fill(
const cytnx_uint32 &val);
595 void fill(
const cytnx_int16 &val);
596 void fill(
const cytnx_uint16 &val);
597 void fill(
const cytnx_bool &val);
599 void resize(
const cytnx_uint64 &newsize);
601 void append(
const Scalar &val);
602 void append(
const cytnx_complex128 &val);
603 void append(
const cytnx_complex64 &val);
604 void append(
const cytnx_double &val);
605 void append(
const cytnx_float &val);
606 void append(
const cytnx_int64 &val);
607 void append(
const cytnx_uint64 &val);
608 void append(
const cytnx_int32 &val);
609 void append(
const cytnx_uint32 &val);
610 void append(
const cytnx_int16 &val);
611 void append(
const cytnx_uint16 &val);
612 void append(
const cytnx_bool &val);
613 Scalar get_item(
const cytnx_uint64 &in)
const;
615 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
616 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
617 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
618 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
619 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
620 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
621 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
622 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
623 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
624 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
625 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
626 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
630 class Int32Storage :
public Storage_base {
632 Int32Storage() { this->dtype = Type.Int32; };
633 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero =
true);
634 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
635 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
636 boost::intrusive_ptr<Storage_base> _create_new_sametype();
637 boost::intrusive_ptr<Storage_base> clone();
638 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
639 const std::vector<cytnx_uint64> &mapper,
640 const std::vector<cytnx_uint64> &invmapper);
641 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
642 const std::vector<cytnx_uint64> &mapper,
643 const std::vector<cytnx_uint64> &invmapper);
644 void to_(
const int &device);
645 boost::intrusive_ptr<Storage_base> to(
const int &device);
646 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
647 const std::vector<cytnx_uint64> &mapper = {});
650 boost::intrusive_ptr<Storage_base> real();
651 boost::intrusive_ptr<Storage_base> imag();
654 void fill(
const cytnx_complex128 &val);
655 void fill(
const cytnx_complex64 &val);
656 void fill(
const cytnx_double &val);
657 void fill(
const cytnx_float &val);
658 void fill(
const cytnx_int64 &val);
659 void fill(
const cytnx_uint64 &val);
660 void fill(
const cytnx_int32 &val);
661 void fill(
const cytnx_uint32 &val);
662 void fill(
const cytnx_int16 &val);
663 void fill(
const cytnx_uint16 &val);
664 void fill(
const cytnx_bool &val);
666 void resize(
const cytnx_uint64 &newsize);
667 void append(
const Scalar &val);
668 void append(
const cytnx_complex128 &val);
669 void append(
const cytnx_complex64 &val);
670 void append(
const cytnx_double &val);
671 void append(
const cytnx_float &val);
672 void append(
const cytnx_int64 &val);
673 void append(
const cytnx_uint64 &val);
674 void append(
const cytnx_int32 &val);
675 void append(
const cytnx_uint32 &val);
676 void append(
const cytnx_int16 &val);
677 void append(
const cytnx_uint16 &val);
678 void append(
const cytnx_bool &val);
679 Scalar get_item(
const cytnx_uint64 &in)
const;
681 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
682 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
683 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
684 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
685 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
686 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
687 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
688 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
689 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
690 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
691 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
692 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
697 class Uint32Storage :
public Storage_base {
699 Uint32Storage() { this->dtype = Type.Uint32; };
700 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero=
true);
701 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
702 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
703 boost::intrusive_ptr<Storage_base> _create_new_sametype();
704 boost::intrusive_ptr<Storage_base> clone();
705 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
706 const std::vector<cytnx_uint64> &mapper,
707 const std::vector<cytnx_uint64> &invmapper);
708 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
709 const std::vector<cytnx_uint64> &mapper,
710 const std::vector<cytnx_uint64> &invmapper);
711 void to_(
const int &device);
712 boost::intrusive_ptr<Storage_base> to(
const int &device);
713 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
714 const std::vector<cytnx_uint64> &mapper = {});
717 boost::intrusive_ptr<Storage_base> real();
718 boost::intrusive_ptr<Storage_base> imag();
721 void fill(
const cytnx_complex128 &val);
722 void fill(
const cytnx_complex64 &val);
723 void fill(
const cytnx_double &val);
724 void fill(
const cytnx_float &val);
725 void fill(
const cytnx_int64 &val);
726 void fill(
const cytnx_uint64 &val);
727 void fill(
const cytnx_int32 &val);
728 void fill(
const cytnx_uint32 &val);
729 void fill(
const cytnx_int16 &val);
730 void fill(
const cytnx_uint16 &val);
731 void fill(
const cytnx_bool &val);
733 void resize(
const cytnx_uint64 &newsize);
734 void append(
const Scalar &val);
735 void append(
const cytnx_complex128 &val);
736 void append(
const cytnx_complex64 &val);
737 void append(
const cytnx_double &val);
738 void append(
const cytnx_float &val);
739 void append(
const cytnx_int64 &val);
740 void append(
const cytnx_uint64 &val);
741 void append(
const cytnx_int32 &val);
742 void append(
const cytnx_uint32 &val);
743 void append(
const cytnx_int16 &val);
744 void append(
const cytnx_uint16 &val);
745 void append(
const cytnx_bool &val);
746 Scalar get_item(
const cytnx_uint64 &in)
const;
748 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
749 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
750 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
751 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
752 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
753 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
754 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
755 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
756 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
757 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
758 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
759 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
764 class Uint16Storage :
public Storage_base {
766 Uint16Storage() { this->dtype = Type.Uint16; };
767 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero=
true);
768 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
769 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
770 boost::intrusive_ptr<Storage_base> _create_new_sametype();
771 boost::intrusive_ptr<Storage_base> clone();
772 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
773 const std::vector<cytnx_uint64> &mapper,
774 const std::vector<cytnx_uint64> &invmapper);
775 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
776 const std::vector<cytnx_uint64> &mapper,
777 const std::vector<cytnx_uint64> &invmapper);
778 void to_(
const int &device);
779 boost::intrusive_ptr<Storage_base> to(
const int &device);
780 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
781 const std::vector<cytnx_uint64> &mapper = {});
784 boost::intrusive_ptr<Storage_base> real();
785 boost::intrusive_ptr<Storage_base> imag();
788 void fill(
const cytnx_complex128 &val);
789 void fill(
const cytnx_complex64 &val);
790 void fill(
const cytnx_double &val);
791 void fill(
const cytnx_float &val);
792 void fill(
const cytnx_int64 &val);
793 void fill(
const cytnx_uint64 &val);
794 void fill(
const cytnx_int32 &val);
795 void fill(
const cytnx_uint32 &val);
796 void fill(
const cytnx_int16 &val);
797 void fill(
const cytnx_uint16 &val);
798 void fill(
const cytnx_bool &val);
800 void resize(
const cytnx_uint64 &newsize);
802 void append(
const Scalar &val);
803 void append(
const cytnx_complex128 &val);
804 void append(
const cytnx_complex64 &val);
805 void append(
const cytnx_double &val);
806 void append(
const cytnx_float &val);
807 void append(
const cytnx_int64 &val);
808 void append(
const cytnx_uint64 &val);
809 void append(
const cytnx_int32 &val);
810 void append(
const cytnx_uint32 &val);
811 void append(
const cytnx_int16 &val);
812 void append(
const cytnx_uint16 &val);
813 void append(
const cytnx_bool &val);
814 Scalar get_item(
const cytnx_uint64 &in)
const;
816 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
817 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
818 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
819 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
820 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
821 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
822 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
823 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
824 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
825 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
826 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
827 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
832 class Int16Storage :
public Storage_base {
834 Int16Storage() { this->dtype = Type.Int16; };
835 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero=
true);
836 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
837 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
838 boost::intrusive_ptr<Storage_base> _create_new_sametype();
839 boost::intrusive_ptr<Storage_base> clone();
840 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
841 const std::vector<cytnx_uint64> &mapper,
842 const std::vector<cytnx_uint64> &invmapper);
843 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
844 const std::vector<cytnx_uint64> &mapper,
845 const std::vector<cytnx_uint64> &invmapper);
846 void to_(
const int &device);
847 boost::intrusive_ptr<Storage_base> to(
const int &device);
848 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
849 const std::vector<cytnx_uint64> &mapper = {});
852 boost::intrusive_ptr<Storage_base> real();
853 boost::intrusive_ptr<Storage_base> imag();
856 void fill(
const cytnx_complex128 &val);
857 void fill(
const cytnx_complex64 &val);
858 void fill(
const cytnx_double &val);
859 void fill(
const cytnx_float &val);
860 void fill(
const cytnx_int64 &val);
861 void fill(
const cytnx_uint64 &val);
862 void fill(
const cytnx_int32 &val);
863 void fill(
const cytnx_uint32 &val);
864 void fill(
const cytnx_int16 &val);
865 void fill(
const cytnx_uint16 &val);
866 void fill(
const cytnx_bool &val);
868 void resize(
const cytnx_uint64 &newsize);
869 void append(
const Scalar &val);
870 void append(
const cytnx_complex128 &val);
871 void append(
const cytnx_complex64 &val);
872 void append(
const cytnx_double &val);
873 void append(
const cytnx_float &val);
874 void append(
const cytnx_int64 &val);
875 void append(
const cytnx_uint64 &val);
876 void append(
const cytnx_int32 &val);
877 void append(
const cytnx_uint32 &val);
878 void append(
const cytnx_int16 &val);
879 void append(
const cytnx_uint16 &val);
880 void append(
const cytnx_bool &val);
881 Scalar get_item(
const cytnx_uint64 &in)
const;
883 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
884 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
885 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
886 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
887 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
888 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
889 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
890 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
891 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
892 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
893 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
894 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
899 class BoolStorage :
public Storage_base {
901 BoolStorage() { this->dtype = Type.Bool; };
902 void Init(
const unsigned long long &len_in,
const int &device = -1,
const bool &init_zero=
true);
903 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device = -1,
904 const bool &iscap =
false,
const unsigned long long &cap_in = 0);
905 boost::intrusive_ptr<Storage_base> _create_new_sametype();
906 boost::intrusive_ptr<Storage_base> clone();
907 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
908 const std::vector<cytnx_uint64> &mapper,
909 const std::vector<cytnx_uint64> &invmapper);
910 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
911 const std::vector<cytnx_uint64> &mapper,
912 const std::vector<cytnx_uint64> &invmapper);
913 void to_(
const int &device);
914 boost::intrusive_ptr<Storage_base> to(
const int &device);
915 void PrintElem_byShape(std::ostream &os,
const std::vector<cytnx_uint64> &shape,
916 const std::vector<cytnx_uint64> &mapper = {});
919 boost::intrusive_ptr<Storage_base> real();
920 boost::intrusive_ptr<Storage_base> imag();
923 void fill(
const cytnx_complex128 &val);
924 void fill(
const cytnx_complex64 &val);
925 void fill(
const cytnx_double &val);
926 void fill(
const cytnx_float &val);
927 void fill(
const cytnx_int64 &val);
928 void fill(
const cytnx_uint64 &val);
929 void fill(
const cytnx_int32 &val);
930 void fill(
const cytnx_uint32 &val);
931 void fill(
const cytnx_int16 &val);
932 void fill(
const cytnx_uint16 &val);
933 void fill(
const cytnx_bool &val);
935 void resize(
const cytnx_uint64 &newsize);
936 void append(
const Scalar &val);
937 void append(
const cytnx_complex128 &val);
938 void append(
const cytnx_complex64 &val);
939 void append(
const cytnx_double &val);
940 void append(
const cytnx_float &val);
941 void append(
const cytnx_int64 &val);
942 void append(
const cytnx_uint64 &val);
943 void append(
const cytnx_int32 &val);
944 void append(
const cytnx_uint32 &val);
945 void append(
const cytnx_int16 &val);
946 void append(
const cytnx_uint16 &val);
947 void append(
const cytnx_bool &val);
948 Scalar get_item(
const cytnx_uint64 &in)
const;
950 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
951 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
952 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
953 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
954 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
955 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
956 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
957 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
958 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
959 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
960 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
961 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
966 typedef boost::intrusive_ptr<Storage_base> (*pStorage_init)();
969 boost::intrusive_ptr<Storage_base> out(
new ComplexDoubleStorage());
973 boost::intrusive_ptr<Storage_base> out(
new ComplexFloatStorage());
976 inline boost::intrusive_ptr<Storage_base>
SIInit_d() {
977 boost::intrusive_ptr<Storage_base> out(
new DoubleStorage());
980 inline boost::intrusive_ptr<Storage_base>
SIInit_f() {
981 boost::intrusive_ptr<Storage_base> out(
new FloatStorage());
985 boost::intrusive_ptr<Storage_base> out(
new Uint64Storage());
989 boost::intrusive_ptr<Storage_base> out(
new Int64Storage());
993 boost::intrusive_ptr<Storage_base> out(
new Uint32Storage());
997 boost::intrusive_ptr<Storage_base> out(
new Int32Storage());
1001 boost::intrusive_ptr<Storage_base> out(
new Uint16Storage());
1005 boost::intrusive_ptr<Storage_base> out(
new Int16Storage());
1009 boost::intrusive_ptr<Storage_base> out(
new BoolStorage());
1013 class Storage_init_interface :
public Type_class {
1016 inline static pStorage_init USIInit[N_Type];
1017 inline static bool inited =
false;
1018 Storage_init_interface(){
1020 USIInit[this->Double] = SIInit_d;
1021 USIInit[this->Float] = SIInit_f;
1022 USIInit[this->ComplexDouble] = SIInit_cd;
1023 USIInit[this->ComplexFloat] = SIInit_cf;
1024 USIInit[this->Uint64] = SIInit_u64;
1025 USIInit[this->Int64] = SIInit_i64;
1026 USIInit[this->Uint32] = SIInit_u32;
1027 USIInit[this->Int32] = SIInit_i32;
1028 USIInit[this->Uint16] = SIInit_u16;
1029 USIInit[this->Int16] = SIInit_i16;
1030 USIInit[this->Bool] = SIInit_b;
1035 extern Storage_init_interface
__SII;
1046 boost::intrusive_ptr<Storage_base> _impl;
1110 Storage(
const std::initializer_list<Tp> &
rhs) {
1115 this->_impl =
rhs._impl;
1122 void _Save(std::fstream &f)
const;
1123 void _Load(std::fstream &f);
1137 void Save(
const std::string &
fname)
const;
1191 const unsigned int &
dtype()
const {
return this->_impl->dtype; }
1198 std::string
out = this->_impl->dtype_str();
1205 const int &
device()
const {
return this->_impl->device; }
1212 std::string
out = this->_impl->device_str();
1223 return this->_impl->append(
val);
1229 return this->_impl->at<
T>(
idx);
1233 Scalar::Sproxy
out(this->_impl,
idx);
1237 Scalar::Sproxy
out(this->_impl,
idx);
1243 return this->_impl->back<
T>();
1246 const Scalar::Sproxy
back()
const {
1247 Scalar::Sproxy
out(this->_impl, this->
size() - 1);
1250 Scalar::Sproxy
back() {
1251 Scalar::Sproxy
out(this->_impl, this->
size() - 1);
1257 return this->_impl->data<
T>();
1260 void *data()
const {
return this->_impl->data(); }
1307 const unsigned long long &
size()
const {
return this->_impl->len; }
1314 const unsigned long long &
capacity()
const {
return this->_impl->cap; }
1323 void print()
const { this->_impl->print(); }
1365 this->_impl->fill(
val);
1421 this->_impl =
__SII.USIInit[
Type.ComplexDouble]();
1426 this->_impl =
__SII.USIInit[
Type.ComplexFloat]();
1431 this->_impl =
__SII.USIInit[
Type.Double]();
1436 this->_impl =
__SII.USIInit[
Type.Float]();
1441 this->_impl =
__SII.USIInit[
Type.Uint64]();
1446 this->_impl =
__SII.USIInit[
Type.Int64]();
1451 this->_impl =
__SII.USIInit[
Type.Uint32]();
1456 this->_impl =
__SII.USIInit[
Type.Int32]();
1461 this->_impl =
__SII.USIInit[
Type.Uint16]();
1466 this->_impl =
__SII.USIInit[
Type.Int16]();
1471 this->_impl =
__SII.USIInit[
Type.Bool]();
1473 this->_impl->_cpy_bool(this->_impl->Mem,
vin);
1524 this->_impl->set_item(
idx,
elem);
1535 std::ostream &
operator<<(std::ostream &os,
const Storage &in);
A class to represent a scalar.
Definition Scalar.hpp:2470
an memeory storage with multi-type/multi-device support
Definition Storage.hpp:1039
void to_(const int &device)
Move the current Storage to different deivce.
Definition Storage.hpp:1274
void append(const T &val)
append a value
Definition Storage.hpp:1222
Storage(const unsigned long long &size, const unsigned int &dtype=Type.Double, int device=-1, const bool &init_zero=true)
The constructor of Storage class. It will call the function Init to initialize the Storage instance.
Definition Storage.hpp:1086
const int & device() const
the device-id of current Storage, see cytnx::Device for more details.
Definition Storage.hpp:1205
Storage real() const
Get the real part form a Complex type Storage.
Definition Storage.hpp:1492
std::vector< T > vector()
Definition Storage.cpp:323
Storage to(const int &device)
move a new Storage with same content as current Storage on different deivce.
Definition Storage.hpp:1283
void Init(const unsigned long long &size, const unsigned int &dtype=Type.Double, int device=-1, const bool &init_zero=true)
initialize a Storage
Definition Storage.hpp:1066
void resize(const cytnx_uint64 &newsize)
resize the current Storage.
Definition Storage.hpp:1267
void Save(const std::string &fname) const
Save current Storage to file.
Definition Storage.cpp:87
void fill(const T &val)
set all the elements to the assigned value val
Definition Storage.hpp:1364
Storage()
The default constructor of Storage class. It will create an empty Storage instance.
Definition Storage.hpp:1100
void Tofile(const std::string &fname) const
Definition Storage.cpp:106
const unsigned int & dtype() const
the dtype-id of current Storage, see cytnx::Type for more details.
Definition Storage.hpp:1191
void set_item(const cytnx_uint64 &idx, const T &elem)
Set the element at the given index.
Definition Storage.hpp:1523
const unsigned long long & capacity() const
the capacity ( no. of real elements in memory) in the Storage
Definition Storage.hpp:1314
void set_zeros()
set all the elements to zero.
Definition Storage.hpp:1332
static Storage Load(const std::string &fname)
Load current Storage from file.
Definition Storage.cpp:230
Storage astype(const unsigned int &new_type) const
cast the type of current Storage
Definition Storage.hpp:1185
const unsigned long long & size() const
the size ( no. of elements ) in the Storage
Definition Storage.hpp:1307
void print_info() const
print the info of the Storage, including the device, dtype and size.
Definition Storage.hpp:1320
static Storage from_vector(const std::vector< T > &vin, const int device=-1)
renew/create a Storage using c++ vector.
Definition Storage.hpp:1374
bool operator!=(const Storage &rhs)
The not-equal operator for Storage.
Definition Storage.cpp:85
static Storage Fromfile(const std::string &fname, const unsigned int &dtype, const cytnx_int64 &count=-1)
Definition Storage.cpp:189
const std::string dtype_str() const
the dtype (std::string) of current Storage, see cytnx::Type for more details.
Definition Storage.hpp:1197
Scalar::Sproxy operator()(const cytnx_uint64 &idx)
The access operator for the Storage.
Definition Storage.cpp:317
void Tofile(std::fstream &f) const
bool operator==(const Storage &rhs)
compare two Storage
Definition Storage.cpp:19
Scalar get_item(const cytnx_uint64 &idx) const
Get the element at the given index.
Definition Storage.hpp:1515
Storage imag() const
Get the imaginary part form a Complex type Storage.
Definition Storage.hpp:1508
const std::string device_str() const
the device (std::string) of current Storage, see cytnx::Device for more details.
Definition Storage.hpp:1211
Storage clone() const
return a deep copy of the current storage.
Definition Storage.hpp:1300
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:16
Definition Accessor.hpp:12
boost::intrusive_ptr< Storage_base > SIInit_u32()
Definition Storage.hpp:992
double cytnx_double
Definition Type.hpp:43
boost::intrusive_ptr< Storage_base > SIInit_d()
Definition Storage.hpp:976
uint32_t cytnx_uint32
Definition Type.hpp:46
boost::intrusive_ptr< Storage_base > SIInit_u64()
Definition Storage.hpp:984
std::complex< double > cytnx_complex128
Definition Type.hpp:53
float cytnx_float
Definition Type.hpp:44
std::ostream & operator<<(std::ostream &os, const Scalar &in)
The stream operator for Scalar objects.
Definition Scalar.cpp:10
boost::intrusive_ptr< Storage_base > SIInit_u16()
Definition Storage.hpp:1000
boost::intrusive_ptr< Storage_base > SIInit_f()
Definition Storage.hpp:980
int16_t cytnx_int16
Definition Type.hpp:50
std::complex< float > cytnx_complex64
Definition Type.hpp:52
int32_t cytnx_int32
Definition Type.hpp:49
boost::intrusive_ptr< Storage_base > SIInit_i16()
Definition Storage.hpp:1004
boost::intrusive_ptr< Storage_base > SIInit_i32()
Definition Storage.hpp:996
uint16_t cytnx_uint16
Definition Type.hpp:47
boost::intrusive_ptr< Storage_base > SIInit_i64()
Definition Storage.hpp:988
uint64_t cytnx_uint64
Definition Type.hpp:45
boost::intrusive_ptr< Storage_base > SIInit_b()
Definition Storage.hpp:1008
int64_t cytnx_int64
Definition Type.hpp:48
Storage_init_interface __SII
Definition Storage.cpp:12
Type_class Type
data type
Definition Type.cpp:23
boost::intrusive_ptr< Storage_base > SIInit_cf()
Definition Storage.hpp:972
boost::intrusive_ptr< Storage_base > SIInit_cd()
Definition Storage.hpp:968