Cytnx v0.9.1
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cytnx::Storage Class Reference

an memeory storage with multi-type/multi-device support More...

#include <Storage.hpp>

Public Member Functions

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 intdtype () 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 intdevice () 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 longsize () const
 the size ( no. of elements ) in the Storage
 
const unsigned long longcapacity () 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.
 

Static Public Member Functions

static Storage Load (const std::string &fname)
 Load current Storage from file.
 
static Storage Load (const char *fname)
 Load current Storage from file, same as Load(const std::string &fname)
 
static Storage Fromfile (const std::string &fname, const unsigned int &dtype, const cytnx_int64 &count=-1)
 Load the binary file, which only contains the raw data, to current Storage.
 
static Storage Fromfile (const char *fname, const unsigned int &dtype, const cytnx_int64 &count=-1)
 
template<class T >
static Storage from_vector (const std::vector< T > &vin, const int device=-1)
 renew/create a Storage using c++ vector.
 

Detailed Description

an memeory storage with multi-type/multi-device support

Constructor & Destructor Documentation

◆ Storage() [1/2]

cytnx::Storage::Storage ( const unsigned long long size,
const unsigned int dtype = Type.Double,
int  device = -1,
const bool init_zero = true 
)
inline

The constructor of Storage class. It will call the function Init to initialize the Storage instance.

See also
Init(const unsigned long long &size, const unsigned int &dtype, int device, const bool &init_zero)

◆ Storage() [2/2]

cytnx::Storage::Storage ( )
inline

The default constructor of Storage class. It will create an empty Storage instance.

Member Function Documentation

◆ append()

template<class T >
void cytnx::Storage::append ( const T val)
inline

append a value

Parameters
[in]valthe value to append. it can be any type defined in cytnx::Type
Note
cannot append a complex value into a real Storage.

◆ astype()

Storage cytnx::Storage::astype ( const unsigned int new_type) const
inline

cast the type of current Storage

  1. if the new_type is the same as the dtype of current Storage, then return self; otherwise, return a new instance that has the same content as current Storage with dtype= new_type .
  2. the return Stoarge will be on the same device as the current Storage.
    Parameters
    [in]new_typethe new type of the Storage instance. This can be any of type defined in cytnx::Type.
    Attention
    This function cannot convert the complex type to real one. Please use real() or imag() to get the real or imaginary part of a complex Storage.

    Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/*
1. Create a Storage with
dtype =Type.Double [default],
*/
Storage A(10);
cout << A.dtype_str() << endl;
// the type is the same as A's type, so B shares the same object with A
Storage B = A.astype(Type.Double);
cout << B.dtype_str() << endl;
cout << is(B, A) << endl; // true
// cast A from Type.Double to Type.Float
Storage C = A.astype(Type.Float);
cout << C.dtype_str() << endl;
cout << is(C, A) << endl; // false
Storage D(10, Type.Double, Device.cuda + 0);
// D is on GPU, so E is also on GPU
Storage E = D.astype(Type.Float);
cout << E.device_str() << endl;
return 0;
}
an memeory storage with multi-type/multi-device support
Definition Storage.hpp:1051
std::vector< T > vector()
renew/create a c++ std::vector using current Storage.
Storage astype(const unsigned int &new_type) const
cast the type of current Storage
Definition Storage.hpp:1235
const std::string dtype_str() const
the dtype (std::string) of current Storage, see cytnx::Type for more details.
Definition Storage.hpp:1247
const std::string device_str() const
the device (std::string) of current Storage, see cytnx::Device for more details.
Definition Storage.hpp:1261
Definition Accessor.hpp:12
Device_class Device
data on which devices.
Type_class Type
data type

output>

Double (Float64)
Double (Float64)
1
Float (Float32)
0

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
A = Storage(10)
print(A.dtype_str())
B = A.astype(Type.Double)
print(B.dtype_str())
print(B is A)
C = A.astype(Type.Float)
print(C.dtype_str())
print(C is A)
D = Storage(10,device=Device.cuda+0);
E = D.astype(Type.Float)
print(E.device_str())

output>

Double (Float64)
Double (Float64)
True
Float (Float32)
False
cytnx device: CUDA/GPU-id:0

◆ capacity()

const unsigned long long & cytnx::Storage::capacity ( ) const
inline

the capacity in the Storage.

the capacity is the actual allocated memory in the Storage. The behavior of capacity is similar to std::vector::capacity() in c++.

Returns
[cytnx_uint64]

◆ clone()

Storage cytnx::Storage::clone ( ) const
inline

return a deep copy of the current storage.

Returns
[Storage]

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
Storage A(15);
Storage B = A; // B shares same object with A
Storage C = A.clone(); // C is a copy of A
// use is() to check if two variable shares same object
cout << is(B, A) << endl;
cout << is(C, A) << endl;
return 0;
}
Storage clone() const
return a deep copy of the current storage.
Definition Storage.hpp:1350

output>

1
0

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
A = Storage(15)
B = A
C = A.clone()
print(B is A)
print(C is A)

output>

True
False

◆ device()

const int & cytnx::Storage::device ( ) const
inline

