|
| void | Init (const unsigned long long &size, const unsigned int &dtype=Type.Double, int device=-1, const bool &init_zero=true) |
| | initialize a Storage
|
| |
| | 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.
|
| |
| | Storage () |
| | The default constructor of Storage class. It will create an empty Storage instance.
|
| |
| void | Save (const std::string &fname) const |
| | Save current Storage to file.
|
| |
| void | Save (const char *fname) const |
| | Save current Storage to file, same as Save(const std::string &fname)
|
| |
| void | Tofile (const std::string &fname) const |
| | Save current Storage to a binary file, which only contains the raw data.
|
| |
| void | Tofile (const char *fname) const |
| |
| void | Tofile (std::fstream &f) const |
| |
| Storage | astype (const unsigned int &new_type) const |
| | cast the type of current Storage
|
| |
| const unsigned int & | dtype () const |
| | the dtype-id of current Storage, see cytnx::Type for more details.
|
| |
| const std::string | dtype_str () const |
| | the dtype (std::string) of current Storage, see cytnx::Type for more details.
|
| |
| const int & | device () const |
| | the device-id of current Storage, see cytnx::Device for more details.
|
| |
| const std::string | device_str () const |
| | the device (std::string) of current Storage, see cytnx::Device for more details.
|
| |
| template<class T > |
| void | append (const T &val) |
| | append a value
|
| |
| void | resize (const cytnx_uint64 &newsize) |
| | resize the current Storage.
|
| |
| void | to_ (const int &device) |
| | Move the current Storage to different deivce.
|
| |
| Storage | to (const int &device) |
| | move a new Storage with same content as current Storage on different deivce.
|
| |
| Storage | clone () const |
| | return a deep copy of the current storage.
|
| |
| const unsigned long long & | size () const |
| | the size ( no. of elements ) in the Storage
|
| |
| const unsigned long long & | capacity () const |
| | the capacity in the Storage.
|
| |
| void | print_info () const |
| | print the info of the Storage, including the device, dtype and size.
|
| |
| void | set_zeros () |
| | set all the elements to zero.
|
| |
| bool | operator== (const Storage &rhs) |
| | compare two Storage
|
| |
| bool | operator!= (const Storage &rhs) |
| | The not-equal operator for Storage.
|
| |
| template<class T > |
| void | fill (const T &val) |
| | set all the elements to the assigned value val
|
| |
| template<class T > |
| std::vector< T > | vector () |
| | renew/create a c++ std::vector using current Storage.
|
| |
| Storage | real () const |
| | Get the real part form a Complex type Storage.
|
| |
| Storage | imag () const |
| | Get the imaginary part form a Complex type Storage.
|
| |
| Scalar | get_item (const cytnx_uint64 &idx) const |
| | Get the element at the given index.
|
| |
| template<class T > |
| void | set_item (const cytnx_uint64 &idx, const T &elem) |
| | Set the element at the given index.
|
| |
| Scalar::Sproxy | operator() (const cytnx_uint64 &idx) |
| | The access operator for the Storage.
|
| |
an memeory storage with multi-type/multi-device support
| Storage cytnx::Storage::imag |
( |
| ) |
const |
|
inline |
Get the imaginary part form a Complex type Storage.
- Note
- Cannot be called from a real type Storage.
Example:
c++ API:
#include <iostream>
for (
unsigned int i = 0;
i <
S1.size();
i++) {
}
for (
unsigned int i = 0;
i <
S1.size();
i++) {
}
return 0;
}
Storage imag() const
Get the imaginary part form a Complex type Storage.
Definition Storage.hpp:1567
std::complex< double > cytnx_complex128
Definition Type.hpp:53
std::complex< float > cytnx_complex64
Definition Type.hpp:52
output>
dtype : Complex Double (Complex Float64)
device: cytnx device: CPU
size : 10
[ 0.00000e+00+1.00000e+00j 1.00000e+00+2.00000e+00j 2.00000e+00+3.00000e+00j 3.00000e+00+4.00000e+00j 4.00000e+00+5.00000e+00j 5.00000e+00+6.00000e+00j 6.00000e+00+7.00000e+00j 7.00000e+00+8.00000e+00j 8.00000e+00+9.00000e+00j 9.00000e+00+1.00000e+01j ]
dtype : Double (Float64)
device: cytnx device: CPU
size : 10
[ 1.00000e+00 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 8.00000e+00 9.00000e+00 1.00000e+01 ]
dtype : Complex Float (Complex Float32)
device: cytnx device: CPU
size : 10
[ 0.00000e+00+2.00000e+00j 1.00000e+00+3.00000e+00j 2.00000e+00+4.00000e+00j 3.00000e+00+5.00000e+00j 4.00000e+00+6.00000e+00j 5.00000e+00+7.00000e+00j 6.00000e+00+8.00000e+00j 7.00000e+00+9.00000e+00j 8.00000e+00+1.00000e+01j 9.00000e+00+1.10000e+01j ]
dtype : Float (Float32)
device: cytnx device: CPU
size : 10
[ 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]
python API:
import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
S1 = Storage(10,Type.ComplexDouble)
for i in range(10):
S1[i] = i + 1j*(i+1)
S1r = S1.imag()
print(S1)
print(S1r)
S2 = Storage(10,Type.ComplexFloat)
for i in range(10):
S2[i] = i + 1j*(i+1)
S2r = S2.imag()
print(S2)
print(S2r)
output>
dtype : Complex Double (Complex Float64)
device: cytnx device: CPU
size : 10
[ 0.00000e+00+1.00000e+00j 1.00000e+00+2.00000e+00j 2.00000e+00+3.00000e+00j 3.00000e+00+4.00000e+00j 4.00000e+00+5.00000e+00j 5.00000e+00+6.00000e+00j 6.00000e+00+7.00000e+00j 7.00000e+00+8.00000e+00j 8.00000e+00+9.00000e+00j 9.00000e+00+1.00000e+01j ]
dtype : Double (Float64)
device: cytnx device: CPU
size : 10
[ 1.00000e+00 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 8.00000e+00 9.00000e+00 1.00000e+01 ]
dtype : Complex Float (Complex Float32)
device: cytnx device: CPU
size : 10
[ 0.00000e+00+1.00000e+00j 1.00000e+00+2.00000e+00j 2.00000e+00+3.00000e+00j 3.00000e+00+4.00000e+00j 4.00000e+00+5.00000e+00j 5.00000e+00+6.00000e+00j 6.00000e+00+7.00000e+00j 7.00000e+00+8.00000e+00j 8.00000e+00+9.00000e+00j 9.00000e+00+1.00000e+01j ]
dtype : Float (Float32)
device: cytnx device: CPU
size : 10
[ 1.00000e+00 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 8.00000e+00 9.00000e+00 1.00000e+01 ]
| Storage cytnx::Storage::real |
( |
| ) |
const |
|
inline |
Get the real part form a Complex type Storage.
- Note
- Cannot be called from a real type Storage.
Example:
c++ API:
#include <iostream>
for (
unsigned int i = 0;
i <
S1.size();
i++) {
}
for (
unsigned int i = 0;
i <
S1.size();
i++) {
}
return 0;
}
Storage real() const
Get the real part form a Complex type Storage.
Definition Storage.hpp:1551
output>
dtype : Complex Double (Complex Float64)
device: cytnx device: CPU
size : 10
[ 0.00000e+00+1.00000e+00j 1.00000e+00+2.00000e+00j 2.00000e+00+3.00000e+00j 3.00000e+00+4.00000e+00j 4.00000e+00+5.00000e+00j 5.00000e+00+6.00000e+00j 6.00000e+00+7.00000e+00j 7.00000e+00+8.00000e+00j 8.00000e+00+9.00000e+00j 9.00000e+00+1.00000e+01j ]
dtype : Double (Float64)
device: cytnx device: CPU
size : 10
[ 0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 8.00000e+00 9.00000e+00 ]
dtype : Complex Float (Complex Float32)
device: cytnx device: CPU
size : 10
[ 0.00000e+00+2.00000e+00j 1.00000e+00+3.00000e+00j 2.00000e+00+4.00000e+00j 3.00000e+00+5.00000e+00j 4.00000e+00+6.00000e+00j 5.00000e+00+7.00000e+00j 6.00000e+00+8.00000e+00j 7.00000e+00+9.00000e+00j 8.00000e+00+1.00000e+01j 9.00000e+00+1.10000e+01j ]
dtype : Float (Float32)
device: cytnx device: CPU
size : 10
[ 0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 8.00000e+00 9.00000e+00 ]
python API:
import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
S1 = Storage(10,Type.ComplexDouble)
for i in range(10):
S1[i] = i + 1j*(i+1)
S1r = S1.real()
print(S1)
print(S1r)
S2 = Storage(10,Type.ComplexFloat)
for i in range(10):
S2[i] = i + 1j*(i+1)
S2r = S2.real()
print(S2)
print(S2r)
output>
dtype : Complex Double (Complex Float64)
device: cytnx device: CPU
size : 10
[ 0.00000e+00+1.00000e+00j 1.00000e+00+2.00000e+00j 2.00000e+00+3.00000e+00j 3.00000e+00+4.00000e+00j 4.00000e+00+5.00000e+00j 5.00000e+00+6.00000e+00j 6.00000e+00+7.00000e+00j 7.00000e+00+8.00000e+00j 8.00000e+00+9.00000e+00j 9.00000e+00+1.00000e+01j ]
dtype : Double (Float64)
device: cytnx device: CPU
size : 10
[ 0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 8.00000e+00 9.00000e+00 ]
dtype : Complex Float (Complex Float32)
device: cytnx device: CPU
size : 10
[ 0.00000e+00+1.00000e+00j 1.00000e+00+2.00000e+00j 2.00000e+00+3.00000e+00j 3.00000e+00+4.00000e+00j 4.00000e+00+5.00000e+00j 5.00000e+00+6.00000e+00j 6.00000e+00+7.00000e+00j 7.00000e+00+8.00000e+00j 8.00000e+00+9.00000e+00j 9.00000e+00+1.00000e+01j ]
dtype : Float (Float32)
device: cytnx device: CPU
size : 10
[ 0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 8.00000e+00 9.00000e+00 ]