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);
171 virtual void append(
const cytnx_complex128 &val);
172 virtual void append(
const cytnx_complex64 &val);
173 virtual void append(
const cytnx_double &val);
174 virtual void append(
const cytnx_float &val);
175 virtual void append(
const cytnx_int64 &val);
176 virtual void append(
const cytnx_uint64 &val);
177 virtual void append(
const cytnx_int32 &val);
178 virtual void append(
const cytnx_uint32 &val);
179 virtual void append(
const cytnx_int16 &val);
180 virtual void append(
const cytnx_uint16 &val);
181 virtual void append(
const cytnx_bool &val);
183 virtual Scalar get_item(
const cytnx_uint64 &in)
const;
185 virtual void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
186 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
187 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
188 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
189 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
190 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
191 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
192 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
193 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
194 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
195 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
196 virtual void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
203 class FloatStorage :
public Storage_base{
205 FloatStorage(){this->dtype=Type.Float;};
206 void Init(
const unsigned long long &len_in,
const int &device=-1);
207 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);
208 boost::intrusive_ptr<Storage_base> _create_new_sametype();
209 boost::intrusive_ptr<Storage_base> clone();
210 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);
211 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
212 void to_(
const int &device);
213 boost::intrusive_ptr<Storage_base> to(
const int &device);
214 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
217 boost::intrusive_ptr<Storage_base> real();
218 boost::intrusive_ptr<Storage_base> imag();
222 void fill(
const cytnx_complex128 &val);
223 void fill(
const cytnx_complex64 &val);
224 void fill(
const cytnx_double &val);
225 void fill(
const cytnx_float &val);
226 void fill(
const cytnx_int64 &val);
227 void fill(
const cytnx_uint64 &val);
228 void fill(
const cytnx_int32 &val);
229 void fill(
const cytnx_uint32 &val);
230 void fill(
const cytnx_int16 &val);
231 void fill(
const cytnx_uint16 &val);
232 void fill(
const cytnx_bool &val);
234 void resize(
const cytnx_uint64 &newsize);
236 void append(
const cytnx_complex128 &val);
237 void append(
const cytnx_complex64 &val);
238 void append(
const cytnx_double &val);
239 void append(
const cytnx_float &val);
240 void append(
const cytnx_int64 &val);
241 void append(
const cytnx_uint64 &val);
242 void append(
const cytnx_int32 &val);
243 void append(
const cytnx_uint32 &val);
244 void append(
const cytnx_int16 &val);
245 void append(
const cytnx_uint16 &val);
246 void append(
const cytnx_bool &val);
247 Scalar get_item(
const cytnx_uint64 &in)
const;
250 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
251 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
252 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
253 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
254 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
255 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
256 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
257 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
258 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
259 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
260 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
261 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
268 class DoubleStorage:
public Storage_base{
270 DoubleStorage(){this->dtype=Type.Double;};
271 void Init(
const unsigned long long &len_in,
const int &device=-1);
272 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);
273 boost::intrusive_ptr<Storage_base> _create_new_sametype();
274 boost::intrusive_ptr<Storage_base> clone();
275 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);
276 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
277 void to_(
const int &device);
278 boost::intrusive_ptr<Storage_base> to(
const int &device);
279 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
282 boost::intrusive_ptr<Storage_base> real();
283 boost::intrusive_ptr<Storage_base> imag();
286 void fill(
const cytnx_complex128 &val);
287 void fill(
const cytnx_complex64 &val);
288 void fill(
const cytnx_double &val);
289 void fill(
const cytnx_float &val);
290 void fill(
const cytnx_int64 &val);
291 void fill(
const cytnx_uint64 &val);
292 void fill(
const cytnx_int32 &val);
293 void fill(
const cytnx_uint32 &val);
294 void fill(
const cytnx_int16 &val);
295 void fill(
const cytnx_uint16 &val);
296 void fill(
const cytnx_bool &val);
298 void resize(
const cytnx_uint64 &newsize);
300 void append(
const cytnx_complex128 &val);
301 void append(
const cytnx_complex64 &val);
302 void append(
const cytnx_double &val);
303 void append(
const cytnx_float &val);
304 void append(
const cytnx_int64 &val);
305 void append(
const cytnx_uint64 &val);
306 void append(
const cytnx_int32 &val);
307 void append(
const cytnx_uint32 &val);
308 void append(
const cytnx_int16 &val);
309 void append(
const cytnx_uint16 &val);
310 void append(
const cytnx_bool &val);
311 Scalar get_item(
const cytnx_uint64 &in)
const;
313 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
314 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
315 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
316 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
317 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
318 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
319 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
320 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
321 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
322 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
323 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
324 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
330 class ComplexDoubleStorage:
public Storage_base{
332 ComplexDoubleStorage(){this->dtype=Type.ComplexDouble;};
333 void Init(
const unsigned long long &len_in,
const int &device=-1);
334 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);
335 boost::intrusive_ptr<Storage_base> _create_new_sametype();
336 boost::intrusive_ptr<Storage_base> clone();
337 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);
338 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
339 void to_(
const int &device);
340 boost::intrusive_ptr<Storage_base> to(
const int &device);
341 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
344 boost::intrusive_ptr<Storage_base> real();
345 boost::intrusive_ptr<Storage_base> imag();
348 void fill(
const cytnx_complex128 &val);
349 void fill(
const cytnx_complex64 &val);
350 void fill(
const cytnx_double &val);
351 void fill(
const cytnx_float &val);
352 void fill(
const cytnx_int64 &val);
353 void fill(
const cytnx_uint64 &val);
354 void fill(
const cytnx_int32 &val);
355 void fill(
const cytnx_uint32 &val);
356 void fill(
const cytnx_int16 &val);
357 void fill(
const cytnx_uint16 &val);
358 void fill(
const cytnx_bool &val);
360 void resize(
const cytnx_uint64 &newsize);
363 void append(
const cytnx_complex128 &val);
364 void append(
const cytnx_complex64 &val);
365 void append(
const cytnx_double &val);
366 void append(
const cytnx_float &val);
367 void append(
const cytnx_int64 &val);
368 void append(
const cytnx_uint64 &val);
369 void append(
const cytnx_int32 &val);
370 void append(
const cytnx_uint32 &val);
371 void append(
const cytnx_int16 &val);
372 void append(
const cytnx_uint16 &val);
373 void append(
const cytnx_bool &val);
374 Scalar get_item(
const cytnx_uint64 &in)
const;
377 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
378 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
379 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
380 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
381 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
382 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
383 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
384 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
385 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
386 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
387 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
388 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
394 class ComplexFloatStorage:
public Storage_base{
396 ComplexFloatStorage(){this->dtype=Type.ComplexFloat;};
397 void Init(
const unsigned long long &len_in,
const int &device=-1);
398 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);
399 boost::intrusive_ptr<Storage_base> _create_new_sametype();
400 boost::intrusive_ptr<Storage_base> clone();
401 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);
402 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
403 void to_(
const int &device);
404 boost::intrusive_ptr<Storage_base> to(
const int &device);
405 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
408 boost::intrusive_ptr<Storage_base> real();
409 boost::intrusive_ptr<Storage_base> imag();
412 void fill(
const cytnx_complex128 &val);
413 void fill(
const cytnx_complex64 &val);
414 void fill(
const cytnx_double &val);
415 void fill(
const cytnx_float &val);
416 void fill(
const cytnx_int64 &val);
417 void fill(
const cytnx_uint64 &val);
418 void fill(
const cytnx_int32 &val);
419 void fill(
const cytnx_uint32 &val);
420 void fill(
const cytnx_int16 &val);
421 void fill(
const cytnx_uint16 &val);
422 void fill(
const cytnx_bool &val);
424 void resize(
const cytnx_uint64 &newsize);
426 void append(
const cytnx_complex128 &val);
427 void append(
const cytnx_complex64 &val);
428 void append(
const cytnx_double &val);
429 void append(
const cytnx_float &val);
430 void append(
const cytnx_int64 &val);
431 void append(
const cytnx_uint64 &val);
432 void append(
const cytnx_int32 &val);
433 void append(
const cytnx_uint32 &val);
434 void append(
const cytnx_int16 &val);
435 void append(
const cytnx_uint16 &val);
436 void append(
const cytnx_bool &val);
437 Scalar get_item(
const cytnx_uint64 &in)
const;
439 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
440 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
441 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
442 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
443 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
444 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
445 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
446 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
447 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
448 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
449 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
450 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
457 class Int64Storage :
public Storage_base{
459 Int64Storage(){this->dtype=Type.Int64;};
460 void Init(
const unsigned long long &len_in,
const int &device=-1);
461 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);
462 boost::intrusive_ptr<Storage_base> _create_new_sametype();
463 boost::intrusive_ptr<Storage_base> clone();
464 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);
465 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
466 void to_(
const int &device);
467 boost::intrusive_ptr<Storage_base> to(
const int &device);
468 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
471 boost::intrusive_ptr<Storage_base> real();
472 boost::intrusive_ptr<Storage_base> imag();
476 void fill(
const cytnx_complex128 &val);
477 void fill(
const cytnx_complex64 &val);
478 void fill(
const cytnx_double &val);
479 void fill(
const cytnx_float &val);
480 void fill(
const cytnx_int64 &val);
481 void fill(
const cytnx_uint64 &val);
482 void fill(
const cytnx_int32 &val);
483 void fill(
const cytnx_uint32 &val);
484 void fill(
const cytnx_int16 &val);
485 void fill(
const cytnx_uint16 &val);
486 void fill(
const cytnx_bool &val);
488 void resize(
const cytnx_uint64 &newsize);
490 void append(
const cytnx_complex128 &val);
491 void append(
const cytnx_complex64 &val);
492 void append(
const cytnx_double &val);
493 void append(
const cytnx_float &val);
494 void append(
const cytnx_int64 &val);
495 void append(
const cytnx_uint64 &val);
496 void append(
const cytnx_int32 &val);
497 void append(
const cytnx_uint32 &val);
498 void append(
const cytnx_int16 &val);
499 void append(
const cytnx_uint16 &val);
500 void append(
const cytnx_bool &val);
501 Scalar get_item(
const cytnx_uint64 &in)
const;
504 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
505 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
506 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
507 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
508 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
509 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
510 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
511 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
512 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
513 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
514 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
515 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
522 class Uint64Storage :
public Storage_base{
524 Uint64Storage(){this->dtype=Type.Uint64;};
525 void Init(
const unsigned long long &len_in,
const int &device=-1);
526 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);
527 boost::intrusive_ptr<Storage_base> _create_new_sametype();
528 boost::intrusive_ptr<Storage_base> clone();
529 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);
530 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
531 void to_(
const int &device);
532 boost::intrusive_ptr<Storage_base> to(
const int &device);
533 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
537 boost::intrusive_ptr<Storage_base> real();
538 boost::intrusive_ptr<Storage_base> imag();
541 void fill(
const cytnx_complex128 &val);
542 void fill(
const cytnx_complex64 &val);
543 void fill(
const cytnx_double &val);
544 void fill(
const cytnx_float &val);
545 void fill(
const cytnx_int64 &val);
546 void fill(
const cytnx_uint64 &val);
547 void fill(
const cytnx_int32 &val);
548 void fill(
const cytnx_uint32 &val);
549 void fill(
const cytnx_int16 &val);
550 void fill(
const cytnx_uint16 &val);
551 void fill(
const cytnx_bool &val);
553 void resize(
const cytnx_uint64 &newsize);
555 void append(
const cytnx_complex128 &val);
556 void append(
const cytnx_complex64 &val);
557 void append(
const cytnx_double &val);
558 void append(
const cytnx_float &val);
559 void append(
const cytnx_int64 &val);
560 void append(
const cytnx_uint64 &val);
561 void append(
const cytnx_int32 &val);
562 void append(
const cytnx_uint32 &val);
563 void append(
const cytnx_int16 &val);
564 void append(
const cytnx_uint16 &val);
565 void append(
const cytnx_bool &val);
566 Scalar get_item(
const cytnx_uint64 &in)
const;
569 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
570 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
571 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
572 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
573 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
574 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
575 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
576 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
577 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
578 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
579 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
580 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
586 class Int32Storage :
public Storage_base{
588 Int32Storage(){this->dtype=Type.Int32;};
589 void Init(
const unsigned long long &len_in,
const int &device=-1);
590 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);
591 boost::intrusive_ptr<Storage_base> _create_new_sametype();
592 boost::intrusive_ptr<Storage_base> clone();
593 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);
594 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
595 void to_(
const int &device);
596 boost::intrusive_ptr<Storage_base> to(
const int &device);
597 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
600 boost::intrusive_ptr<Storage_base> real();
601 boost::intrusive_ptr<Storage_base> imag();
604 void fill(
const cytnx_complex128 &val);
605 void fill(
const cytnx_complex64 &val);
606 void fill(
const cytnx_double &val);
607 void fill(
const cytnx_float &val);
608 void fill(
const cytnx_int64 &val);
609 void fill(
const cytnx_uint64 &val);
610 void fill(
const cytnx_int32 &val);
611 void fill(
const cytnx_uint32 &val);
612 void fill(
const cytnx_int16 &val);
613 void fill(
const cytnx_uint16 &val);
614 void fill(
const cytnx_bool &val);
616 void resize(
const cytnx_uint64 &newsize);
617 void append(
const cytnx_complex128 &val);
618 void append(
const cytnx_complex64 &val);
619 void append(
const cytnx_double &val);
620 void append(
const cytnx_float &val);
621 void append(
const cytnx_int64 &val);
622 void append(
const cytnx_uint64 &val);
623 void append(
const cytnx_int32 &val);
624 void append(
const cytnx_uint32 &val);
625 void append(
const cytnx_int16 &val);
626 void append(
const cytnx_uint16 &val);
627 void append(
const cytnx_bool &val);
628 Scalar get_item(
const cytnx_uint64 &in)
const;
631 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
632 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
633 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
634 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
635 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
636 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
637 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
638 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
639 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
640 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
641 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
642 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
649 class Uint32Storage :
public Storage_base{
651 Uint32Storage(){this->dtype=Type.Uint32;};
652 void Init(
const unsigned long long &len_in,
const int &device=-1);
653 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);
654 boost::intrusive_ptr<Storage_base> _create_new_sametype();
655 boost::intrusive_ptr<Storage_base> clone();
656 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);
657 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
658 void to_(
const int &device);
659 boost::intrusive_ptr<Storage_base> to(
const int &device);
660 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
663 boost::intrusive_ptr<Storage_base> real();
664 boost::intrusive_ptr<Storage_base> imag();
668 void fill(
const cytnx_complex128 &val);
669 void fill(
const cytnx_complex64 &val);
670 void fill(
const cytnx_double &val);
671 void fill(
const cytnx_float &val);
672 void fill(
const cytnx_int64 &val);
673 void fill(
const cytnx_uint64 &val);
674 void fill(
const cytnx_int32 &val);
675 void fill(
const cytnx_uint32 &val);
676 void fill(
const cytnx_int16 &val);
677 void fill(
const cytnx_uint16 &val);
678 void fill(
const cytnx_bool &val);
680 void resize(
const cytnx_uint64 &newsize);
681 void append(
const cytnx_complex128 &val);
682 void append(
const cytnx_complex64 &val);
683 void append(
const cytnx_double &val);
684 void append(
const cytnx_float &val);
685 void append(
const cytnx_int64 &val);
686 void append(
const cytnx_uint64 &val);
687 void append(
const cytnx_int32 &val);
688 void append(
const cytnx_uint32 &val);
689 void append(
const cytnx_int16 &val);
690 void append(
const cytnx_uint16 &val);
691 void append(
const cytnx_bool &val);
692 Scalar get_item(
const cytnx_uint64 &in)
const;
694 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
695 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
696 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
697 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
698 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
699 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
700 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
701 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
702 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
703 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
704 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
705 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
711 class Uint16Storage :
public Storage_base{
713 Uint16Storage(){this->dtype=Type.Uint16;};
714 void Init(
const unsigned long long &len_in,
const int &device=-1);
715 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);
716 boost::intrusive_ptr<Storage_base> _create_new_sametype();
717 boost::intrusive_ptr<Storage_base> clone();
718 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);
719 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
720 void to_(
const int &device);
721 boost::intrusive_ptr<Storage_base> to(
const int &device);
722 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
725 boost::intrusive_ptr<Storage_base> real();
726 boost::intrusive_ptr<Storage_base> imag();
729 void fill(
const cytnx_complex128 &val);
730 void fill(
const cytnx_complex64 &val);
731 void fill(
const cytnx_double &val);
732 void fill(
const cytnx_float &val);
733 void fill(
const cytnx_int64 &val);
734 void fill(
const cytnx_uint64 &val);
735 void fill(
const cytnx_int32 &val);
736 void fill(
const cytnx_uint32 &val);
737 void fill(
const cytnx_int16 &val);
738 void fill(
const cytnx_uint16 &val);
739 void fill(
const cytnx_bool &val);
741 void resize(
const cytnx_uint64 &newsize);
742 void append(
const cytnx_complex128 &val);
743 void append(
const cytnx_complex64 &val);
744 void append(
const cytnx_double &val);
745 void append(
const cytnx_float &val);
746 void append(
const cytnx_int64 &val);
747 void append(
const cytnx_uint64 &val);
748 void append(
const cytnx_int32 &val);
749 void append(
const cytnx_uint32 &val);
750 void append(
const cytnx_int16 &val);
751 void append(
const cytnx_uint16 &val);
752 void append(
const cytnx_bool &val);
753 Scalar get_item(
const cytnx_uint64 &in)
const;
756 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
757 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
758 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
759 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
760 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
761 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
762 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
763 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
764 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
765 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
766 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
767 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
775 class Int16Storage :
public Storage_base{
777 Int16Storage(){this->dtype=Type.Int16;};
778 void Init(
const unsigned long long &len_in,
const int &device=-1);
779 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);
780 boost::intrusive_ptr<Storage_base> _create_new_sametype();
781 boost::intrusive_ptr<Storage_base> clone();
782 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);
783 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
784 void to_(
const int &device);
785 boost::intrusive_ptr<Storage_base> to(
const int &device);
786 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
789 boost::intrusive_ptr<Storage_base> real();
790 boost::intrusive_ptr<Storage_base> imag();
793 void fill(
const cytnx_complex128 &val);
794 void fill(
const cytnx_complex64 &val);
795 void fill(
const cytnx_double &val);
796 void fill(
const cytnx_float &val);
797 void fill(
const cytnx_int64 &val);
798 void fill(
const cytnx_uint64 &val);
799 void fill(
const cytnx_int32 &val);
800 void fill(
const cytnx_uint32 &val);
801 void fill(
const cytnx_int16 &val);
802 void fill(
const cytnx_uint16 &val);
803 void fill(
const cytnx_bool &val);
805 void resize(
const cytnx_uint64 &newsize);
806 void append(
const cytnx_complex128 &val);
807 void append(
const cytnx_complex64 &val);
808 void append(
const cytnx_double &val);
809 void append(
const cytnx_float &val);
810 void append(
const cytnx_int64 &val);
811 void append(
const cytnx_uint64 &val);
812 void append(
const cytnx_int32 &val);
813 void append(
const cytnx_uint32 &val);
814 void append(
const cytnx_int16 &val);
815 void append(
const cytnx_uint16 &val);
816 void append(
const cytnx_bool &val);
817 Scalar get_item(
const cytnx_uint64 &in)
const;
820 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
821 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
822 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
823 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
824 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
825 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
826 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
827 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
828 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
829 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
830 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
831 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
840 class BoolStorage :
public Storage_base{
842 BoolStorage(){this->dtype=Type.Bool;};
843 void Init(
const unsigned long long &len_in,
const int &device=-1);
844 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);
845 boost::intrusive_ptr<Storage_base> _create_new_sametype();
846 boost::intrusive_ptr<Storage_base> clone();
847 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);
848 void Move_memory_(
const std::vector<cytnx_uint64> &old_shape,
const std::vector<cytnx_uint64> &mapper,
const std::vector<cytnx_uint64> &invmapper);
849 void to_(
const int &device);
850 boost::intrusive_ptr<Storage_base> to(
const int &device);
851 void PrintElem_byShape(std::ostream& os,
const std::vector<cytnx_uint64> &shape,
const std::vector<cytnx_uint64> &mapper={});
854 boost::intrusive_ptr<Storage_base> real();
855 boost::intrusive_ptr<Storage_base> imag();
858 void fill(
const cytnx_complex128 &val);
859 void fill(
const cytnx_complex64 &val);
860 void fill(
const cytnx_double &val);
861 void fill(
const cytnx_float &val);
862 void fill(
const cytnx_int64 &val);
863 void fill(
const cytnx_uint64 &val);
864 void fill(
const cytnx_int32 &val);
865 void fill(
const cytnx_uint32 &val);
866 void fill(
const cytnx_int16 &val);
867 void fill(
const cytnx_uint16 &val);
868 void fill(
const cytnx_bool &val);
870 void resize(
const cytnx_uint64 &newsize);
871 void append(
const cytnx_complex128 &val);
872 void append(
const cytnx_complex64 &val);
873 void append(
const cytnx_double &val);
874 void append(
const cytnx_float &val);
875 void append(
const cytnx_int64 &val);
876 void append(
const cytnx_uint64 &val);
877 void append(
const cytnx_int32 &val);
878 void append(
const cytnx_uint32 &val);
879 void append(
const cytnx_int16 &val);
880 void append(
const cytnx_uint16 &val);
881 void append(
const cytnx_bool &val);
882 Scalar get_item(
const cytnx_uint64 &in)
const;
885 void set_item(
const cytnx_uint64 &idx,
const Scalar &val);
886 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex128 &val);
887 void set_item(
const cytnx_uint64 &idx,
const cytnx_complex64 &val);
888 void set_item(
const cytnx_uint64 &idx,
const cytnx_double &val);
889 void set_item(
const cytnx_uint64 &idx,
const cytnx_float &val);
890 void set_item(
const cytnx_uint64 &idx,
const cytnx_int64 &val);
891 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint64 &val);
892 void set_item(
const cytnx_uint64 &idx,
const cytnx_int32 &val);
893 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint32 &val);
894 void set_item(
const cytnx_uint64 &idx,
const cytnx_int16 &val);
895 void set_item(
const cytnx_uint64 &idx,
const cytnx_uint16 &val);
896 void set_item(
const cytnx_uint64 &idx,
const cytnx_bool &val);
905 typedef boost::intrusive_ptr<Storage_base> (*pStorage_init)();
909 class Storage_init_interface:
public Type_class{
911 std::vector<pStorage_init> USIInit;
912 Storage_init_interface();
914 extern Storage_init_interface
__SII;
925 boost::intrusive_ptr<Storage_base> _impl;
960 this->_impl =
rhs._impl;
968 Storage(
const std::initializer_list<Tp> &
rhs){
974 this->_impl =
rhs._impl;
983 void _Save(std::fstream &
f)
const;
984 void _Load(std::fstream &
f);
998 void Save(
const std::string &
fname)
const;
1046 return this->_impl->dtype;
1055 std::string
out = this->_impl->dtype_str();
1064 return this->_impl->device;
1073 std::string
out = this->_impl->device_str();
1086 return this->_impl->append(
val);
1092 return this->_impl->at<
T>(
idx);
1096 Scalar::Sproxy
out(this->_impl,
idx);
1100 Scalar::Sproxy
out(this->_impl,
idx);
1106 return this->_impl->back<
T>();
1109 const Scalar::Sproxy
back()
const{
1110 Scalar::Sproxy
out(this->_impl,this->
size()-1);
1113 Scalar::Sproxy
back(){
1114 Scalar::Sproxy
out(this->_impl,this->
size()-1);
1121 return this->_impl->data<
T>();
1125 return this->_impl->data();
1146 this->_impl->to_(
device);
1177 return Storage(this->_impl->clone());
1185 const unsigned long long &
size()
const{
1186 return this->_impl->len;
1195 return this->_impl->cap;
1203 this->_impl->print_info();
1208 this->_impl->print();
1220 this->_impl->set_zeros();
1251 this->_impl->fill(
val);
1283 this->_impl =
__SII.USIInit[
Type.ComplexDouble]();
1288 this->_impl =
__SII.USIInit[
Type.ComplexFloat]();
1293 this->_impl =
__SII.USIInit[
Type.Double]();
1298 this->_impl =
__SII.USIInit[
Type.Float]();
1303 this->_impl =
__SII.USIInit[
Type.Uint64]();
1308 this->_impl =
__SII.USIInit[
Type.Int64]();
1313 this->_impl =
__SII.USIInit[
Type.Uint32]();
1318 this->_impl =
__SII.USIInit[
Type.Int32]();
1323 this->_impl =
__SII.USIInit[
Type.Uint16]();
1328 this->_impl =
__SII.USIInit[
Type.Int16]();
1333 this->_impl =
__SII.USIInit[
Type.Bool]();
1335 this->_impl->_cpy_bool(this->_impl->Mem,
vin);
1357 return Storage(this->_impl->real());
1375 return Storage(this->_impl->imag());
1379 return this->_impl->get_item(
idx);
1384 this->_impl->set_item(
idx,
elem);
1394 std::ostream&
operator<<(std::ostream& os,
const Storage &in);
Definition Scalar.hpp:1630
an memeory storage with multi-type/multi-device support
Definition Storage.hpp:918
void to_(const int &device)
move the current Storage to different deivce.
Definition Storage.hpp:1145
void append(const T &val)
append a value
Definition Storage.hpp:1085
const int & device() const
the device-id of current Storage
Definition Storage.hpp:1063
Storage real() const
Get the real part form a Complex type Storage.
Definition Storage.hpp:1356
Storage(const unsigned long long &size, const unsigned int &dtype=Type.Double, int device=-1)
Definition Storage.hpp:951
Storage to(const int &device)
move a new Storage with same content as current Storage on different deivce.
Definition Storage.hpp:1158
void resize(const cytnx_uint64 &newsize)
resize the current Storage.
Definition Storage.hpp:1134
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:1250
Storage()
Definition Storage.hpp:954
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:1045
void set_item(const cytnx_uint64 &idx, const T &elem)
Definition Storage.hpp:1383
void Init(const unsigned long long &size, const unsigned int &dtype=Type.Double, int device=-1)
initialize a Storage
Definition Storage.hpp:946
const unsigned long long & capacity() const
the capacity ( no. of real elements in memory) in the Storage
Definition Storage.hpp:1194
void set_zeros()
set all the elements to zero.
Definition Storage.hpp:1219
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:1036
const unsigned long long & size() const
the size ( no. of elements ) in the Storage
Definition Storage.hpp:1185
void print_info() const
print the info of the Storage, including the device, dtype and size.
Definition Storage.hpp:1202
static Storage from_vector(const std::vector< T > &vin, const int device=-1)
Definition Storage.hpp:1263
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:1054
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:1378
Storage imag() const
Get the imaginary part form a Complex type Storage.
Definition Storage.hpp:1374
const std::string device_str() const
the device (std::string) of current Storage
Definition Storage.hpp:1072
Storage clone() const
return a copy of current storage.
Definition Storage.hpp:1176
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
Definition Accessor.hpp:12
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:137