the device-id of current Storage, see cytnx::Device for more details.

Returns
[cytnx_int64] the device-id.

◆ device_str()

const std::string cytnx::Storage::device_str ( ) const
inline

the device (std::string) of current Storage, see cytnx::Device for more details.

Returns
[std::string] device name

◆ dtype()

const unsigned int & cytnx::Storage::dtype ( ) const
inline

the dtype-id of current Storage, see cytnx::Type for more details.

Returns
[cytnx_uint64] the dtype-id.

◆ dtype_str()

const std::string cytnx::Storage::dtype_str ( ) const
inline

the dtype (std::string) of current Storage, see cytnx::Type for more details.

Returns
[std::string] dtype name

◆ fill()

template<class T >
void cytnx::Storage::fill ( const T val)
inline

set all the elements to the assigned value val

Parameters
[in]valthe value to set on all the elements. it can be any type defined in cytnx::Type
Note
cannot assign a complex value into a real Storage.

◆ from_vector()

template<class T >
static Storage cytnx::Storage::from_vector ( const std::vector< T > &  vin,
const int  device = -1 
)
inlinestatic

renew/create a Storage using c++ vector.

Parameters
[in]vinthe C++ vector with supported types.
Note
This function is C++ only

◆ Fromfile() [1/2]

static Storage cytnx::Storage::Fromfile ( const char fname,
const unsigned int dtype,
const cytnx_int64 count = -1 
)
static
See also
Fromfile(const std::string &fname, const unsigned int &dtype, const cytnx_int64 &count = -1)

◆ Fromfile() [2/2]

static Storage cytnx::Storage::Fromfile ( const std::string &  fname,
const unsigned int dtype,
const cytnx_int64 count = -1 
)
static

Load the binary file, which only contains the raw data, to current Storage.

This function will load the binary file, which only contains the raw data, to current Storage with specified dtype and number of elements.

Parameters
[in]fnamefile name
[in]dtypethe data type of the binary file. See cytnx::Type.
[in]Nelemthe number of elements you want to load from the binary file. If Nelem is -1, then it will load all the elements in the binary file.
Precondition
  1. The dtype cannot be Type.Void.
  2. The dtype must be the same as the data type of the binary file.
  3. The Nelem cannot be 0.
  4. The Nelem cannot be larger than the number of elements in the binary file.
  5. The file name fname must be valid.
See also
Tofile(const std::string &fname) const

◆ get_item()

Scalar cytnx::Storage::get_item ( const cytnx_uint64 idx) const
inline

Get the element at the given index.

Parameters
[in]idxThe index of the element.
Returns
The element at the given index.

◆ imag()

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 "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/*
Get the imag part from a complex128 (ComplexDouble) Storage
*/
Storage S1(10, Type.ComplexDouble);
for (unsigned int i = 0; i < S1.size(); i++) {
}
cout << S1 << endl;
cout << S1r << endl;
/*
Get the imag part from a complex64 (ComplexFloat) Storage
*/
Storage S2(10, Type.ComplexFloat);
for (unsigned int i = 0; i < S1.size(); i++) {
}
cout << S2 << endl;
cout << S2r << endl;
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 ]


◆ Init()

void cytnx::Storage::Init ( const unsigned long long size,
const unsigned int dtype = Type.Double,
int  device = -1,
const bool init_zero = true 
)
inline

initialize a Storage

Parameters
[in]sizethe number of elements for the Storage
[in]dtypethe dtype of the Storage instance. This can be any of type defined in cytnx::Type
[in]devicethe device of the Storage instance. This can be cytnx::Device.cpu or cytnx::Device.cuda+<gpuid> (see cytnx::Device for more details)

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/*
1. Create a Storage with
10 elements,
dtype =Type.Double [default],
device=Device.cpu [default]
*/
Storage A(10);
cout << A << endl;
/*
2. Create a Storage with
10 elements,
dtype =Type.Uint64,
device=Device.cpu [default],
[Note] the dtype can be any one of the supported type.
*/
Storage B(10, Type.Uint64);
cout << B << endl;
/*
3. Initialize a Storage with
10 elements,
dtype =Type.Double,
device=Device.cuda+0, (on gpu with gpu-id=0)
[Note] the gpu device can be set with Device.cuda+<gpu-id>
*/
Storage C(10, Type.Double, Device.cuda + 0);
cout << C << endl;
// 4. Create an empty Storage, and init later
D.Init(10, Type.Double, Device.cpu);
return 0;
}
void Init(const unsigned long long &size, const unsigned int &dtype=Type.Double, int device=-1, const bool &init_zero=true)
initialize a Storage
Definition Storage.hpp:1079

output>

dtype : Double (Float64)
device: cytnx device: CPU
size  : 10
[ 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]

dtype : Uint64
device: cytnx device: CPU
size  : 10
[                   0                   0                   0                   0                   0                   0                   0                   0                   0                   0  ]

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
A = Storage(10);
print(A)
B = Storage(10,dtype=Type.Uint64)
print(B)
C = Storage(10,device=Device.cuda+0)
print(C)
D = Storage()
D.Init(10,dtype=Type.Double,device=Device.cpu)

output>

