9#include <initializer_list>
22#define STORAGE_DEFT_SZ 2
27 class Storage_base :
public intrusive_ptr_base<Storage_base> {
32 unsigned long long len;
33 unsigned long long cap;
37 Storage_base(): cap(0),len(0), Mem(NULL),dtype(0), device(-1){};
40 Storage_base(
const unsigned long long &len_in,
const int &device);
42 Storage_base(Storage_base &Rhs);
43 Storage_base& operator=(Storage_base &Rhs);
44 boost::intrusive_ptr<Storage_base> astype(
const unsigned int &dtype);
47 std::string dtype_str()
const ;
48 std::string device_str()
const;
49 const unsigned long long &capacity()
const{
52 const unsigned long long &size()
const{
59 T& at(
const cytnx_uint64 &idx)
const;
71 void _cpy_bool(
void *ptr,
const std::vector<cytnx_bool> &vin);
95 void _Init_byptr_safe(T *rawptr,
const unsigned long long &len_in){
97 if(this->dtype==Type.Float){
98 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_float),
"%s",
"[ERROR _Init_byptr_safe type not match]");
99 }
else if(this->dtype==Type.Double){
100 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_double),
"%s",
"[ERROR _Init_byptr_safe type not match]");
101 }
else if(this->dtype==Type.Uint64){
102 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_uint64),
"%s",
"[ERROR _Init_byptr_safe type not match]");
103 }
else if(this->dtype==Type.Uint32){
104 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_uint32),
"%s",
"[ERROR _Init_byptr_safe type not match]");
105 }
else if(this->dtype==Type.Int64){
106 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_int64),
"%s",
"[ERROR _Init_byptr_safe type not match]");
107 }
else if(this->dtype==Type.Int32){
108 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_int32),
"%s",
"[ERROR _Init_byptr_safe type not match]");
109 }
else if(this->dtype==Type.ComplexDouble){
110 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_complex128),
"%s",
"[ERROR _Init_byptr_safe type not match]");
111 }
else if(this->dtype==Type.ComplexFloat){
112 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_complex64),
"%s",
"[ERROR _Init_byptr_safe type not match]");
113 }
else if(this->dtype==Type.Int16){
114 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_int16),
"%s",
"[ERROR _Init_byptr_safe type not match]");
115 }
else if(this->dtype==Type.Uint16){
116 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_uint16),
"%s",
"[ERROR _Init_byptr_safe type not match]");
117 }
else if(this->dtype==Type.Bool){
118 cytnx_error_msg(
typeid(T) !=
typeid(cytnx_bool),
"%s",
"[ERROR _Init_byptr_safe type not match]");
123 this->_Init_byptr((
void*)rawptr,len_in);
128 void GetElem_byShape_v2(boost::intrusive_ptr<Storage_base> &out,
const std::vector<cytnx_uint64> &shape,
const std::vector<std::vector<cytnx_uint64> > &locators,
const cytnx_uint64 &Nunit);
129 void GetElem_byShape(boost::intrusive_ptr<Storage_base> &out,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &len,
const std::vector<std::vector<cytnx_uint64> > &locators);
130 void SetElem_byShape(boost::intrusive_ptr<Storage_base> &in,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &len,
const std::vector<std::vector<cytnx_uint64> > &locators,
const bool &is_scalar);
131 void SetElem_byShape_v2(boost::intrusive_ptr<Storage_base> &in,
const std::vector<cytnx_uint64> &shape,
const std::vector<std::vector<cytnx_uint64> > &locators,
const cytnx_uint64 &Nunit,
const bool &is_scalar);
134 virtual void Init(
const unsigned long long &len_in,
const int &device=-1);
135 virtual void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
139 virtual boost::intrusive_ptr<Storage_base> _create_new_sametype();
142 virtual void to_(
const int &device);
143 virtual boost::intrusive_ptr<Storage_base> to(
const int &device);
145 virtual boost::intrusive_ptr<Storage_base> clone();
148 virtual boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
149 virtual void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
150 virtual void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
151 virtual void print_elems();
153 virtual boost::intrusive_ptr<Storage_base> real();
154 virtual boost::intrusive_ptr<Storage_base> imag();
157 virtual void fill(
const cytnx_complex128 &val);
158 virtual void fill(
const cytnx_complex64 &val);
159 virtual void fill(
const cytnx_double &val);
160 virtual void fill(
const cytnx_float &val);
161 virtual void fill(
const cytnx_int64 &val);
162 virtual void fill(
const cytnx_uint64 &val);
163 virtual void fill(
const cytnx_int32 &val);
164 virtual void fill(
const cytnx_uint32 &val);
165 virtual void fill(
const cytnx_int16 &val);
166 virtual void fill(
const cytnx_uint16 &val);
167 virtual void fill(
const cytnx_bool &val);
168 virtual void set_zeros();
169 virtual void resize(
const cytnx_uint64 &newsize);
172 virtual void append(
const Scalar &val);
173 virtual void append(
const cytnx_complex128 &val);
174 virtual void append(
const cytnx_complex64 &val);
175 virtual void append(
const cytnx_double &val);
176 virtual void append(
const cytnx_float &val);
177 virtual void append(
const cytnx_int64 &val);
178 virtual void append(
const cytnx_uint64 &val);
179 virtual void append(
const cytnx_int32 &val);
180 virtual void append(
const cytnx_uint32 &val);
181 virtual void append(
const cytnx_int16 &val);
182 virtual void append(
const cytnx_uint16 &val);
183 virtual void append(
const cytnx_bool &val);
185 virtual Scalar get_item(
const cytnx_uint64 &in)
const;
187 virtual void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
188 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
189 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
190 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
191 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
192 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
193 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
194 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
195 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
196 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
197 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
198 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
205 class FloatStorage :
public Storage_base{
207 FloatStorage(){this->dtype=Type.Float;};
208 void Init(
const unsigned long long &len_in,
const int &device=-1);
209 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
210 boost::intrusive_ptr<Storage_base> _create_new_sametype();
211 boost::intrusive_ptr<Storage_base> clone();
212 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
213 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
214 void to_(
const int &device);
215 boost::intrusive_ptr<Storage_base> to(
const int &device);
216 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
219 boost::intrusive_ptr<Storage_base> real();
220 boost::intrusive_ptr<Storage_base> imag();
224 void fill(
const cytnx_complex128 &val);
225 void fill(
const cytnx_complex64 &val);
226 void fill(
const cytnx_double &val);
227 void fill(
const cytnx_float &val);
228 void fill(
const cytnx_int64 &val);
229 void fill(
const cytnx_uint64 &val);
230 void fill(
const cytnx_int32 &val);
231 void fill(
const cytnx_uint32 &val);
232 void fill(
const cytnx_int16 &val);
233 void fill(
const cytnx_uint16 &val);
234 void fill(
const cytnx_bool &val);
236 void resize(
const cytnx_uint64 &newsize);
238 void append(
const Scalar &val);
239 void append(
const cytnx_complex128 &val);
240 void append(
const cytnx_complex64 &val);
241 void append(
const cytnx_double &val);
242 void append(
const cytnx_float &val);
243 void append(
const cytnx_int64 &val);
244 void append(
const cytnx_uint64 &val);
245 void append(
const cytnx_int32 &val);
246 void append(
const cytnx_uint32 &val);
247 void append(
const cytnx_int16 &val);
248 void append(
const cytnx_uint16 &val);
249 void append(
const cytnx_bool &val);
250 Scalar get_item(
const cytnx_uint64 &in)
const;
253 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
254 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
255 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
256 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
257 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
258 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
259 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
260 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
261 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
262 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
263 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
264 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
271 class DoubleStorage:
public Storage_base{
273 DoubleStorage(){this->dtype=Type.Double;};
274 void Init(
const unsigned long long &len_in,
const int &device=-1);
275 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
276 boost::intrusive_ptr<Storage_base> _create_new_sametype();
277 boost::intrusive_ptr<Storage_base> clone();
278 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
279 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
280 void to_(
const int &device);
281 boost::intrusive_ptr<Storage_base> to(
const int &device);
282 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
285 boost::intrusive_ptr<Storage_base> real();
286 boost::intrusive_ptr<Storage_base> imag();
289 void fill(
const cytnx_complex128 &val);
290 void fill(
const cytnx_complex64 &val);
291 void fill(
const cytnx_double &val);
292 void fill(
const cytnx_float &val);
293 void fill(
const cytnx_int64 &val);
294 void fill(
const cytnx_uint64 &val);
295 void fill(
const cytnx_int32 &val);
296 void fill(
const cytnx_uint32 &val);
297 void fill(
const cytnx_int16 &val);
298 void fill(
const cytnx_uint16 &val);
299 void fill(
const cytnx_bool &val);
301 void resize(
const cytnx_uint64 &newsize);
303 void append(
const Scalar &val);
304 void append(
const cytnx_complex128 &val);
305 void append(
const cytnx_complex64 &val);
306 void append(
const cytnx_double &val);
307 void append(
const cytnx_float &val);
308 void append(
const cytnx_int64 &val);
309 void append(
const cytnx_uint64 &val);
310 void append(
const cytnx_int32 &val);
311 void append(
const cytnx_uint32 &val);
312 void append(
const cytnx_int16 &val);
313 void append(
const cytnx_uint16 &val);
314 void append(
const cytnx_bool &val);
315 Scalar get_item(
const cytnx_uint64 &in)
const;
317 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
318 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
319 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
320 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
321 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
322 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
323 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
324 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
325 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
326 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
327 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
328 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
334 class ComplexDoubleStorage:
public Storage_base{
336 ComplexDoubleStorage(){this->dtype=Type.ComplexDouble;};
337 void Init(
const unsigned long long &len_in,
const int &device=-1);
338 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
339 boost::intrusive_ptr<Storage_base> _create_new_sametype();
340 boost::intrusive_ptr<Storage_base> clone();
341 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
342 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
343 void to_(
const int &device);
344 boost::intrusive_ptr<Storage_base> to(
const int &device);
345 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
348 boost::intrusive_ptr<Storage_base> real();
349 boost::intrusive_ptr<Storage_base> imag();
352 void fill(
const cytnx_complex128 &val);
353 void fill(
const cytnx_complex64 &val);
354 void fill(
const cytnx_double &val);
355 void fill(
const cytnx_float &val);
356 void fill(
const cytnx_int64 &val);
357 void fill(
const cytnx_uint64 &val);
358 void fill(
const cytnx_int32 &val);
359 void fill(
const cytnx_uint32 &val);
360 void fill(
const cytnx_int16 &val);
361 void fill(
const cytnx_uint16 &val);
362 void fill(
const cytnx_bool &val);
364 void resize(
const cytnx_uint64 &newsize);
366 void append(
const Scalar &val);
367 void append(
const cytnx_complex128 &val);
368 void append(
const cytnx_complex64 &val);
369 void append(
const cytnx_double &val);
370 void append(
const cytnx_float &val);
371 void append(
const cytnx_int64 &val);
372 void append(
const cytnx_uint64 &val);
373 void append(
const cytnx_int32 &val);
374 void append(
const cytnx_uint32 &val);
375 void append(
const cytnx_int16 &val);
376 void append(
const cytnx_uint16 &val);
377 void append(
const cytnx_bool &val);
378 Scalar get_item(
const cytnx_uint64 &in)
const;
381 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
382 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
383 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
384 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
385 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
386 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
387 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
388 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
389 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
390 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
391 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
392 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
398 class ComplexFloatStorage:
public Storage_base{
400 ComplexFloatStorage(){this->dtype=Type.ComplexFloat;};
401 void Init(
const unsigned long long &len_in,
const int &device=-1);
402 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
403 boost::intrusive_ptr<Storage_base> _create_new_sametype();
404 boost::intrusive_ptr<Storage_base> clone();
405 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
406 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
407 void to_(
const int &device);
408 boost::intrusive_ptr<Storage_base> to(
const int &device);
409 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
412 boost::intrusive_ptr<Storage_base> real();
413 boost::intrusive_ptr<Storage_base> imag();
416 void fill(
const cytnx_complex128 &val);
417 void fill(
const cytnx_complex64 &val);
418 void fill(
const cytnx_double &val);
419 void fill(
const cytnx_float &val);
420 void fill(
const cytnx_int64 &val);
421 void fill(
const cytnx_uint64 &val);
422 void fill(
const cytnx_int32 &val);
423 void fill(
const cytnx_uint32 &val);
424 void fill(
const cytnx_int16 &val);
425 void fill(
const cytnx_uint16 &val);
426 void fill(
const cytnx_bool &val);
428 void resize(
const cytnx_uint64 &newsize);
431 void append(
const Scalar &val);
432 void append(
const cytnx_complex128 &val);
433 void append(
const cytnx_complex64 &val);
434 void append(
const cytnx_double &val);
435 void append(
const cytnx_float &val);
436 void append(
const cytnx_int64 &val);
437 void append(
const cytnx_uint64 &val);
438 void append(
const cytnx_int32 &val);
439 void append(
const cytnx_uint32 &val);
440 void append(
const cytnx_int16 &val);
441 void append(
const cytnx_uint16 &val);
442 void append(
const cytnx_bool &val);
443 Scalar get_item(
const cytnx_uint64 &in)
const;
445 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
446 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
447 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
448 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
449 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
450 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
451 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
452 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
453 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
454 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
455 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
456 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
463 class Int64Storage :
public Storage_base{
465 Int64Storage(){this->dtype=Type.Int64;};
466 void Init(
const unsigned long long &len_in,
const int &device=-1);
467 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
468 boost::intrusive_ptr<Storage_base> _create_new_sametype();
469 boost::intrusive_ptr<Storage_base> clone();
470 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
471 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
472 void to_(
const int &device);
473 boost::intrusive_ptr<Storage_base> to(
const int &device);
474 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
477 boost::intrusive_ptr<Storage_base> real();
478 boost::intrusive_ptr<Storage_base> imag();
482 void fill(
const cytnx_complex128 &val);
483 void fill(
const cytnx_complex64 &val);
484 void fill(
const cytnx_double &val);
485 void fill(
const cytnx_float &val);
486 void fill(
const cytnx_int64 &val);
487 void fill(
const cytnx_uint64 &val);
488 void fill(
const cytnx_int32 &val);
489 void fill(
const cytnx_uint32 &val);
490 void fill(
const cytnx_int16 &val);
491 void fill(
const cytnx_uint16 &val);
492 void fill(
const cytnx_bool &val);
494 void resize(
const cytnx_uint64 &newsize);
497 void append(
const Scalar &val);
498 void append(
const cytnx_complex128 &val);
499 void append(
const cytnx_complex64 &val);
500 void append(
const cytnx_double &val);
501 void append(
const cytnx_float &val);
502 void append(
const cytnx_int64 &val);
503 void append(
const cytnx_uint64 &val);
504 void append(
const cytnx_int32 &val);
505 void append(
const cytnx_uint32 &val);
506 void append(
const cytnx_int16 &val);
507 void append(
const cytnx_uint16 &val);
508 void append(
const cytnx_bool &val);
509 Scalar get_item(
const cytnx_uint64 &in)
const;
512 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
513 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
514 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
515 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
516 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
517 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
518 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
519 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
520 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
521 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
522 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
523 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
530 class Uint64Storage :
public Storage_base{
532 Uint64Storage(){this->dtype=Type.Uint64;};
533 void Init(
const unsigned long long &len_in,
const int &device=-1);
534 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
535 boost::intrusive_ptr<Storage_base> _create_new_sametype();
536 boost::intrusive_ptr<Storage_base> clone();
537 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
538 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
539 void to_(
const int &device);
540 boost::intrusive_ptr<Storage_base> to(
const int &device);
541 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
545 boost::intrusive_ptr<Storage_base> real();
546 boost::intrusive_ptr<Storage_base> imag();
549 void fill(
const cytnx_complex128 &val);
550 void fill(
const cytnx_complex64 &val);
551 void fill(
const cytnx_double &val);
552 void fill(
const cytnx_float &val);
553 void fill(
const cytnx_int64 &val);
554 void fill(
const cytnx_uint64 &val);
555 void fill(
const cytnx_int32 &val);
556 void fill(
const cytnx_uint32 &val);
557 void fill(
const cytnx_int16 &val);
558 void fill(
const cytnx_uint16 &val);
559 void fill(
const cytnx_bool &val);
561 void resize(
const cytnx_uint64 &newsize);
564 void append(
const Scalar &val);
565 void append(
const cytnx_complex128 &val);
566 void append(
const cytnx_complex64 &val);
567 void append(
const cytnx_double &val);
568 void append(
const cytnx_float &val);
569 void append(
const cytnx_int64 &val);
570 void append(
const cytnx_uint64 &val);
571 void append(
const cytnx_int32 &val);
572 void append(
const cytnx_uint32 &val);
573 void append(
const cytnx_int16 &val);
574 void append(
const cytnx_uint16 &val);
575 void append(
const cytnx_bool &val);
576 Scalar get_item(
const cytnx_uint64 &in)
const;
579 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
580 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
581 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
582 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
583 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
584 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
585 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
586 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
587 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
588 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
589 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
590 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
596 class Int32Storage :
public Storage_base{
598 Int32Storage(){this->dtype=Type.Int32;};
599 void Init(
const unsigned long long &len_in,
const int &device=-1);
600 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
601 boost::intrusive_ptr<Storage_base> _create_new_sametype();
602 boost::intrusive_ptr<Storage_base> clone();
603 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
604 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
605 void to_(
const int &device);
606 boost::intrusive_ptr<Storage_base> to(
const int &device);
607 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
610 boost::intrusive_ptr<Storage_base> real();
611 boost::intrusive_ptr<Storage_base> imag();
614 void fill(
const cytnx_complex128 &val);
615 void fill(
const cytnx_complex64 &val);
616 void fill(
const cytnx_double &val);
617 void fill(
const cytnx_float &val);
618 void fill(
const cytnx_int64 &val);
619 void fill(
const cytnx_uint64 &val);
620 void fill(
const cytnx_int32 &val);
621 void fill(
const cytnx_uint32 &val);
622 void fill(
const cytnx_int16 &val);
623 void fill(
const cytnx_uint16 &val);
624 void fill(
const cytnx_bool &val);
626 void resize(
const cytnx_uint64 &newsize);
627 void append(
const Scalar &val);
628 void append(
const cytnx_complex128 &val);
629 void append(
const cytnx_complex64 &val);
630 void append(
const cytnx_double &val);
631 void append(
const cytnx_float &val);
632 void append(
const cytnx_int64 &val);
633 void append(
const cytnx_uint64 &val);
634 void append(
const cytnx_int32 &val);
635 void append(
const cytnx_uint32 &val);
636 void append(
const cytnx_int16 &val);
637 void append(
const cytnx_uint16 &val);
638 void append(
const cytnx_bool &val);
639 Scalar get_item(
const cytnx_uint64 &in)
const;
642 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
643 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
644 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
645 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
646 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
647 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
648 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
649 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
650 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
651 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
652 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
653 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
660 class Uint32Storage :
public Storage_base{
662 Uint32Storage(){this->dtype=Type.Uint32;};
663 void Init(
const unsigned long long &len_in,
const int &device=-1);
664 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
665 boost::intrusive_ptr<Storage_base> _create_new_sametype();
666 boost::intrusive_ptr<Storage_base> clone();
667 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
668 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
669 void to_(
const int &device);
670 boost::intrusive_ptr<Storage_base> to(
const int &device);
671 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
674 boost::intrusive_ptr<Storage_base> real();
675 boost::intrusive_ptr<Storage_base> imag();
679 void fill(
const cytnx_complex128 &val);
680 void fill(
const cytnx_complex64 &val);
681 void fill(
const cytnx_double &val);
682 void fill(
const cytnx_float &val);
683 void fill(
const cytnx_int64 &val);
684 void fill(
const cytnx_uint64 &val);
685 void fill(
const cytnx_int32 &val);
686 void fill(
const cytnx_uint32 &val);
687 void fill(
const cytnx_int16 &val);
688 void fill(
const cytnx_uint16 &val);
689 void fill(
const cytnx_bool &val);
691 void resize(
const cytnx_uint64 &newsize);
692 void append(
const Scalar &val);
693 void append(
const cytnx_complex128 &val);
694 void append(
const cytnx_complex64 &val);
695 void append(
const cytnx_double &val);
696 void append(
const cytnx_float &val);
697 void append(
const cytnx_int64 &val);
698 void append(
const cytnx_uint64 &val);
699 void append(
const cytnx_int32 &val);
700 void append(
const cytnx_uint32 &val);
701 void append(
const cytnx_int16 &val);
702 void append(
const cytnx_uint16 &val);
703 void append(
const cytnx_bool &val);
704 Scalar get_item(
const cytnx_uint64 &in)
const;
706 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
707 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
708 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
709 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
710 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
711 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
712 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
713 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
714 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
715 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
716 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
717 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
723 class Uint16Storage :
public Storage_base{
725 Uint16Storage(){this->dtype=Type.Uint16;};
726 void Init(
const unsigned long long &len_in,
const int &device=-1);
727 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
728 boost::intrusive_ptr<Storage_base> _create_new_sametype();
729 boost::intrusive_ptr<Storage_base> clone();
730 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
731 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
732 void to_(
const int &device);
733 boost::intrusive_ptr<Storage_base> to(
const int &device);
734 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
737 boost::intrusive_ptr<Storage_base> real();
738 boost::intrusive_ptr<Storage_base> imag();
741 void fill(
const cytnx_complex128 &val);
742 void fill(
const cytnx_complex64 &val);
743 void fill(
const cytnx_double &val);
744 void fill(
const cytnx_float &val);
745 void fill(
const cytnx_int64 &val);
746 void fill(
const cytnx_uint64 &val);
747 void fill(
const cytnx_int32 &val);
748 void fill(
const cytnx_uint32 &val);
749 void fill(
const cytnx_int16 &val);
750 void fill(
const cytnx_uint16 &val);
751 void fill(
const cytnx_bool &val);
753 void resize(
const cytnx_uint64 &newsize);
755 void append(
const Scalar &val);
756 void append(
const cytnx_complex128 &val);
757 void append(
const cytnx_complex64 &val);
758 void append(
const cytnx_double &val);
759 void append(
const cytnx_float &val);
760 void append(
const cytnx_int64 &val);
761 void append(
const cytnx_uint64 &val);
762 void append(
const cytnx_int32 &val);
763 void append(
const cytnx_uint32 &val);
764 void append(
const cytnx_int16 &val);
765 void append(
const cytnx_uint16 &val);
766 void append(
const cytnx_bool &val);
767 Scalar get_item(
const cytnx_uint64 &in)
const;
770 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
771 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
772 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
773 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
774 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
775 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
776 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
777 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
778 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
779 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
780 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
781 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
789 class Int16Storage :
public Storage_base{
791 Int16Storage(){this->dtype=Type.Int16;};
792 void Init(
const unsigned long long &len_in,
const int &device=-1);
793 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
794 boost::intrusive_ptr<Storage_base> _create_new_sametype();
795 boost::intrusive_ptr<Storage_base> clone();
796 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
797 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
798 void to_(
const int &device);
799 boost::intrusive_ptr<Storage_base> to(
const int &device);
800 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
803 boost::intrusive_ptr<Storage_base> real();
804 boost::intrusive_ptr<Storage_base> imag();
807 void fill(
const cytnx_complex128 &val);
808 void fill(
const cytnx_complex64 &val);
809 void fill(
const cytnx_double &val);
810 void fill(
const cytnx_float &val);
811 void fill(
const cytnx_int64 &val);
812 void fill(
const cytnx_uint64 &val);
813 void fill(
const cytnx_int32 &val);
814 void fill(
const cytnx_uint32 &val);
815 void fill(
const cytnx_int16 &val);
816 void fill(
const cytnx_uint16 &val);
817 void fill(
const cytnx_bool &val);
819 void resize(
const cytnx_uint64 &newsize);
820 void append(
const Scalar &val);
821 void append(
const cytnx_complex128 &val);
822 void append(
const cytnx_complex64 &val);
823 void append(
const cytnx_double &val);
824 void append(
const cytnx_float &val);
825 void append(
const cytnx_int64 &val);
826 void append(
const cytnx_uint64 &val);
827 void append(
const cytnx_int32 &val);
828 void append(
const cytnx_uint32 &val);
829 void append(
const cytnx_int16 &val);
830 void append(
const cytnx_uint16 &val);
831 void append(
const cytnx_bool &val);
832 Scalar get_item(
const cytnx_uint64 &in)
const;
835 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
836 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
837 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
838 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
839 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
840 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
841 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
842 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
843 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
844 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
845 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
846 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
855 class BoolStorage :
public Storage_base{
857 BoolStorage(){this->dtype=Type.Bool;};
858 void Init(
const unsigned long long &len_in,
const int &device=-1);
859 void _Init_byptr(
void *rawptr,
const unsigned long long &len_in,
const int &device=-1,
const bool &iscap=
false,
const unsigned long long &cap_in=0);
860 boost::intrusive_ptr<Storage_base> _create_new_sametype();
861 boost::intrusive_ptr<Storage_base> clone();
862 boost::intrusive_ptr<Storage_base> Move_memory(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
863 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
864 void to_(
const int &device);
865 boost::intrusive_ptr<Storage_base> to(
const int &device);
866 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
869 boost::intrusive_ptr<Storage_base> real();
870 boost::intrusive_ptr<Storage_base> imag();
873 void fill(
const cytnx_complex128 &val);
874 void fill(
const cytnx_complex64 &val);
875 void fill(
const cytnx_double &val);
876 void fill(
const cytnx_float &val);
877 void fill(
const cytnx_int64 &val);
878 void fill(
const cytnx_uint64 &val);
879 void fill(
const cytnx_int32 &val);
880 void fill(
const cytnx_uint32 &val);
881 void fill(
const cytnx_int16 &val);
882 void fill(
const cytnx_uint16 &val);
883 void fill(
const cytnx_bool &val);
885 void resize(
const cytnx_uint64 &newsize);
886 void append(
const Scalar &val);
887 void append(
const cytnx_complex128 &val);
888 void append(
const cytnx_complex64 &val);
889 void append(
const cytnx_double &val);
890 void append(
const cytnx_float &val);
891 void append(
const cytnx_int64 &val);
892 void append(
const cytnx_uint64 &val);
893 void append(
const cytnx_int32 &val);
894 void append(
const cytnx_uint32 &val);
895 void append(
const cytnx_int16 &val);
896 void append(
const cytnx_uint16 &val);
897 void append(
const cytnx_bool &val);
898 Scalar get_item(
const cytnx_uint64 &in)
const;
901 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
902 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
903 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
904 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
905 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
906 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
907 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
908 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
909 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
910 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
911 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
912 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
921 typedef boost::intrusive_ptr<Storage_base> (*pStorage_init)();
925 class Storage_init_interface:
public Type_class{
927 std::vector<pStorage_init> USIInit;
928 Storage_init_interface();
930 extern Storage_init_interface
__SII;
941 boost::intrusive_ptr<Storage_base> _impl;
976 this->_impl =
rhs._impl;
984 Storage(
const std::initializer_list<Tp> &
rhs){
990 this->_impl =
rhs._impl;
999 void _Save(std::fstream &
f)
const;
1000 void _Load(std::fstream &
f);
1014 void Save(
const std::string &
fname)
const;
1062 return this->_impl->dtype;
1071 std::string
out = this->_impl->dtype_str();
1080 return this->_impl->device;
1089 std::string
out = this->_impl->device_str();
1102 return this->_impl->append(
val);
1108 return this->_impl->at<
T>(
idx);
1112 Scalar::Sproxy
out(this->_impl,
idx);
1116 Scalar::Sproxy
out(this->_impl,
idx);
1122 return this->_impl->back<
T>();
1125 const Scalar::Sproxy
back()
const{
1126 Scalar::Sproxy
out(this->_impl,this->
size()-1);
1129 Scalar::Sproxy
back(){
1130 Scalar::Sproxy
out(this->_impl,this->
size()-1);
1137 return this->_impl->data<
T>();
1141 return this->_impl->data();
1162 this->_impl->to_(
device);
1193 return Storage(this->_impl->clone());
1201 const unsigned long long &
size()
const{
1202 return this->_impl->len;
1211 return this->_impl->cap;
1219 this->_impl->print_info();
1224 this->_impl->print();
1236 this->_impl->set_zeros();
1267 this->_impl->fill(
val);
1294 cytnx_error_msg(
Type.cy_typeid(
tmp)!=
this->dtype(),
"[ERROR] the dtype of current Storage does not match assigned vector type.%s",
"\n");
1296 std::vector<T>
out(this->
size());
1322 this->_impl =
__SII.USIInit[
Type.ComplexDouble]();
1327 this->_impl =
__SII.USIInit[
Type.ComplexFloat]();
1332 this->_impl =
__SII.USIInit[
Type.Double]();
1337 this->_impl =
__SII.USIInit[
Type.Float]();
1342 this->_impl =
__SII.USIInit[
Type.Uint64]();
1347 this->_impl =
__SII.USIInit[
Type.Int64]();
1352 this->_impl =
__SII.USIInit[
Type.Uint32]();
1357 this->_impl =
__SII.USIInit[
Type.Int32]();
1362 this->_impl =
__SII.USIInit[
Type.Uint16]();
1367 this->_impl =
__SII.USIInit[
Type.Int16]();
1372 this->_impl =
__SII.USIInit[
Type.Bool]();
1374 this->_impl->_cpy_bool(this->_impl->Mem,
vin);
1396 return Storage(this->_impl->real());
1414 return Storage(this->_impl->imag());
1418 return this->_impl->get_item(
idx);
1423 this->_impl->set_item(
idx,
elem);
1432 std::ostream&
operator<<(std::ostream& os,
const Storage &in);
Definition Scalar.hpp:1751
an memeory storage with multi-type/multi-device support
Definition Storage.hpp:934
void to_(const int &device)
move the current Storage to different deivce.
Definition Storage.hpp:1161
void append(const T &val)
append a value
Definition Storage.hpp:1101
const int & device() const
the device-id of current Storage
Definition Storage.hpp:1079
Storage real() const
Get the real part form a Complex type Storage.
Definition Storage.hpp:1395
std::vector< T > vector()
Definition Storage.hpp:1292
Storage(const unsigned long long &size, const unsigned int &dtype=Type.Double, int device=-1)
Definition Storage.hpp:967
Storage to(const int &device)
move a new Storage with same content as current Storage on different deivce.
Definition Storage.hpp:1174
void resize(const cytnx_uint64 &newsize)
resize the current Storage.
Definition Storage.hpp:1150
void Save(const std::string &fname) const
Save current Storage to file.
Definition Storage.cpp:92
void fill(const T &val)
set all the elements to the assigned value val
Definition Storage.hpp:1266
Storage()
Definition Storage.hpp:970
void Tofile(const std::string &fname) const
Definition Storage.cpp:111
const unsigned int & dtype() const
the dtype-id of current Storage
Definition Storage.hpp:1061
void set_item(const cytnx_uint64 &idx, const T &elem)
Definition Storage.hpp:1422
void Init(const unsigned long long &size, const unsigned int &dtype=Type.Double, int device=-1)
initialize a Storage
Definition Storage.hpp:962
const unsigned long long & capacity() const
the capacity ( no. of real elements in memory) in the Storage
Definition Storage.hpp:1210
void set_zeros()
set all the elements to zero.
Definition Storage.hpp:1235
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:1052
const unsigned long long & size() const
the size ( no. of elements ) in the Storage
Definition Storage.hpp:1201
void print_info() const
print the info of the Storage, including the device, dtype and size.
Definition Storage.hpp:1218
static Storage from_vector(const std::vector< T > &vin, const int device=-1)
Definition Storage.hpp:1279
bool operator!=(const Storage &rhs)
Definition Storage.cpp:87
static Storage Fromfile(const std::string &fname, const unsigned int &dtype, const cytnx_int64 &count=-1)
Definition Storage.cpp:193
const std::string dtype_str() const
the dtype (std::string) of current Storage
Definition Storage.hpp:1070
Scalar::Sproxy operator()(const cytnx_uint64 &idx)
Definition Storage.cpp:315
void Tofile(std::fstream &f) const
bool operator==(const Storage &rhs)
compare two Storage
Definition Storage.cpp:20
Scalar get_item(const cytnx_uint64 &idx) const
Definition Storage.hpp:1417
Storage imag() const
Get the imaginary part form a Complex type Storage.
Definition Storage.hpp:1413
const std::string device_str() const
the device (std::string) of current Storage
Definition Storage.hpp:1088
Storage clone() const
return a copy of current storage.
Definition Storage.hpp:1192
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
Definition Accessor.hpp:12
Device_class Device
Definition Device.cpp:105
double cytnx_double
Definition Type.hpp:20
uint32_t cytnx_uint32
Definition Type.hpp:23
std::complex< double > cytnx_complex128
Definition Type.hpp:30
float cytnx_float
Definition Type.hpp:21
std::ostream & operator<<(std::ostream &os, const Scalar &in)
Definition Scalar.cpp:14
int16_t cytnx_int16
Definition Type.hpp:27
std::complex< float > cytnx_complex64
Definition Type.hpp:29
int32_t cytnx_int32
Definition Type.hpp:26
uint16_t cytnx_uint16
Definition Type.hpp:24
uint64_t cytnx_uint64
Definition Type.hpp:22
int64_t cytnx_int64
Definition Type.hpp:25
Storage_init_interface __SII
Definition Storage.cpp:13
Type_class Type
Definition Type.cpp:143