12. Common APIs

The central objects that store data in Cytnx such as Storage, Tensor and UniTensor share very similar member functions and attributes, in this seciton we summerize these APIs and the hyperlink to the correspnding guide page for convenience.

12.1. Data type

.dtype()
.dtype()

The dtype-id of current Storage, Tensor or UniTensor.

.dtype_str()

The dtype (string) of current Storage, Tensor or UniTensor.

.astype(type)

Cast the type of current Storage, Tensor or UniTensor.

.real()

Get the real part of the current Storage or Tensor.

.imag()

Get the imaginary part of the current Storage or Tensor.

See:

Creating a Storage

Creating a Tensor

Creating a UniTensor

12.2. Device

.device()

The device-id of current Storage, Tensor or UniTensor.

.device_str()

The device(string) of current Storage, Tensor or UniTensor.

.to(device)

move the current Storage, Tensor or UniTensor to different device.

.to_(device)

move a new Storage, Tensor or UniTensor with same content as current object on different deivce.

See:

Creating a Storage

Creating a Tensor

Creating a UniTensor

12.3. Save & Load

.Save(name)
.Save(name)

Save current Storage, Tensor or UniTensor to file.

.Load(name)

Load a Storage, Tensor or UniTensor from file.

.Tofile(name)
.Tofile(name)

Save current Storage or Tensor to binary file without any additional header information.

.Fromfile(name)

Load the Storage or Tensor from binary file.

See:

Save/Load a storage

Save/Load a Tensor

Save/Load a UniTensor

12.4. Operations

.clone()

Return a clone of the current Storage, Tensor or UniTensor.