dtype : Double (Float64)
device: cytnx device: CPU
size  : 10
[ 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]


dtype : Uint64
device: cytnx device: CPU
size  : 10
[                   0                   0                   0                   0                   0                   0                   0                   0                   0                   0  ]


dtype : Double (Float64)
device: cytnx device: CUDA/GPU-id:0
size  : 10
[ 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]


◆ Load() [1/2]

static Storage cytnx::Storage::Load ( const char fname)
static

Load current Storage from file, same as Load(const std::string &fname)

◆ Load() [2/2]

static Storage cytnx::Storage::Load ( const std::string &  fname)
static

Load current Storage from file.

Parameters
[in]fnamefile name

load the Storage from file with file path specify with input param 'fname'.

Precondition
The file must be a Storage object, which is saved by the function Save(const std::string &fname) const.

◆ operator!=()

The not-equal operator for Storage.

◆ operator()()

Scalar::Sproxy cytnx::Storage::operator() ( const cytnx_uint64 idx)

The access operator for the Storage.

Parameters
[in]idxThe index of the element.

◆ operator==()

compare two Storage

This function will compare the content between two Storage objects. It will compare the "value" of each element. Even the two Storage are different objects (different instance), if they have the same values, this function will return true.

Parameters
[in]Storageanother Storage to compare to
Note
the == operator will compare the content between two storages. use cytnx::is() for checking two variables share the same instance.

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/*
1. Create a Storage with
dtype =Type.Double [default],
*/
Storage A(10);
cout << A.dtype_str() << endl;
Storage B = A;
cout << (B == A) << endl; // true (share same instance)
cout << is(B, A) << endl; // true (share same instance)
cout << (C == A) << endl; // true (the same content.)
cout << is(C, A) << endl; // false (not share same instance)
return 0;
}

output>

Double (Float64)
1
1
1
0

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
A = Storage(10)
print(A.dtype_str())
B = A
C = A.clone()
print(B == A) # true (share same instance)
print(B is A) # true (share same instance)
print(C == A) # true (the same content.)
print(C is A) # false (not share same instance)

output>

Double (Float64)
True
True
True
False

◆ print_info()

void cytnx::Storage::print_info ( ) const
inline

print the info of the Storage, including the device, dtype and size.

◆ real()

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 "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/*
Get the real part from a complex128 (ComplexDouble) Storage
*/
Storage S1(10, Type.ComplexDouble);
for (unsigned int i = 0; i < S1.size(); i++) {
}
cout << S1 << endl;
cout << S1r << endl;
/*
Get the real part from a complex64 (ComplexFloat) Storage
*/
Storage S2(10, Type.ComplexFloat);
for (unsigned int i = 0; i < S1.size(); i++) {
}
cout << S2 << endl;
cout << S2r << endl;
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 ]


◆ resize()

void cytnx::Storage::resize ( const cytnx_uint64 newsize)
inline

resize the current Storage.

Parameters
[in]newsize.

◆ Save() [1/2]

void cytnx::Storage::Save ( const char fname) const

Save current Storage to file, same as Save(const std::string &fname)

◆ Save() [2/2]

void cytnx::Storage::Save ( const std::string &  fname) const

Save current Storage to file.

Parameters
[in]fnamefile name

Save the Storage to file with file path specify with input param fname with postfix ".cyst"

Postcondition
The file extension will be ".cyst".

◆ set_item()

template<class T >
void cytnx::Storage::set_item ( const cytnx_uint64 idx,
const T elem 
)
inline

Set the element at the given index.

Parameters
[in]idxThe index of the element.
[in]elemThe element to be set.

◆ set_zeros()

void cytnx::Storage::set_zeros ( )
inline

set all the elements to zero.

Note
although it is also possible to use Storage.fill(0) to set all the elements to zero, using set_zeros will have significant faster performance.

◆ size()

const unsigned long long & cytnx::Storage::size ( ) const
inline

the size ( no. of elements ) in the Storage

Returns
[cytnx_uint64]

◆ to()

Storage cytnx::Storage::to ( const int device)
inline

move a new Storage with same content as current Storage on different deivce.

Parameters
[in]devicethe device-id. It can be any device defined in cytnx::Device
Note
if the device is the same as the current Storage's device, return self.
See also
Storage::to_()

◆ to_()

void cytnx::Storage::to_ ( const int device)
inline

Move the current Storage to different deivce.

Parameters
[in]devicethe device-id. It can be any device defined in cytnx::Device.
See also
Storage::to()

◆ Tofile() [1/3]

void cytnx::Storage::Tofile ( const char fname) const

◆ Tofile() [2/3]

void cytnx::Storage::Tofile ( const std::string &  fname) const

Save current Storage to a binary file, which only contains the raw data.

See also
Fromfile(const std::string &fname, const unsigned int &dtype, const cytnx_int64 &count)

◆ Tofile() [3/3]

void cytnx::Storage::Tofile ( std::fstream &  f) const

◆ vector()

template<class T >
std::vector< T > cytnx::Storage::vector ( )

renew/create a c++ std::vector using current Storage.

Note
This function is C++ only

The documentation for this class was generated from the following file: