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

An Enhanced tensor specifically designed for physical Tensor network simulation. More...

#include <UniTensor.hpp>

Public Member Functions

 UniTensor (const Tensor &in_tensor, const bool &is_diag=false, const cytnx_int64 &rowrank=-1, const std::vector< std::string > &in_labels={}, const std::string &name="")
 Construct a UniTensor from a cytnx::Tensor.
 
void Init (const Tensor &in_tensor, const bool &is_diag=false, const cytnx_int64 &rowrank=-1, const std::vector< std::string > &in_labels={}, const std::string &name="")
 Initialize a UniTensor with cytnx::Tensor.
 
 UniTensor (const std::vector< Bond > &bonds, const std::vector< std::string > &in_labels={}, const cytnx_int64 &rowrank=-1, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const bool &is_diag=false, const std::string &name="")
 Construct a UniTensor.
 
void Init (const std::vector< Bond > &bonds, const std::vector< std::string > &in_labels={}, const cytnx_int64 &rowrank=-1, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const bool &is_diag=false, const std::string &name="")
 Initialize the UniTensor with the given arguments.
 
UniTensorset_name (const std::string &in)
 Set the name of the UniTensor.
 
UniTensorset_label (const cytnx_int64 &idx, const std::string &new_label)
 Set a new label for bond at the assigned index.
 
UniTensorset_label (const cytnx_int64 &idx, const char *new_label)
 
UniTensorset_label (const std::string &old_label, const std::string &new_label)
 set a new label for bond to replace one of the current label.
 
UniTensorset_label (const char *old_label, const std::string &new_label)
 
UniTensorset_label (const std::string &old_label, const char *new_label)
 
UniTensorset_label (const char *old_label, const char *new_label)
 
UniTensorset_labels (const std::vector< std::string > &new_labels)
 Set new labels for all the bonds.
 
UniTensorset_labels (const std::initializer_list< char * > &new_labels)
 
UniTensorset_rowrank_ (const cytnx_uint64 &new_rowrank)
 Set the row rank of the UniTensor.
 
UniTensor set_rowrank (const cytnx_uint64 &new_rowrank) const
 
template<class T >
Titem ()
 
Scalar::Sproxy item () const
 
cytnx_uint64 Nblocks () const
 Return the number of blocks in the UniTensor.
 
cytnx_uint64 rank () const
 Return the rank of the UniTensor.
 
cytnx_uint64 rowrank () const
 Return the row rank of the UniTensor.
 
unsigned int dtype () const
 Return the data type of the UniTensor.
 
int uten_type () const
 Return the UniTensor type (cytnx::UTenType) of the UniTensor.
 
int device () const
 Return the device of the UniTensor.
 
std::string name () const
 Return the name of the UniTensor.
 
std::string dtype_str () const
 Return the data type of the UniTensor in 'string' form.
 
std::string device_str () const
 Return the device of the UniTensor in 'string' form.
 
std::string uten_type_str () const
 Return the UniTensor type (cytnx::UTenType) of the UniTensor in 'string' form.
 
bool is_contiguous () const
 To tell whether the UniTensor is contiguous.
 
bool is_diag () const
 To tell whether the UniTensor is in diagonal form.
 
bool is_tag () const
 To tell whether the UniTensor is tagged. That is, all of the Bond in the UniTensor is directional (all of them are bondType.BD_KET or bondType.BD_BRA)
 
std::vector< Symmetrysyms () const
 Return the symmetry type of the UniTensor.
 
const boolis_braket_form () const
 Check whether the UniTensor is in braket form.
 
const std::vector< std::string > & labels () const
 Return the labels of the UniTensor.
 
cytnx_int64 get_index (std::string label) const
 Get the index of an desired label string.
 
const std::vector< Bond > & bonds () const
 Get the bonds of the UniTensor.
 
std::vector< Bond > & bonds ()
 
const Bondbond_ (const cytnx_uint64 &idx) const
 
Bondbond_ (const cytnx_uint64 &idx)
 
const Bondbond_ (const std::string &label) const
 
Bondbond_ (const std::string &label)
 
Bond bond (const cytnx_uint64 &idx) const
 
Bond bond (const std::string &label) const
 
std::vector< cytnx_uint64shape () const
 Get the shape of the UniTensor.
 
bool is_blockform () const
 Check whether the UniTensor is in block form.
 
void to_ (const int &device)
 move the current UniTensor to the assigned device (inplace).
 
UniTensor to (const int &device) const
 move the current UniTensor to the assigned device.
 
UniTensor clone () const
 Clone (deep copy) the UniTensor.
 
UniTensorrelabels_ (const std::vector< std::string > &new_labels)
 Set new labels for all the bonds.
 
UniTensor relabels (const std::vector< std::string > &new_labels) const
 relables all of the labels in UniTensor.
 
UniTensor relabels (const std::initializer_list< char * > &new_labels) const
 
UniTensorrelabels_ (const std::initializer_list< char * > &new_labels)
 
UniTensor relabels (const std::vector< std::string > &old_labels, const std::vector< std::string > &new_labels) const
 replace part or all labels by given new labels for the bonds.
 
UniTensorrelabels_ (const std::vector< std::string > &old_labels, const std::vector< std::string > &new_labels)
 relables part or all of the labels in UniTensor by given new labels
 
UniTensor relabels (const std::initializer_list< char * > &old_labels, const std::initializer_list< char * > &new_labels) const
 
UniTensorrelabels_ (const std::initializer_list< char * > &old_labels, const std::initializer_list< char * > &new_labels)
 
UniTensor relabel (const cytnx_int64 &inx, const std::string &new_label) const
 rebable the lags in the UniTensor by given index.
 
UniTensorrelabel_ (const cytnx_int64 &inx, const std::string &new_label)
 rebable the lags in the UniTensor by given index.
 
UniTensorrelabel_ (const std::string &old_label, const std::string &new_label)
 relabel the lags in the UniTensor by a given label.
 
UniTensor relabel (const std::string &old_label, const std::string &new_label) const
 relabel the lags in the UniTensor by a given label.
 
UniTensor astype (const unsigned int &dtype) const
 Return a new UniTensor that cast to different data type.
 
UniTensor permute (const std::vector< cytnx_int64 > &mapper, const cytnx_int64 &rowrank=-1) const
 permute the lags of the UniTensor
 
UniTensor permute (const std::vector< std::string > &mapper, const cytnx_int64 &rowrank=-1) const
 permute the lags of the UniTensor by labels
 
UniTensor permute (const std::initializer_list< char * > &mapper, const cytnx_int64 &rowrank=-1) const
 
void permute_ (const std::vector< cytnx_int64 > &mapper, const cytnx_int64 &rowrank=-1)
 permute the lags of the UniTensor, inplacely.
 
void permute_ (const std::vector< std::string > &mapper, const cytnx_int64 &rowrank=-1)
 permute the lags of the UniTensor, inplacely.
 
UniTensor contiguous () const
 Make the UniTensor contiguous by coalescing the memory (storage).
 
void contiguous_ ()
 Make the UniTensor contiguous by coalescing the memory (storage), inplacely.
 
void print_diagram (const bool &bond_info=false)
 Plot the diagram of the UniTensor.
 
void print_blocks (const bool &full_info=true) const
 Print all of the blocks in the UniTensor.
 
void print_block (const cytnx_int64 &idx, const bool &full_info=true) const
 Given a index and print out the corresponding block of the UniTensor.
 
void group_basis_ ()
 Group the same quantum number basis together.
 
UniTensor group_basis () const
 
template<class T >
Tat (const std::vector< cytnx_uint64 > &locator)
 Get an element at specific location.
 
template<class T >
const Tat (const std::vector< cytnx_uint64 > &locator) const
 Get an element at specific location.
 
template<class T >
const Tat (const std::vector< std::string > &labels, const std::vector< cytnx_uint64 > &locator) const
 
template<class T >
Tat (const std::vector< std::string > &labels, const std::vector< cytnx_uint64 > &locator)
 
const Scalar::Sproxy at (const std::vector< cytnx_uint64 > &locator) const
 Get an element at specific location.
 
Scalar::Sproxy at (const std::vector< cytnx_uint64 > &locator)
 Get an element at specific location.
 
Scalar::Sproxy at (const std::vector< std::string > &labels, const std::vector< cytnx_uint64 > &locator)
 
const Scalar::Sproxy at (const std::vector< std::string > &labels, const std::vector< cytnx_uint64 > &locator) const
 
Tensor get_block (const cytnx_uint64 &idx=0) const
 Get the block of the UniTensor for a given index.
 
Tensor get_block (const std::vector< cytnx_int64 > &qidx, const bool &force=false) const
 Get the block of the UniTensor for the given quantun indices.
 
Tensor get_block (const std::vector< std::string > &labels, const std::vector< cytnx_int64 > &qidx, const bool &force=false) const
 
Tensor get_block (const std::initializer_list< cytnx_int64 > &qnum, const bool &force=false) const
 
Tensor get_block (const std::vector< cytnx_uint64 > &qnum, const bool &force=false) const
 
Tensor get_block (const std::vector< std::string > &labels, const std::vector< cytnx_uint64 > &qidx, const bool &force=false) const
 
const Tensorget_block_ (const cytnx_uint64 &idx=0) const
 Get the shared view of block for the given index.
 
Tensorget_block_ (const cytnx_uint64 &idx=0)
 
Tensorget_block_ (const std::vector< cytnx_int64 > &qidx, const bool &force=false)
 Get the shared view of block for the given quantum indices.
 
Tensor get_block_ (const std::vector< std::string > &labels, const std::vector< cytnx_int64 > &qidx, const bool &force=false)
 Get the shared (data) view of block for the given quantum indices on given labels.
 
Tensorget_block_ (const std::initializer_list< cytnx_int64 > &qidx, const bool &force=false)
 
Tensorget_block_ (const std::vector< cytnx_uint64 > &qidx, const bool &force=false)
 
Tensor get_block_ (const std::vector< std::string > &labels, const std::vector< cytnx_uint64 > &qidx, const bool &force=false)
 
const Tensorget_block_ (const std::vector< cytnx_int64 > &qidx, const bool &force=false) const
 
const Tensorget_block_ (const std::initializer_list< cytnx_int64 > &qidx, const bool &force=false) const
 
const Tensorget_block_ (const std::vector< cytnx_uint64 > &qidx, const bool &force=false) const
 
std::vector< Tensorget_blocks () const
 Get all the blocks of the UniTensor.
 
const std::vector< Tensor > & get_blocks_ (const bool &silent=false) const
 Get all the blocks of the UniTensor, inplacely.
 
std::vector< Tensor > & get_blocks_ (const bool &silent=false)
 
void put_block (const Tensor &in, const cytnx_uint64 &idx=0)
 Put the block into the UniTensor with given index.
 
void put_block (const Tensor &in_tens, const std::vector< cytnx_int64 > &qidx, const bool &force)
 Put the block into the UniTensor with given quantum number.
 
void put_block (Tensor &in, const std::vector< std::string > &lbls, const std::vector< cytnx_int64 > &qidx, const bool &force=false)
 Put the block into the UniTensor with given quantum indices, will copy the input tensor.
 
void put_block_ (Tensor &in, const cytnx_uint64 &idx=0)
 Put the block into the UniTensor with given index, inplacely.
 
void put_block_ (Tensor &in, const std::vector< cytnx_int64 > &qidx, const bool &force)
 Put the block into the UniTensor with given quantum indices, inplacely.
 
void put_block_ (Tensor &in, const std::vector< std::string > &lbls, const std::vector< cytnx_int64 > &qidx, const bool &force=false)
 Put the block into the UniTensor with given quantum indices, inplacely.
 
UniTensor get (const std::vector< Accessor > &accessors) const
 
void set (const std::vector< Accessor > &accessors, const Tensor &rhs)
 
void set (const std::vector< Accessor > &accessors, const UniTensor &rhs)
 
UniTensor reshape (const std::vector< cytnx_int64 > &new_shape, const cytnx_uint64 &rowrank=0)
 Reshape the UniTensor.
 
void reshape_ (const std::vector< cytnx_int64 > &new_shape, const cytnx_uint64 &rowrank=0)
 Reshape the UniTensor, inplacely.
 
UniTensor to_dense ()
 Convert the UniTensor to non-diagonal form.
 
void to_dense_ ()
 Convert the UniTensor to non-diagonal form, inplacely.
 
void combineBonds (const std::vector< cytnx_int64 > &indicators, const bool &force, const bool &by_label)
 
void combineBonds (const std::vector< std::string > &indicators, const bool &force=false)
 Combine the sevral bonds of the UniTensor.
 
void combineBonds (const std::vector< cytnx_int64 > &indicators, const bool &force=false)
 
UniTensor contract (const UniTensor &inR, const bool &mv_elem_self=false, const bool &mv_elem_rhs=false) const
 Contract the UniTensor with common labels.
 
bool same_data (const UniTensor &rhs) const
 Check whether the Blocks address are the same.
 
UniTensorAdd_ (const UniTensor &rhs)
 The addition function of the UniTensor.
 
UniTensorMul_ (const UniTensor &rhs)
 The multiplcation function of the UniTensor.
 
UniTensorSub_ (const UniTensor &rhs)
 The subtraction function of the UniTensor.
 
UniTensorDiv_ (const UniTensor &rhs)
 The division function of the UniTensor.
 
UniTensorAdd_ (const Scalar &rhs)
 The addition function for a given scalar.
 
UniTensorMul_ (const Scalar &rhs)
 The multiplication function for a given scalar.
 
UniTensorSub_ (const Scalar &rhs)
 The subtraction function for a given scalar.
 
UniTensorDiv_ (const Scalar &rhs)
 The division function for a given scalar.
 
UniTensor Add (const UniTensor &rhs) const
 The addition function of the UniTensor.
 
UniTensor Add (const Scalar &rhs) const
 The addition function for a given scalar.
 
UniTensor Mul (const UniTensor &rhs) const
 The multiplication function of the UniTensor.
 
UniTensor Mul (const Scalar &rhs) const
 The multiplication function for a given scalar.
 
UniTensor Div (const UniTensor &rhs) const
 The division function of the UniTensor.
 
UniTensor Div (const Scalar &rhs) const
 The division function for a given scalar.
 
UniTensor Sub (const UniTensor &rhs) const
 The subtraction function of the UniTensor.
 
UniTensor Sub (const Scalar &rhs) const
 The subtraction function for a given scalar.
 
Tensor Norm () const
 Return the norm of the UniTensor.
 
UniTensoroperator+= (const UniTensor &rhs)
 The addition assignment operator of the UniTensor.
 
UniTensoroperator-= (const UniTensor &rhs)
 The subtraction assignment operator of the UniTensor.
 
UniTensoroperator/= (const UniTensor &rhs)
 The division assignment operator of the UniTensor.
 
UniTensoroperator*= (const UniTensor &rhs)
 The multiplication assignment operator of the UniTensor.
 
UniTensoroperator+= (const Scalar &rhs)
 The addition assignment operator for a given scalar.
 
UniTensoroperator-= (const Scalar &rhs)
 The subtraction assignment operator for a given scalar.
 
UniTensoroperator/= (const Scalar &rhs)
 The division assignment operator for a given scalar.
 
UniTensoroperator*= (const Scalar &rhs)
 The multiplication assignment operator for a given scalar.
 
UniTensor Conj () const
 Apply complex conjugate on each entry of the UniTensor.
 
UniTensorConj_ ()
 Apply complex conjugate on each entry of the UniTensor.
 
UniTensor Transpose () const
 Take the transpose of the UniTensor.
 
UniTensorTranspose_ ()
 Take the transpose of the UniTensor, inplacely.
 
UniTensor normalize () const
 normalize the current UniTensor instance with 2-norm.
 
UniTensornormalize_ ()
 normalize the UniTensor, inplacely.
 
UniTensor Trace (const std::string &a, const std::string &b) const
 Take the partial trance to the UniTensor.
 
UniTensor Trace (const cytnx_int64 &a=0, const cytnx_int64 &b=1) const
 Take the partial trance to the UniTensor.
 
UniTensorTrace_ (const std::string &a, const std::string &b)
 Take the partial trance to the UniTensor, inplacely.
 
UniTensorTrace_ (const cytnx_int64 &a=0, const cytnx_int64 &b=1)
 Take the partial trance to the UniTensor, inplacely.
 
UniTensor Dagger () const
 Take the conjugate transpose to the UniTensor.
 
UniTensorDagger_ ()
 Take the conjugate transpose to the UniTensor, inplacely.
 
UniTensortag ()
 Set the UniTensor as a tagged UniTensor.
 
UniTensor Pow (const double &p) const
 Power function.
 
UniTensorPow_ (const double &p)
 Power function.
 
bool elem_exists (const std::vector< cytnx_uint64 > &locator) const
 Geiven the locator, check if the element exists.
 
template<class T >
T get_elem (const std::vector< cytnx_uint64 > &locator) const
 
template<class T2 >
void set_elem (const std::vector< cytnx_uint64 > &locator, const T2 &rc)
 
void Save (const std::string &fname) const
 save a UniTensor to file
 
void Save (const char *fname) const
 save a UniTensor to file
 
UniTensortruncate_ (const std::string &label, const cytnx_uint64 &dim)
 truncate bond dimension of the UniTensor by the given bond label and dimension.
 
UniTensortruncate_ (const cytnx_int64 &bond_idx, const cytnx_uint64 &dim)
 truncate bond dimension of the UniTensor by the given bond index and dimension.
 
UniTensor truncate (const std::string &label, const cytnx_uint64 &dim) const
 truncate bond dimension of the UniTensor by the given bond label and dimension.
 
UniTensor truncate (const cytnx_int64 &bond_idx, const cytnx_uint64 &dim) const
 truncate bond dimension of the UniTensor by the given bond index and dimension.
 
const std::vector< cytnx_uint64 > & get_qindices (const cytnx_uint64 &bidx) const
 get the q-indices on each leg for the [bidx]-th block
 
std::vector< cytnx_uint64 > & get_qindices (const cytnx_uint64 &bidx)
 get the q-indices on each leg for the [bidx]-th block
 
const vec2d< cytnx_uint64 > & get_itoi () const
 get the q-indices on each leg for all the blocks
 
vec2d< cytnx_uint64 > & get_itoi ()
 
UniTensorconvert_from (const UniTensor &rhs, const bool &force=false)
 
void normal_ (const double &mean, const double &std, const unsigned int &seed=cytnx::random::__static_random_device())
 Generate a one-bond UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution, inplacely.
 
void uniform_ (const double &low=0, const double &high=1, const unsigned int &seed=cytnx::random::__static_random_device())
 Generate a UniTensor with all elements are random numbers sampled from a uniform distribution, inplacely.
 

Static Public Member Functions

static UniTensor Load (const std::string &fname)
 load a UniTensor from file
 
static UniTensor Load (const char *fname)
 load a UniTensor from file
 
static UniTensor zeros (const cytnx_uint64 &Nelem, const std::vector< std::string > &in_labels={}, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a one-bond UniTensor with all elements set to zero.
 
static UniTensor zeros (const std::vector< cytnx_uint64 > &shape, const std::vector< std::string > &in_labels={}, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a UniTensor with all elements set to zero.
 
static UniTensor ones (const cytnx_uint64 &Nelem, const std::vector< std::string > &in_labels={}, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a one-bond UniTensor with all elements set to one.
 
static UniTensor identity (const cytnx_uint64 &dim, const std::vector< std::string > &in_labels={}, const cytnx_bool &is_diag=false, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a identity UniTensor.
 
static UniTensor eye (const cytnx_uint64 &dim, const std::vector< std::string > &in_labels={}, const cytnx_bool &is_diag=false, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a 2-bond identity UniTensor.
 
static UniTensor ones (const std::vector< cytnx_uint64 > &shape, const std::vector< std::string > &in_labels={}, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a UniTensor with all elements set to one.
 
static UniTensor arange (const cytnx_int64 &Nelem, const std::vector< std::string > &in_labels={}, const std::string &name="")
 Generate a one-bond UniTensor with all elements are arange from 0 to Nelem-1.
 
static UniTensor arange (const cytnx_double &start, const cytnx_double &end, const cytnx_double &step=1, const std::vector< std::string > &in_labels={}, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a UniTensor with all elements are arange from start to end.
 
static UniTensor linspace (const cytnx_double &start, const cytnx_double &end, const cytnx_uint64 &Nelem, const bool &endpoint=true, const std::vector< std::string > &in_labels={}, const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a one-bond UniTensor with all elements are evenly spaced numbers over a specified interval.
 
static UniTensor normal (const cytnx_uint64 &Nelem, const double &mean, const double &std, const std::vector< std::string > &in_labels={}, const unsigned int &seed=cytnx::random::__static_random_device(), const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a one-bond UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution.
 
static UniTensor normal (const std::vector< cytnx_uint64 > &shape, const double &mean, const double &std, const std::vector< std::string > &in_labels={}, const unsigned int &seed=cytnx::random::__static_random_device(), const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution.
 
static UniTensor uniform (const cytnx_uint64 &Nelem, const double &low, const double &high, const std::vector< std::string > &in_labels={}, const unsigned int &seed=cytnx::random::__static_random_device(), const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a one-bond UniTensor with all elements are random numbers sampled from a uniform distribution.
 
static UniTensor uniform (const std::vector< cytnx_uint64 > &shape, const double &low, const double &high, const std::vector< std::string > &in_labels={}, const unsigned int &seed=cytnx::random::__static_random_device(), const unsigned int &dtype=Type.Double, const int &device=Device.cpu, const std::string &name="")
 Generate a UniTensor with all elements are random numbers sampled from a uniform distribution.
 

Detailed Description

An Enhanced tensor specifically designed for physical Tensor network simulation.

Constructor & Destructor Documentation

◆ UniTensor() [1/2]

cytnx::UniTensor::UniTensor ( const Tensor in_tensor,
const bool is_diag = false,
const cytnx_int64 rowrank = -1,
const std::vector< std::string > &  in_labels = {},
const std::string &  name = "" 
)
inlineexplicit

Construct a UniTensor from a cytnx::Tensor.

Parameters
[in]in_tensora cytnx::Tensor
[in]is_diagWhether the input Tensor in_tensor is a diagonal Tensor. This will requires that the input of in_tensor to be 1D.
[in]rowrankthe rowrank of the outcome UniTensor
Note
  1. The constructed UniTensor will have same rank as the input Tensor, with default labels, and a shared view (shared instance) of interal block as the input Tensor.
  2. The constructed UniTensor is always untagged.
Attention
The internal block of UniTensor is a referece of input Tensor. That is, they share the same memory. All the change afterward on UniTensor block will change in input Tensor as well. Use Tensor.clone() if a shared view is not the case.

Example:

c++ API:

output>

 

python API:

output>

 

◆ UniTensor() [2/2]

cytnx::UniTensor::UniTensor ( const std::vector< Bond > &  bonds,
const std::vector< std::string > &  in_labels = {},
const cytnx_int64 rowrank = -1,
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const bool is_diag = false,
const std::string &  name = "" 
)
inline

Construct a UniTensor.

Parameters
[in]bondsthe bond list. Each bond will be deep copy( not a shared view of bond object with input bond)
[in]in_labelsthe labels for each rank(bond)
[in]rowrankthe rank of physical row space.
[in]dtypethe data type of the UniTensor. It can be any type defined in cytnx::Type.
[in]devicethe device that the UniTensor is put on. It can be any device defined in cytnx::Device.
[in]is_diagif the constructed UniTensor is a diagonal UniTensor. This can only be assigned true when the UniTensor is square and rank-2 UniTensor. The UniTensor must have one in-bond and one out-bond.
Precondition
  1. the bonds cannot contain simutaneously untagged bond(s) and tagged bond(s)
  2. If the bonds are with symmetry (qnums), the symmetry types should be the same across all the bonds.

Member Function Documentation

◆ Add() [1/2]

UniTensor cytnx::UniTensor::Add ( const Scalar rhs) const

The addition function for a given scalar.

Given the scalar rhs, it will perform the addition for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsa scalar you want to add in the UniTensor.
Returns
UniTensor
Note
Compare to Add_(const Scalar&), this function will create a new UniTensor.
See also
Add_(const Scalar&), Add_(const UniTensor&), Add(const UniTensor&)const, operator+=(const UniTensor&), operator+=(const Scalar&), operator+

◆ Add() [2/2]

UniTensor cytnx::UniTensor::Add ( const UniTensor rhs) const

The addition function of the UniTensor.

This is addition function of the UniTensor. Given the UniTensor \( UT_2\) as the argument, it will return a new UniTensor

\[ UT = UT_{self} + UT_2 \]

Perform element-wise addition of two UniTensor.

Parameters
[in]rhsThe UniTensor you want to add by.
Returns
UniTensor
Precondition
The two UniTensor need to have same structure.
Note
Compare to Add_(const UniTensor&), this function will create a new UniTensor.
See also
Add_(const UniTensor&), Add_(const Scalar&), Add(const Scalar&)const , operator+=(const UniTensor&), operator+=(const Scalar&), operator+

◆ Add_() [1/2]

UniTensor & cytnx::UniTensor::Add_ ( const Scalar rhs)
inline

The addition function for a given scalar.

Given the Scalar rhs, it will perform the addition for each element in UniTensor with this Scalar rhs.

Parameters
[in]rhsa Scalar you want to add in the UniTensor.
Returns
UniTensor&
Note
Compare to Add(const Scalar&)const, this is an inplace function.
See also
Add_(const UniTensor&), Add(const UniTensor&)const, Add(const Scalar&)const , operator+=(const UniTensor&), operator+=(const Scalar&), operator+

◆ Add_() [2/2]

UniTensor & cytnx::UniTensor::Add_ ( const UniTensor rhs)
inline

The addition function of the UniTensor.

This is addition function of the UniTensor. Given the UniTensor \( UT_2\) as the argument, it will return

\[ UT_{self} = UT_{self} + UT_2 \]

Perform element-wise addition of two UniTensor.

Parameters
[in]rhsThe UniTensor you want to add by.
Returns
UniTensor&
Precondition
The two UniTensor need to have same structure.
Note
Compare to Add(const UniTensor&)const, this is an inplace function.
See also
Add_(const Scalar&), Add(const UniTensor&)const, Add(const Scalar&)const , operator+=(const UniTensor&), operator+=(const Scalar&), operator+

◆ arange() [1/2]

static UniTensor cytnx::UniTensor::arange ( const cytnx_double start,
const cytnx_double end,
const cytnx_double step = 1,
const std::vector< std::string > &  in_labels = {},
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate a UniTensor with all elements are arange from start to end.

Generate a UniTensor with all elements are arange from start to end , the step is step .

Parameters
[in]startthe start of the arange.
[in]endthe end of the arange.
[in]stepthe step of the arange.
[in]in_labelsthe labels of the UniTensor.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
arange(const cytnx_double &start, const cytnx_double &end, const cytnx_double &step, const unsigned int &dtype, const int &device)

◆ arange() [2/2]

static UniTensor cytnx::UniTensor::arange ( const cytnx_int64 Nelem,
const std::vector< std::string > &  in_labels = {},
const std::string &  name = "" 
)
inlinestatic

Generate a one-bond UniTensor with all elements are arange from 0 to Nelem-1.

Generate a UniTensor with all elements are arange from 0 to Nelem-1 with double data type on cpu device. The step is 1.

Parameters
[in]Nelemthe number of elements.
[in]in_labelsthe labels of the UniTensor.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
arange(const cytnx_double &start, const cytnx_double &end, const cytnx_double &step, const unsigned int &dtype, const int &device)
arange(const cytnx_int64 &Nelem)

◆ astype()

UniTensor cytnx::UniTensor::astype ( const unsigned int dtype) const
inline

Return a new UniTensor that cast to different data type.

Parameters
[in]new_typethe new data type. It an be any type defined in cytnx::Type.
Returns
UniTensor
Attention
If the new_type is same as dtype of the original UniTensor, return self.

◆ at() [1/8]

template<class T >
T & cytnx::UniTensor::at ( const std::vector< cytnx_uint64 > &  locator)
inline

Get an element at specific location.

Parameters
[in]locatorthe location of the element we want to access.
Note
this API is only for C++.

◆ at() [2/8]

Scalar::Sproxy cytnx::UniTensor::at ( const std::vector< cytnx_uint64 > &  locator)
inline

Get an element at specific location.

see more information at user guide 6.3.5.

◆ at() [3/8]

template<class T >
const T & cytnx::UniTensor::at ( const std::vector< cytnx_uint64 > &  locator) const
inline

Get an element at specific location.

Parameters
[in]locatorthe location of the element we want to access.
Note
this API is only for C++.

◆ at() [4/8]

const Scalar::Sproxy cytnx::UniTensor::at ( const std::vector< cytnx_uint64 > &  locator) const
inline

Get an element at specific location.

see more information at user guide 6.3.5.

◆ at() [5/8]

template<class T >
T & cytnx::UniTensor::at ( const std::vector< std::string > &  labels,
const std::vector< cytnx_uint64 > &  locator 
)
inline

◆ at() [6/8]

Scalar::Sproxy cytnx::UniTensor::at ( const std::vector< std::string > &  labels,
const std::vector< cytnx_uint64 > &  locator 
)
inline

◆ at() [7/8]

template<class T >
const T & cytnx::UniTensor::at ( const std::vector< std::string > &  labels,
const std::vector< cytnx_uint64 > &  locator 
) const
inline

◆ at() [8/8]

const Scalar::Sproxy cytnx::UniTensor::at ( const std::vector< std::string > &  labels,
const std::vector< cytnx_uint64 > &  locator 
) const
inline

◆ bond() [1/2]

Bond cytnx::UniTensor::bond ( const cytnx_uint64 idx) const
inline

◆ bond() [2/2]

Bond cytnx::UniTensor::bond ( const std::string &  label) const
inline

◆ bond_() [1/4]

Bond & cytnx::UniTensor::bond_ ( const cytnx_uint64 idx)
inline

◆ bond_() [2/4]

const Bond & cytnx::UniTensor::bond_ ( const cytnx_uint64 idx) const
inline

◆ bond_() [3/4]

Bond & cytnx::UniTensor::bond_ ( const std::string &  label)
inline

◆ bond_() [4/4]

const Bond & cytnx::UniTensor::bond_ ( const std::string &  label) const
inline

◆ bonds() [1/2]

std::vector< Bond > & cytnx::UniTensor::bonds ( )
inline
See also
bonds();

◆ bonds() [2/2]

const std::vector< Bond > & cytnx::UniTensor::bonds ( ) const
inline

Get the bonds of the UniTensor.

Returns
std::vector<Bond>

◆ clone()

UniTensor cytnx::UniTensor::clone ( ) const
inline

Clone (deep copy) the UniTensor.

Returns
UniTensor

◆ combineBonds() [1/3]

void cytnx::UniTensor::combineBonds ( const std::vector< cytnx_int64 > &  indicators,
const bool force,
const bool by_label 
)
inline

◆ combineBonds() [2/3]

void cytnx::UniTensor::combineBonds ( const std::vector< cytnx_int64 > &  indicators,
const bool force = false 
)
inline

◆ combineBonds() [3/3]

void cytnx::UniTensor::combineBonds ( const std::vector< std::string > &  indicators,
const bool force = false 
)
inline

Combine the sevral bonds of the UniTensor.

Parameters
[in]indicatorsthe labels of the lags you want to combine.
[in]forceIf force is true, it will combine the bonds anyway even the direction of the bonds are same. After combining, the direction of the bonds will be set as same as the first bond.
Precondition
  1. The size of indicators need to >= 2.
  2. The UniTensor cannot be diagonal form (that means is_diag cannot be true.)

◆ Conj()

UniTensor cytnx::UniTensor::Conj ( ) const
inline

Apply complex conjugate on each entry of the UniTensor.

Conj() apply complex conjugate on each entry of the UniTensor.

Returns
UniTensor
Note
Compare to Conj_(), this fucntion will create a new object UniTensor.
See also
Conj_()

◆ Conj_()

UniTensor & cytnx::UniTensor::Conj_ ( )
inline

Apply complex conjugate on each entry of the UniTensor.

Conj_() apply complex conjugate on each entry of the UniTensor, inplacely.

Returns
UniTensor
Note
Compare to Conj(), this fucntion is inplace function.
See also
Conj()

◆ contiguous()

UniTensor cytnx::UniTensor::contiguous ( ) const
inline

Make the UniTensor contiguous by coalescing the memory (storage).

See also
contiguous_()

◆ contiguous_()

void cytnx::UniTensor::contiguous_ ( )
inline

Make the UniTensor contiguous by coalescing the memory (storage), inplacely.

See also
contiguous()

◆ contract()

UniTensor cytnx::UniTensor::contract ( const UniTensor inR,
const bool mv_elem_self = false,
const bool mv_elem_rhs = false 
) const
inline

Contract the UniTensor with common labels.

This function contract the UniTensor lags with common labels.

Parameters
[in]inRThe UniTensor you want to contract with.
[in]mv_elem_selfWhether the self UniTensor need to do contiguous() after the contraction.
[in]mv_elem_rhsWhether the rhs UniTensor inR need to do contiguous() after the contraction.
Precondition
  1. Two UniTensor need to have same UniTensor type, namely, same UTenType. You cannot contract symmetric to non-symmetric UniTensor.
  2. You cannot contract tagged UniTensor and untagged UniTensor.
  3. For Dense diagonal UniTensor, the type of Bond (bra-ket) should match.
  4. For symmetric UniTensor (UTenType.Block), Symmetry, degeneracy, quantum numbers and Bond type should be consistent.
Returns
UniTensor
See also
uten_type(), linalg::Tensordot

◆ convert_from()

UniTensor & cytnx::UniTensor::convert_from ( const UniTensor rhs,
const bool force = false 
)
inline

◆ Dagger()

UniTensor cytnx::UniTensor::Dagger ( ) const
inline

Take the conjugate transpose to the UniTensor.

Returns
UniTensor
Note
Compare to Dagger_(), this function will create a new UniTensor ojbect.
See also
Dagger_(), Transpose()

◆ Dagger_()

UniTensor & cytnx::UniTensor::Dagger_ ( )
inline

Take the conjugate transpose to the UniTensor, inplacely.

Returns
UniTensor&
Note
Compare to Dagger(), this is an inplace function.
See also
Dagger()

◆ device()

int cytnx::UniTensor::device ( ) const
inline

Return the device of the UniTensor.

The function return the device of the UniTensor.

Returns
int

◆ device_str()

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

Return the device of the UniTensor in 'string' form.

Returns
std::string
See also
device()

◆ Div() [1/2]

UniTensor cytnx::UniTensor::Div ( const Scalar rhs) const

The division function for a given scalar.

Given the scalar rhs, it will perform the division for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsa scalar you want to divide in the UniTensor.
Returns
UniTensor
Note
Compare to Div_(const Scalar&), this function will create a new UniTensor.
See also
Div_(const Scalar&), Div_(const UniTensor&), Div(const UniTensor&)const, operator/=(const UniTensor&), operator/=(const Scalar&), operator/

◆ Div() [2/2]

UniTensor cytnx::UniTensor::Div ( const UniTensor rhs) const

The division function of the UniTensor.

This is division function of the UniTensor. Given the UniTensor \( UT_2\) as the argument, it will return a new UniTensor

\[ UT = UT_{self} / UT_2 \]

Perform element-wise division of two UniTensor.

Parameters
[in]rhsthe divisor
Returns
UniTensor
Precondition
The two UniTensor need to have same structure.
Note
Compare to Div_(const UniTensor&), this function will create a new UniTensor.
See also
Div_(const UniTensor&), Div_(const Scalar&), Div(const Scalar&)const , operator/=(const UniTensor&), operator/=(const Scalar&), operator/

◆ Div_() [1/2]

UniTensor & cytnx::UniTensor::Div_ ( const Scalar rhs)
inline

The division function for a given scalar.

Given the scalar rhs, it will perform the division for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsa scalar you want to divide in the UniTensor.
Returns
UniTensor&
Note
Compare to Sub(const Scalar&)const, this is an inplace function.
See also
Div_(const UniTensor&), Div(const UniTensor&)const, Div(const Scalar&)const , operator/=(const UniTensor&), operator/=(const Scalar&), operator/

◆ Div_() [2/2]

UniTensor & cytnx::UniTensor::Div_ ( const UniTensor rhs)
inline

The division function of the UniTensor.

This is division function of the UniTensor. Given the UniTensor \( UT_2\) as the argument, it will return

\[ UT_{self} = UT_{self} / UT_2 \]

Perform element-wise division of two UniTensor.

Parameters
[in]rhsthe divisor
Returns
UniTensor&
Precondition
The two UniTensor need to have same structure.
Note
Compare to Div(const UniTensor&)const, this is an inplace function.
See also
Div_(const Scalar&), Div(const UniTensor&)const, Div(const Scalar&)const , operator/=(const UniTensor&), operator/=(const Scalar&), operator/

◆ dtype()

unsigned int cytnx::UniTensor::dtype ( ) const
inline

Return the data type of the UniTensor.

The function return the data type of the UniTensor.

Returns
unsigned int

◆ dtype_str()

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

Return the data type of the UniTensor in 'string' form.

Returns
std::string
See also
dtype()

◆ elem_exists()

bool cytnx::UniTensor::elem_exists ( const std::vector< cytnx_uint64 > &  locator) const
inline

Geiven the locator, check if the element exists.

Parameters
[in]locatorthe locator of the element.
Returns
[bool]
Note
Same as at(locator).exists().

◆ eye()

static UniTensor cytnx::UniTensor::eye ( const cytnx_uint64 dim,
const std::vector< std::string > &  in_labels = {},
const cytnx_bool is_diag = false,
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate a 2-bond identity UniTensor.

Parameters
[in]dimthe dimension of the diagnal.
[in]in_labelsthe labels of the UniTensor.
[in]is_diagdetermine if the UniTensor is diagonal or not. Default is false.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
Note
2-bond if not diagonal. 1-bond if diagonal.
See also
identity(Nelem, in_labels, is_diag, dtype, device, name) Note: This function is a alias of cytnx::UniTensor::identity().

◆ get()

UniTensor cytnx::UniTensor::get ( const std::vector< Accessor > &  accessors) const
inline

◆ get_block() [1/6]

Tensor cytnx::UniTensor::get_block ( const cytnx_uint64 idx = 0) const
inline

Get the block of the UniTensor for a given index.

Parameters
[in]idxthe index of the block we want to get
Returns
Tensor

◆ get_block() [2/6]

Tensor cytnx::UniTensor::get_block ( const std::initializer_list< cytnx_int64 > &  qnum,
const bool force = false 
) const
inline

◆ get_block() [3/6]

Tensor cytnx::UniTensor::get_block ( const std::vector< cytnx_int64 > &  qidx,
const bool force = false 
) const
inline

Get the block of the UniTensor for the given quantun indices.

Parameters
[in]qidxinput the quantum indices you want to get the corresponding block.
[in]forceIf force is true, it will return the tensor anyway (Even the corresponding block is empty, it will return void type tensor if force is set as true. Otherwise, it will trow the exception.)
Returns
Tensor

◆ get_block() [4/6]

Tensor cytnx::UniTensor::get_block ( const std::vector< cytnx_uint64 > &  qnum,
const bool force = false 
) const
inline

◆ get_block() [5/6]

Tensor cytnx::UniTensor::get_block ( const std::vector< std::string > &  labels,
const std::vector< cytnx_int64 > &  qidx,
const bool force = false 
) const
inline

◆ get_block() [6/6]

Tensor cytnx::UniTensor::get_block ( const std::vector< std::string > &  labels,
const std::vector< cytnx_uint64 > &  qidx,
const bool force = false 
) const
inline

◆ get_block_() [1/10]

Tensor & cytnx::UniTensor::get_block_ ( const cytnx_uint64 idx = 0)
inline
See also
get_block_(const cytnx_uint64 &idx) const
Note
This function only works for non-symmetric UniTensor.

◆ get_block_() [2/10]

const Tensor & cytnx::UniTensor::get_block_ ( const cytnx_uint64 idx = 0) const
inline

Get the shared view of block for the given index.

Parameters
[in]idxinput the index you want to get the corresponding block
Returns
const Tensor&

◆ get_block_() [3/10]

Tensor & cytnx::UniTensor::get_block_ ( const std::initializer_list< cytnx_int64 > &  qidx,
const bool force = false 
)
inline

◆ get_block_() [4/10]

const Tensor & cytnx::UniTensor::get_block_ ( const std::initializer_list< cytnx_int64 > &  qidx,
const bool force = false 
) const
inline

◆ get_block_() [5/10]

Tensor & cytnx::UniTensor::get_block_ ( const std::vector< cytnx_int64 > &  qidx,
const bool force = false 
)
inline

Get the shared view of block for the given quantum indices.

Parameters
[in]qidxinput the quantum indices you want to get the corresponding block.
[in]forceIf force is true, it will return the tensor anyway (Even the corresponding block is empty, it will return void type tensor if force is set as true. Otherwise, it will trow the exception.)
Returns
Tensor&

◆ get_block_() [6/10]

const Tensor & cytnx::UniTensor::get_block_ ( const std::vector< cytnx_int64 > &  qidx,
const bool force = false 
) const
inline

◆ get_block_() [7/10]

Tensor & cytnx::UniTensor::get_block_ ( const std::vector< cytnx_uint64 > &  qidx,
const bool force = false 
)
inline

◆ get_block_() [8/10]

const Tensor & cytnx::UniTensor::get_block_ ( const std::vector< cytnx_uint64 > &  qidx,
const bool force = false 
) const
inline

◆ get_block_() [9/10]

Tensor cytnx::UniTensor::get_block_ ( const std::vector< std::string > &  labels,
const std::vector< cytnx_int64 > &  qidx,
const bool force = false 
)
inline

Get the shared (data) view of block for the given quantum indices on given labels.

Parameters
[in]labelsthe labels of the bonds.
[in]qidxinput the quantum indices you want to get the corresponding block.
[in]forceIf force is true, it will return the tensor anyway (Even the corresponding block is empty, it will return void type tensor if force is set as true. Otherwise, it will trow the exception.)
Returns
Tensor&
Note
labels and qidx forming one to one pairs. e.g. it means get qidx[i] qnum at Bond labels[i]. Also note that the return Tensor will have axes in the same order specified by labels.

◆ get_block_() [10/10]

Tensor cytnx::UniTensor::get_block_ ( const std::vector< std::string > &  labels,
const std::vector< cytnx_uint64 > &  qidx,
const bool force = false 
)
inline

◆ get_blocks()

std::vector< Tensor > cytnx::UniTensor::get_blocks ( ) const
inline

Get all the blocks of the UniTensor.

get_blocks will return the blocks of the UniTensor. Furthermore,

  1. For symmetric UniTensor, it will call contiguous() and then return the deep copy of blocks.

For non-symmetric UniTensor, it will return the deep copy of blocks.

Returns
std::vector<Tensor>

◆ get_blocks_() [1/2]

std::vector< Tensor > & cytnx::UniTensor::get_blocks_ ( const bool silent = false)
inline
See also
get_blocks()_

◆ get_blocks_() [2/2]

const std::vector< Tensor > & cytnx::UniTensor::get_blocks_ ( const bool silent = false) const
inline

Get all the blocks of the UniTensor, inplacely.

See also
get_blocks()
Parameters
[in]silentwhether need to print out the warning messages.

◆ get_elem()

template<class T >
T cytnx::UniTensor::get_elem ( const std::vector< cytnx_uint64 > &  locator) const
inline
Deprecated:
This function is deprecated, please use at() instread.
Note
C++: Deprecated soon, use at()

◆ get_index()

cytnx_int64 cytnx::UniTensor::get_index ( std::string  label) const
inline

Get the index of an desired label string.

Parameters
labelLabel you want to find
Returns
The index of the label. If not found, return -1

◆ get_itoi() [1/2]

vec2d< cytnx_uint64 > & cytnx::UniTensor::get_itoi ( )
inline

◆ get_itoi() [2/2]

const vec2d< cytnx_uint64 > & cytnx::UniTensor::get_itoi ( ) const
inline

get the q-indices on each leg for all the blocks

Returns
[2d vector]

◆ get_qindices() [1/2]

std::vector< cytnx_uint64 > & cytnx::UniTensor::get_qindices ( const cytnx_uint64 bidx)
inline

get the q-indices on each leg for the [bidx]-th block

Parameters
bidxthe bidx-th block in current block list.
Returns
[vector]

◆ get_qindices() [2/2]

const std::vector< cytnx_uint64 > & cytnx::UniTensor::get_qindices ( const cytnx_uint64 bidx) const
inline

get the q-indices on each leg for the [bidx]-th block

Parameters
bidxthe bidx-th block in current block list.
Returns
[vector]

◆ group_basis()

UniTensor cytnx::UniTensor::group_basis ( ) const
inline

◆ group_basis_()

void cytnx::UniTensor::group_basis_ ( )
inline

Group the same quantum number basis together.

If the UniTensor has duplicated quantum number, then this function will group the basis with the same quantum number.

Precondition
The UniTensor must be in block form. That is, the UniTensor is UTenType::Block.

◆ identity()

static UniTensor cytnx::UniTensor::identity ( const cytnx_uint64 dim,
const std::vector< std::string > &  in_labels = {},
const cytnx_bool is_diag = false,
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate a identity UniTensor.

Parameters
[in]dimthe dimension of the diagnal.
[in]in_labelsthe labels of the UniTensor.
[in]is_diagdetermine if the UniTensor is diagonal or not. Default is false.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
Note
2-bond if not diagonal. 1-bond if diagonal.

◆ Init() [1/2]

void cytnx::UniTensor::Init ( const std::vector< Bond > &  bonds,
const std::vector< std::string > &  in_labels = {},
const cytnx_int64 rowrank = -1,
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const bool is_diag = false,
const std::string &  name = "" 
)
inline

Initialize the UniTensor with the given arguments.

This is the initial function of the UniTensor. If you want to initialize your UniTensor after declaring just a 'void' UniTensor. You can use this function to initialize it.

Parameters
[in]bondsthe bond list. Each bond will be deep copy( not a shared view of bond object with input bond)
[in]in_labelsthe labels for each rank(bond)
[in]rowrankthe rank of physical row space
[in]dtypethe dtype of the UniTensor. It can be any type defined in cytnx::Type.
[in]devicethe device that the UniTensor is put on. It can be any device defined in cytnx::Device.
[in]is_diagif the constructed UniTensor is a diagonal UniTensor. This can only be assigned true when the UniTensor is square, untagged and rank-2 UniTensor.
[in]nameuser specified name of the UniTensor.
Precondition
Please ensure that all of the Bond in bonds should be all symmetric or non-symmetric. You cannot mix them.
See also
UniTensor(const std::vector<Bond> &bonds, const std::vector<std::string> &in_labels, const cytnx_int64 &rowrank, const unsigned int &dtype, const int &device, const bool &is_diag)

◆ Init() [2/2]

void cytnx::UniTensor::Init ( const Tensor in_tensor,
const bool is_diag = false,
const cytnx_int64 rowrank = -1,
const std::vector< std::string > &  in_labels = {},
const std::string &  name = "" 
)
inline

Initialize a UniTensor with cytnx::Tensor.

Parameters
[in]in_tensora cytnx::Tensor
[in]is_diagWhether the input Tensor in_tensor is a diagonal Tensor. This will requires that the input of in_tensor to be 1D.
[in]rowrankthe rowrank of the outcome UniTensor.
[in]nameuser specified name of the UniTensor.
Note
  1. The constructed UniTensor will have same rank as the input Tensor, with default labels, and a shared view (shared instance) of interal block as the input Tensor.
  2. The constructed UniTensor is always untagged.
Attention
The internal block of UniTensor is a referece of input Tensor. That is, they share the same memory. All the change afterward on UniTensor block will change in input Tensor as well. Use Tensor.clone() if a shared view is not the case.
See also
UniTensor(const Tensor &, const bool &, const cytnx_int64 &)

◆ is_blockform()

bool cytnx::UniTensor::is_blockform ( ) const
inline

Check whether the UniTensor is in block form.

This function will check whether the UniTensor is in block form. That is, the uten_type() is UTenType::Block.

◆ is_braket_form()

const bool & cytnx::UniTensor::is_braket_form ( ) const
inline

Check whether the UniTensor is in braket form.

This function will check whether the UniTensor is in braket form. That is,

  1. The bonds order, all of the in-bonds are before out-bonds.
  2. The number of in-bonds is equal to the rowrank.

◆ is_contiguous()

bool cytnx::UniTensor::is_contiguous ( ) const
inline

To tell whether the UniTensor is contiguous.

Returns
bool
See also
contiguous(), contiguous_()

◆ is_diag()

bool cytnx::UniTensor::is_diag ( ) const
inline

To tell whether the UniTensor is in diagonal form.

Returns
bool

◆ is_tag()

bool cytnx::UniTensor::is_tag ( ) const
inline

To tell whether the UniTensor is tagged. That is, all of the Bond in the UniTensor is directional (all of them are bondType.BD_KET or bondType.BD_BRA)

Returns
bool

◆ item() [1/2]

template<class T >
T & cytnx::UniTensor::item ( )
inline

◆ item() [2/2]

Scalar::Sproxy cytnx::UniTensor::item ( ) const
inline

◆ labels()

const std::vector< std::string > & cytnx::UniTensor::labels ( ) const
inline

Return the labels of the UniTensor.

Returns
std::vector<std::string>

◆ linspace()

static UniTensor cytnx::UniTensor::linspace ( const cytnx_double start,
const cytnx_double end,
const cytnx_uint64 Nelem,
const bool endpoint = true,
const std::vector< std::string > &  in_labels = {},
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate a one-bond UniTensor with all elements are evenly spaced numbers over a specified interval.

Generate a UniTensor with all elements are evenly spaced numbers over a specified interval. The interval is [start, end] and the number of elements is Nelem.

Parameters
[in]startthe start of the linspace.
[in]endthe end of the linspace.
[in]Nelemthe number of elements.
[in]endpointif endpoint is true, the end of linspace is end, else the end of linspace is end - step.
[in]in_labelsthe labels of the UniTensor.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
linspace(const cytnx_double &start, const cytnx_double &end, const cytnx_uint64 &Nelem, const bool &endpoint, const unsigned int &dtype, const int &device)

◆ Load() [1/2]

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

load a UniTensor from file

Parameters
[in]fnamethe file name
Returns
the loaded UniTensor
Precondition
The file must be a UniTensor object. That is, the file must be created by UniTensor::Save().
See also
Save(const char* fname) const

◆ Load() [2/2]

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

load a UniTensor from file

Parameters
[in]fnamethe file name
Returns
the loaded UniTensor
Precondition
The file must be a UniTensor object. That is, the file must be created by UniTensor::Save().
See also
Save(const std::string &fname) const

◆ Mul() [1/2]

UniTensor cytnx::UniTensor::Mul ( const Scalar rhs) const

The multiplication function for a given scalar.

Given the scalar rhs, it will perform the multiplication for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsa scalar you want to multiply in the UniTensor.
Returns
UniTensor
Note
Compare to Mul_(const Scalar&), this function will create a new UniTensor.
See also
Mul_(const Scalar&), Mul_(const UniTensor&), Mul(const UniTensor&)const, operator*=(const UniTensor&), operator*=(const Scalar&), operator*

◆ Mul() [2/2]

UniTensor cytnx::UniTensor::Mul ( const UniTensor rhs) const

The multiplication function of the UniTensor.

This is multiplication function of the UniTensor. Given the UniTensor \( UT_2\) as the argument, it will return a new UniTensor

\[ UT = UT_{self} \times UT_2 \]

Perform element-wise multiplcation of two UniTensor.

Parameters
[in]rhsThe UniTensor you want to multiplicate by.
Returns
UniTensor
Precondition
The two UniTensor need to have same structure.
Note
Compare to Mul_(const UniTensor&), this function will create a new UniTensor.
See also
Mul_(const UniTensor&), Mul_(const Scalar&), Mul(const Scalar&)const , operator*=(const UniTensor&), operator*=(const Scalar&), operator*

◆ Mul_() [1/2]

UniTensor & cytnx::UniTensor::Mul_ ( const Scalar rhs)
inline

The multiplication function for a given scalar.

Given the scalar rhs, it will perform the multiplication for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsa scalar you want to multiplicate in the UniTensor.
Returns
UniTensor&
Note
Compare to Mul(const Scalar&)const, this is an inplace function.
See also
Mul_(const UniTensor&), Mul(const UniTensor&)const, Mul(const Scalar&)const , operator*=(const UniTensor&), operator*=(const Scalar&), operator*

◆ Mul_() [2/2]

UniTensor & cytnx::UniTensor::Mul_ ( const UniTensor rhs)
inline

The multiplcation function of the UniTensor.

This is multiplcation function of the UniTensor. Given the UniTensor \( UT_2\) as the argument, it will return

\[ UT_{self} = UT_{self} \times UT_2 \]

Perform element-wise multiplication of two UniTensor.

Parameters
[in]rhsThe UniTensor you want to multiplcate by.
Returns
UniTensor&
Precondition
The two UniTensor need to have same structure.
Note
Compare to Mul(const UniTensor&)const, this is an inplace function.
See also
Mul_(const Scalar&), Mul(const UniTensor&)const, Mul(const Scalar&)const , operator*=(const UniTensor&), operator*=(const Scalar&), operator*

◆ name()

std::string cytnx::UniTensor::name ( ) const
inline

Return the name of the UniTensor.

Returns
std::string

◆ Nblocks()

cytnx_uint64 cytnx::UniTensor::Nblocks ( ) const
inline

Return the number of blocks in the UniTensor.

Returns
cytnx_uint64

◆ Norm()

Tensor cytnx::UniTensor::Norm ( ) const
inline

Return the norm of the UniTensor.

Norm() return the 2-norm of the UniTensor \(UT\). Namely, it return

\[ ||UT||_2 \]

Returns
Tensor

◆ normal() [1/2]

static UniTensor cytnx::UniTensor::normal ( const cytnx_uint64 Nelem,
const double mean,
const double std,
const std::vector< std::string > &  in_labels = {},
const unsigned int seed = cytnx::random::__static_random_device(),
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
static

Generate a one-bond UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution.

Generate a UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution. The mean is mean and the standard deviation is std.

Parameters
[in]Nelemthe number of elements.
[in]meanthe mean of the normal distribution.
[in]stdthe standard deviation of the normal distribution.
[in]in_labelsthe labels of the UniTensor.
[in]seedthe seed of the random generator.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
random::normal(const cytnx_uint64 &Nelem, const double &mean, const double &std, const int &device, const unsigned int &seed, const unsigned int &dtype)

◆ normal() [2/2]

static UniTensor cytnx::UniTensor::normal ( const std::vector< cytnx_uint64 > &  shape,
const double mean,
const double std,
const std::vector< std::string > &  in_labels = {},
const unsigned int seed = cytnx::random::__static_random_device(),
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
static

Generate a UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution.

Generate a UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution. The mean is mean and the standard deviation is std.

Parameters
[in]shapethe shape of the UniTensor.
[in]meanthe mean of the normal distribution.
[in]stdthe standard deviation of the normal distribution.
[in]in_labelsthe labels of the UniTensor.
[in]seedthe seed of the random generator.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
random::normal(const std::vector< cytnx_uint64 > &shape, const double &mean, const double &std, const int &device, const unsigned int &seed, const unsigned int &dtype)

◆ normal_()

void cytnx::UniTensor::normal_ ( const double mean,
const double std,
const unsigned int seed = cytnx::random::__static_random_device() 
)

Generate a one-bond UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution, inplacely.

This function provides an inplacely way to generate a UniTensor with all elements are random numbers sampled from a normal (Gaussian) distribution. The mean is mean and the standard deviation is std.

Parameters
[in]meanthe mean of the normal distribution.
[in]stdthe standard deviation of the normal distribution.
[in]seedthe seed of the random generator.
See also
random::normal_(UniTensor &in, const double &mean, const double &std, const unsigned int &seed)

◆ normalize()

UniTensor cytnx::UniTensor::normalize ( ) const
inline

normalize the current UniTensor instance with 2-norm.

Returns
UniTensor
Note
Compare to normalize_(), this fucntion will return new UniTensor object.
See also
normalize_()

◆ normalize_()

UniTensor & cytnx::UniTensor::normalize_ ( )
inline

normalize the UniTensor, inplacely.

Returns
UniTensor
Note
Compare to normalize(), this fucntion is inplace function.
See also
normalize()

◆ ones() [1/2]

static UniTensor cytnx::UniTensor::ones ( const cytnx_uint64 Nelem,
const std::vector< std::string > &  in_labels = {},
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate a one-bond UniTensor with all elements set to one.

Parameters
[in]Nelemthe number of elements.
[in]in_labelsthe labels of the UniTensor.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
ones(const cytnx_uint64 &Nelem, const unsigned int &dtype, const int &device)

◆ ones() [2/2]

static UniTensor cytnx::UniTensor::ones ( const std::vector< cytnx_uint64 > &  shape,
const std::vector< std::string > &  in_labels = {},
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate a UniTensor with all elements set to one.

Parameters
[in]shapethe shape of the UniTensor.
[in]in_labelsthe labels of the UniTensor.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
ones(const std::vector< cytnx_uint64 > &shape, const unsigned int &dtype, const int &device)

◆ operator*=() [1/2]

The multiplication assignment operator for a given scalar.

Given the scalar rhs, it will perform the multiplication for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsa scalar you want to multiply in the UniTensor.
Returns
UniTensor&
See also
operator*=(const Scalar&), operator*, Mul_(const UniTensor&), Mul_(const Scalar&), Mul(const UniTensor&), Mul(const Scalar&)const

◆ operator*=() [2/2]

The multiplication assignment operator of the UniTensor.

This is multiplication assignment operator of the UniTensor. It will perform element-wise multiplication and return

\[ UT *= UT_R \]

Parameters
[in]rhsThe UniTensor you want to multilicate by.
Returns
UniTensor&
Precondition
The two UniTensor need to have same structure.
See also
operator*=(const Scalar&), operator*, Mul_(const UniTensor&), Mul_(const Scalar&), Mul(const UniTensor&), Mul(const Scalar&)const

◆ operator+=() [1/2]

The addition assignment operator for a given scalar.

Given the scalar rhs, it will perform the addition for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsa scalar you want to add in the UniTensor.
Returns
UniTensor&
See also
operator+=(const UniTensor&), operator+, Add_(const UniTensor&), Add_(const Scalar&), Add(const UniTensor&), Add(const Scalar&)const

◆ operator+=() [2/2]

The addition assignment operator of the UniTensor.

This is addition assignment operator of the UniTensor. It will perform element-wise addition and return

\[ UT += UT_R \]

Parameters
[in]rhsThe UniTensor you want to add by.
Returns
UniTensor&
Precondition
The two UniTensor need to have same structure.
See also
operator+=(const Scalar&), operator+, Add_(const UniTensor&), Add_(const Scalar&), Add(const UniTensor&), Add(const Scalar&)const

◆ operator-=() [1/2]

The subtraction assignment operator for a given scalar.

Given the scalar rhs, it will perform the subtraction for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsthe subtrahend
Returns
UniTensor&
See also
operator-=(const UniTensor&), operator-, Sub_(const UniTensor&), Sub_(const Scalar&), Sub(const UniTensor&), Sub(const Scalar&)const

◆ operator-=() [2/2]

The subtraction assignment operator of the UniTensor.

This is subtraction assignment operator of the UniTensor. It will perform element-wise subtraction and return

\[ UT -= UT_R \]

Parameters
[in]rhsthe subtrahend
Returns
UniTensor&
Precondition
The two UniTensor need to have same structure.
See also
operator-=(const Scalar&), operator-, Sub_(const UniTensor&), Sub_(const Scalar&), Sub(const UniTensor&), Sub(const Scalar&)const

◆ operator/=() [1/2]

The division assignment operator for a given scalar.

Given the scalar rhs, it will perform the division for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsthe divisor
Returns
UniTensor&
See also
operator/=(const UniTensor&), operator/, Div_(const UniTensor&), Div_(const Scalar&), Div(const UniTensor&), Div(const Scalar&)const

◆ operator/=() [2/2]

The division assignment operator of the UniTensor.

This is division assignment operator of the UniTensor. It will perform element-wise division and return

\[ UT /= UT_R \]

Parameters
[in]rhsthe divisor
Returns
UniTensor&
Precondition
The two UniTensor need to have same structure.
See also
operator/=(const Scalar&), operator/, Div_(const UniTensor&), Div_(const Scalar&), Div(const UniTensor&), Div(const Scalar&)const

◆ permute() [1/3]

UniTensor cytnx::UniTensor::permute ( const std::initializer_list< char * > &  mapper,
const cytnx_int64 rowrank = -1 
) const
inline
See also
permute(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank = -1)

◆ permute() [2/3]

UniTensor cytnx::UniTensor::permute ( const std::vector< cytnx_int64 > &  mapper,
const cytnx_int64 rowrank = -1 
) const
inline

permute the lags of the UniTensor

Parameters
[in]mapperthe mapper of the permutation. This mapper is mapped by bond index if by_label is false, otherwise it is mapped by bond label.
[in]rowrankthe new rowrank after the permutation
Returns
UniTensor
Warning
by_label will be deprecated!

◆ permute() [3/3]

UniTensor cytnx::UniTensor::permute ( const std::vector< std::string > &  mapper,
const cytnx_int64 rowrank = -1 
) const
inline

permute the lags of the UniTensor by labels

Parameters
[in]mapperthe mapper by babels
[in]rowrankthe row rank
Returns
UniTensor

◆ permute_() [1/2]

void cytnx::UniTensor::permute_ ( const std::vector< cytnx_int64 > &  mapper,
const cytnx_int64 rowrank = -1 
)
inline

permute the lags of the UniTensor, inplacely.

Deprecated:
It is recommended to use permute_(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank = -1)
Parameters
[in]mapperthe mapper by labels
[in]rowrankthe row rank after the permutation
Warning
by_label will be deprecated!

◆ permute_() [2/2]

void cytnx::UniTensor::permute_ ( const std::vector< std::string > &  mapper,
const cytnx_int64 rowrank = -1 
)
inline

permute the lags of the UniTensor, inplacely.

Parameters
[in]mapperthe mapper by labels
[in]rowrankthe row rank after the permutation
See also
permute(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank = -1)

◆ Pow()

UniTensor cytnx::UniTensor::Pow ( const double p) const

Power function.

Take power p on all the elements in the UniTensor.

Parameters
ppower
Returns
UniTensor
Note
Compare to Pow_(), this function will create a new UniTensor ojbect.
See also
Pow_()

◆ Pow_()

UniTensor & cytnx::UniTensor::Pow_ ( const double p)

Power function.

Take power p on all the elements in the UniTensor, inplacely.

Parameters
ppower
Returns
UniTensor&
Note
Compare to Pow(), this function is an inplacely function.
See also
Pow()

◆ print_block()

void cytnx::UniTensor::print_block ( const cytnx_int64 idx,
const bool full_info = true 
) const
inline

Given a index and print out the corresponding block of the UniTensor.

Parameters
[in]idxthe input index
[in]full_infowhether need to print the full information of the block

◆ print_blocks()

void cytnx::UniTensor::print_blocks ( const bool full_info = true) const
inline

Print all of the blocks in the UniTensor.

Parameters
[in]full_infowhether need to print the full information of the blocks

◆ print_diagram()

void cytnx::UniTensor::print_diagram ( const bool bond_info = false)
inline

Plot the diagram of the UniTensor.

Parameters
[in]bond_infowhether need to print the information of the bonds of the UniTensor.

◆ put_block() [1/3]

void cytnx::UniTensor::put_block ( const Tensor in,
const cytnx_uint64 idx = 0 
)
inline

Put the block into the UniTensor with given index.

Parameters
[in]inthe block you want to put into UniTensor
[in]inthe index of the UniTensor you want to put the block in in.

◆ put_block() [2/3]

void cytnx::UniTensor::put_block ( const Tensor in_tens,
const std::vector< cytnx_int64 > &  qidx,
const bool force 
)
inline

Put the block into the UniTensor with given quantum number.

Parameters
[in]in_tensthe block you want to put into UniTensor
[in]qidxthe quantum indices of the UniTensor you want to put the block in_tens in.
Warning
force will be deprecated soon!

◆ put_block() [3/3]

void cytnx::UniTensor::put_block ( Tensor in,
const std::vector< std::string > &  lbls,
const std::vector< cytnx_int64 > &  qidx,
const bool force = false 
)
inline

Put the block into the UniTensor with given quantum indices, will copy the input tensor.

◆ put_block_() [1/3]

void cytnx::UniTensor::put_block_ ( Tensor in,
const cytnx_uint64 idx = 0 
)
inline

Put the block into the UniTensor with given index, inplacely.

Note
the put block will have shared view with the internal block, i.e. non-clone.
See also
put_block(const Tensor &in, const cytnx_uint64 &idx)

◆ put_block_() [2/3]

void cytnx::UniTensor::put_block_ ( Tensor in,
const std::vector< cytnx_int64 > &  qidx,
const bool force 
)
inline

Put the block into the UniTensor with given quantum indices, inplacely.

Note
the put block will have shared view with the internal block, i.e. non-clone.
See also
put_block(const Tensor &in, const cytnx_uint64 &idx)
Warning
force will be deprecated soon!

◆ put_block_() [3/3]

void cytnx::UniTensor::put_block_ ( Tensor in,
const std::vector< std::string > &  lbls,
const std::vector< cytnx_int64 > &  qidx,
const bool force = false 
)
inline

Put the block into the UniTensor with given quantum indices, inplacely.

Note
the put block will have shared view with the internal block, i.e. non-clone.

◆ rank()

cytnx_uint64 cytnx::UniTensor::rank ( ) const
inline

Return the rank of the UniTensor.

Returns
cytnx_uint64

◆ relabel() [1/2]

UniTensor cytnx::UniTensor::relabel ( const cytnx_int64 inx,
const std::string &  new_label 
) const
inline

rebable the lags in the UniTensor by given index.

This function will relabel the lags in the UniTensor by a given index. This function will return a new UniTensor with the new label, but the data is still shared with the original UniTensor (that is if you use same_data() to check, it will return true). Compare to set_label(), this function will return a new UniTensor object with different meta data.

Parameters
[in]inxa given index
[in]new_labelthe new label of the UniTensor in the index inx
Attention
This function will return a new UniTensor with the new label, but the data is still shared with the original UniTensor. That is the meta data of the UniTensor is different, but the internal data is still shared.
See also
set_label(const cytnx_int64 &idx, const std::string &new_label)

◆ relabel() [2/2]

UniTensor cytnx::UniTensor::relabel ( const std::string &  old_label,
const std::string &  new_label 
) const
inline

relabel the lags in the UniTensor by a given label.

This function will relabel the lags in the UniTensor by a given label. This function will return a new UniTensor with the new label, but the data is still shared with the original UniTensor (that is if you use same_data() to check, it will return true). Compare to set_label(), this function will return a new UniTensor object with different meta data.

Parameters
[in]old_labeloriginal label you want to replace
[in]new_labelthe new label
Attention
This function will return a new UniTensor with the new label, but the data is still shared with the original UniTensor. That is the meta data of the UniTensor is different, but the internal data is still shared.
See also
set_label(const std::string &old_label, const std::string &new_label)

◆ relabel_() [1/2]

UniTensor & cytnx::UniTensor::relabel_ ( const cytnx_int64 inx,
const std::string &  new_label 
)
inline

rebable the lags in the UniTensor by given index.

This function will relabel the lags in the UniTensor by a given index. This function will alter the label of the UniTensor directly.

Parameters
[in]inxa given index
[in]new_labelthe new label of the UniTensor in the index inx
See also
set_label(const cytnx_int64 &idx, const std::string &new_label)

◆ relabel_() [2/2]

UniTensor & cytnx::UniTensor::relabel_ ( const std::string &  old_label,
const std::string &  new_label 
)
inline

relabel the lags in the UniTensor by a given label.

This function will relabel the lags in the UniTensor by a given label. This function will alter the label of the UniTensor directly.

Parameters
[in]old_labeloriginal label you want to replace
[in]new_labelthe new label
See also
set_label(const std::string &old_label, const std::string &new_label)

◆ relabels() [1/4]

UniTensor cytnx::UniTensor::relabels ( const std::initializer_list< char * > &  new_labels) const
inline

◆ relabels() [2/4]

UniTensor cytnx::UniTensor::relabels ( const std::initializer_list< char * > &  old_labels,
const std::initializer_list< char * > &  new_labels 
) const
inline

◆ relabels() [3/4]

UniTensor cytnx::UniTensor::relabels ( const std::vector< std::string > &  new_labels) const
inline

relables all of the labels in UniTensor.

Parameters
[in]new_labelsthe new labels for each bond.
Note
  1. the new assign label cannot be the same as the label of any other bonds in the UniTensor. ( cannot have duplicate labels )
Attention
This function will return a new UniTensor with the new label, but the data is still shared with the original UniTensor. That is the meta data of the UniTensor is different, but the internal data is still shared.

◆ relabels() [4/4]

UniTensor cytnx::UniTensor::relabels ( const std::vector< std::string > &  old_labels,
const std::vector< std::string > &  new_labels 
) const
inline

replace part or all labels by given new labels for the bonds.

Parameters
[in]old_labelsthe old labels for each bond.
[in]new_labelsthe new labels for each bond.
Note
  1. the final output UniTensor cannot have duplicate labels.

◆ relabels_() [1/4]

UniTensor & cytnx::UniTensor::relabels_ ( const std::initializer_list< char * > &  new_labels)
inline

◆ relabels_() [2/4]

UniTensor & cytnx::UniTensor::relabels_ ( const std::initializer_list< char * > &  old_labels,
const std::initializer_list< char * > &  new_labels 
)
inline

◆ relabels_() [3/4]

UniTensor & cytnx::UniTensor::relabels_ ( const std::vector< std::string > &  new_labels)
inline

Set new labels for all the bonds.

Parameters
[in]new_labelsthe new labels for each bond.
Note
  1. the new assign label cannot be the same as the label of any other bonds in the UniTensor. ( cannot have duplicate labels )
  2. Compare to relabels(const std::vector<std::string> &new_labels) const, this function set the new label to itself.

◆ relabels_() [4/4]

UniTensor & cytnx::UniTensor::relabels_ ( const std::vector< std::string > &  old_labels,
const std::vector< std::string > &  new_labels 
)
inline

relables part or all of the labels in UniTensor by given new labels

Parameters
[in]old_labelsthe old labels for each bond.
[in]new_labelsthe new labels for each bond.
Note
  1. the final output UniTensor cannot have duplicate labels.
  2. Compare to relabels(const std::vector<std::string> &old_labels, const std::vector<std::string> &new_labels) const , this function set the new label(s) to itself.
See also
relabels(const std::vector<std::string> &old_labels, const std::vector<std::string> &new_labels) const
Attention
This function will return a new UniTensor with the new labels, but the data is still shared with the original UniTensor. That is the meta data of the UniTensor is different, but the internal data is still shared.

◆ reshape()

UniTensor cytnx::UniTensor::reshape ( const std::vector< cytnx_int64 > &  new_shape,
const cytnx_uint64 rowrank = 0 
)
inline

Reshape the UniTensor.

Parameters
[in]new_shapethe new shape you want to reshape to.
[in]rowrankthe rowrank of the UniTensor after you reshape it.
Note
This function only works for non-symmetric UniTensor. That is, the UniTensor cannot be UTenType::Block.

◆ reshape_()

void cytnx::UniTensor::reshape_ ( const std::vector< cytnx_int64 > &  new_shape,
const cytnx_uint64 rowrank = 0 
)
inline

Reshape the UniTensor, inplacely.

Note
This function only works for non-symmetric UniTensor. That is, the UniTensor cannot be UTenType::Block.
See also
reshape(const std::vector<cytnx_int64> &new_shape, const cytnx_uint64 &rowrank)

◆ rowrank()

cytnx_uint64 cytnx::UniTensor::rowrank ( ) const
inline

Return the row rank of the UniTensor.

Returns
cytnx_uint64

◆ same_data()

bool cytnx::UniTensor::same_data ( const UniTensor rhs) const
inline

Check whether the Blocks address are the same.

Returns
bool

◆ Save() [1/2]

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

save a UniTensor to file

Save a UniTensor to file. The file extension will be extended as '.cytnx'

Parameters
[in]fnamethe file name (exclude the file extension).
See also
Load(const char *fname)

◆ Save() [2/2]

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

save a UniTensor to file

Save a UniTensor to file. The file extension will be extended as '.cytnx'

Parameters
[in]fnamethe file name (exclude the file extension).
See also
Load(const std::string &fname)

◆ set() [1/2]

void cytnx::UniTensor::set ( const std::vector< Accessor > &  accessors,
const Tensor rhs 
)
inline

◆ set() [2/2]

void cytnx::UniTensor::set ( const std::vector< Accessor > &  accessors,
const UniTensor rhs 
)
inline

◆ set_elem()

template<class T2 >
void cytnx::UniTensor::set_elem ( const std::vector< cytnx_uint64 > &  locator,
const T2 rc 
)
inline
Deprecated:
This function is deprecated, please use at() instread.
Note
C++: Deprecated soon, use at()

◆ set_label() [1/6]

UniTensor & cytnx::UniTensor::set_label ( const char old_label,
const char new_label 
)
inline

◆ set_label() [2/6]

UniTensor & cytnx::UniTensor::set_label ( const char old_label,
const std::string &  new_label 
)
inline

◆ set_label() [3/6]

UniTensor & cytnx::UniTensor::set_label ( const cytnx_int64 idx,
const char new_label 
)
inline

◆ set_label() [4/6]

UniTensor & cytnx::UniTensor::set_label ( const cytnx_int64 idx,
const std::string &  new_label 
)
inline

Set a new label for bond at the assigned index.

Parameters
[in]idxthe index of the bond.
[in]new_labelthe new label that is assign to the bond.
Note
  1. the new assign label cannot be the same as the label of any other bonds in the UniTensor. ( cannot have duplicate labels )
  2. Compare to relabel(const cytnx_int64 &idx, const std::string &new_label) const, this function set the new label and return self.

◆ set_label() [5/6]

UniTensor & cytnx::UniTensor::set_label ( const std::string &  old_label,
const char new_label 
)
inline

◆ set_label() [6/6]

UniTensor & cytnx::UniTensor::set_label ( const std::string &  old_label,
const std::string &  new_label 
)
inline

set a new label for bond to replace one of the current label.

Parameters
[in]old_labelthe current label of the bond.
[in]new_labelthe new label that is assign to the bond.
Note
  1. the new assign label cannot be the same as the label of any other bonds in the UniTensor. ( cannot have duplicate labels )
  2. Compare to relabel(const std::string &old_label, const std::string &new_label) const, this function set the new label and return self.

◆ set_labels() [1/2]

UniTensor & cytnx::UniTensor::set_labels ( const std::initializer_list< char * > &  new_labels)
inline

◆ set_labels() [2/2]

UniTensor & cytnx::UniTensor::set_labels ( const std::vector< std::string > &  new_labels)
inline

Set new labels for all the bonds.

Parameters
[in]new_labelsthe new labels for each bond.
Note
  1. the new assign label cannot be the same as the label of any other bonds in the UniTensor. ( cannot have duplicate labels )
  2. Compare to relabels(const std::vector<std::string> &new_labels) const, this function set the new label and return self.

◆ set_name()

UniTensor & cytnx::UniTensor::set_name ( const std::string &  in)
inline

Set the name of the UniTensor.

You can use this function to give a name for the UniTensor.

Parameters
[in]inInput the name you want to set for the UniTensor. It should be a string.
Returns
UniTensor

◆ set_rowrank()

UniTensor cytnx::UniTensor::set_rowrank ( const cytnx_uint64 new_rowrank) const
inline

◆ set_rowrank_()

UniTensor & cytnx::UniTensor::set_rowrank_ ( const cytnx_uint64 new_rowrank)
inline

Set the row rank of the UniTensor.

You can use this function to set the row rank of the UniTensor. The row rank is important if you want to use the linear algebra process.

Parameters
[in]new_rowrankthe new row rank of the UniTensor

◆ shape()

std::vector< cytnx_uint64 > cytnx::UniTensor::shape ( ) const
inline

Get the shape of the UniTensor.

Returns
std::vector<cytnx_uint64>

◆ Sub() [1/2]

UniTensor cytnx::UniTensor::Sub ( const Scalar rhs) const

The subtraction function for a given scalar.

Given the scalar rhs, it will perform the subtraction for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsthe subtrahend
Returns
UniTensor
Note
Compare to Sub_(const Scalar&), this function will create a new UniTensor.
See also
Sub_(const Scalar&), Sub_(const UniTensor&), Sub(const UniTensor&)const, operator-=(const UniTensor&), operator-=(const Scalar&), operator-

◆ Sub() [2/2]

UniTensor cytnx::UniTensor::Sub ( const UniTensor rhs) const

The subtraction function of the UniTensor.

This is subtraction function of the UniTensor. Given the UniTensor \( UT_2\) as the argument, it will return a new UniTensor

\[ UT = UT_{self} - UT_2 \]

Perform element-wise subtraction of two UniTensor.

Parameters
[in]rhsthe subtrahend
Returns
UniTensor
Precondition
The two UniTensor need to have same structure.
Note
Compare to Sub_(const UniTensor&), this function will create a new UniTensor.
See also
Sub_(const UniTensor&), Sub_(const Scalar&), Sub(const Scalar&)const , operator-=(const UniTensor&), operator-=(const Scalar&), operator-

◆ Sub_() [1/2]

UniTensor & cytnx::UniTensor::Sub_ ( const Scalar rhs)
inline

The subtraction function for a given scalar.

Given the scalar rhs, it will perform the subtraction for each element in UniTensor with this scalar rhs.

Parameters
[in]rhsa scalar you want to subtract in the UniTensor.
Returns
UniTensor&
Note
Compare to Sub(const Scalar&)const, this is an inplace function.
See also
Sub_(const UniTensor&), Sub(const UniTensor&)const, Sub(const Scalar&)const , operator-=(const UniTensor&), operator-=(const Scalar&), operator-

◆ Sub_() [2/2]

UniTensor & cytnx::UniTensor::Sub_ ( const UniTensor rhs)
inline

The subtraction function of the UniTensor.

This is subtraction function of the UniTensor. Given the UniTensor \( UT_2\) as the argument, it will return

\[ UT_{self} = UT_{self} - UT_2 \]

Perform element-wise subtraction of two UniTensor.

Parameters
[in]rhsthe subtrahend
Returns
UniTensor&
Precondition
The two UniTensor need to have same structure.
Note
Compare to Sub(const UniTensor&)const, this is an inplace function.
See also
Sub_(const Scalar&), Sub(const UniTensor&)const, Sub(const Scalar&)const , operator-=(const UniTensor&), operator-=(const Scalar&), operator-

◆ syms()

std::vector< Symmetry > cytnx::UniTensor::syms ( ) const
inline

Return the symmetry type of the UniTensor.

We can get the Symmetry structure by calling this function.

Returns
std::vector<Symmetry>

◆ tag()

UniTensor & cytnx::UniTensor::tag ( )
inline

Set the UniTensor as a tagged UniTensor.

This function will set the untagged UniTensor(all of the Bonds are BondType::BD_REG) ) to tagged UniTensor (all of the Bonds are BondType::BD_BRA or BondType::BD_KET). And it will change the UniTensor to bra-ket form. See is_braket_form() for more information.

See also
is_braket_form()

◆ to()

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

move the current UniTensor to the assigned device.

Warning
if the device-id is the same as current Tensor's device, then return self. otherwise, return a copy of instance that located on the target device.
Parameters
[in]devicethe device-id(cytnx::Device) that is moving to. It can by any device defined in cytnx::Device.
Returns
UniTensor
See also
to(const int &device)

◆ to_()

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

move the current UniTensor to the assigned device (inplace).

Parameters
[in]devicethe device-id(cytnx::Device) that is moving to. It can by any device defined in cytnx::Device.
See also
to_(const int &device)

◆ to_dense()

UniTensor cytnx::UniTensor::to_dense ( )
inline

Convert the UniTensor to non-diagonal form.

to_dense() convert the UniTensor from diagonal form to non-diagonal structure. That means input the UniTensor with is_diag = true to is_diag = false.

Precondition
  1. The UniTensor need to be Dense UniTensor, that means this function is only support for UTenType.Dense.
  2. The UniTensor need to be diagonal form (that means is_diag is true.)
Returns
UniTensor
See also
to_dense_(), is_diag()

◆ to_dense_()

void cytnx::UniTensor::to_dense_ ( )
inline

Convert the UniTensor to non-diagonal form, inplacely.

See also
to_dense(), is_diag()

◆ Trace() [1/2]

UniTensor cytnx::UniTensor::Trace ( const cytnx_int64 a = 0,
const cytnx_int64 b = 1 
) const
inline

Take the partial trance to the UniTensor.

Take the partial trace to the UniTensor with the give two labels.

Parameters
[in]alabel 1
[in]blabel 2
Returns
UniTensor
Note
Compare to Trace_(), this fucntion will return a new UniTensor object.
See also
Trace_()

◆ Trace() [2/2]

UniTensor cytnx::UniTensor::Trace ( const std::string &  a,
const std::string &  b 
) const
inline

Take the partial trance to the UniTensor.

Take the partial trace to the UniTensor with the give two labels.

Parameters
[in]alabel 1
[in]blabel 2
Returns
UniTensor
Note
Compare to Trace_(), this fucntion will return a new UniTensor object.
See also
Trace_()

◆ Trace_() [1/2]

UniTensor & cytnx::UniTensor::Trace_ ( const cytnx_int64 a = 0,
const cytnx_int64 b = 1 
)
inline

Take the partial trance to the UniTensor, inplacely.

Take the partial trace to the UniTensor with the give two labels.

Parameters
[in]alabel 1
[in]blabel 2
Returns
UniTensor&
Note
Compare to Trace(), this is an inplace function.
See also
Trace()

◆ Trace_() [2/2]

UniTensor & cytnx::UniTensor::Trace_ ( const std::string &  a,
const std::string &  b 
)
inline

Take the partial trance to the UniTensor, inplacely.

Take the partial trace to the UniTensor with the give two labels.

Parameters
[in]alabel 1
[in]blabel 2
Returns
UniTensor&
Note
Compare to Trace(), this is an inplace function.
See also
Trace()

◆ Transpose()

UniTensor cytnx::UniTensor::Transpose ( ) const
inline

Take the transpose of the UniTensor.

This function will take the transpose of the UniTensor. If the UniTensor is tagged (i.e. the Bonds are directional), it will swap the direction of the Bonds but the rowrank will not change. If the UniTensor is untagged (i.e. the Bonds are BondType::BD_REG), it will change the rowrank to the opposite side.

Returns
UniTensor
Note
Compare to Transpose_(), this fucntion will return new UniTensor object.
See also
Transpose_()

◆ Transpose_()

UniTensor & cytnx::UniTensor::Transpose_ ( )
inline

Take the transpose of the UniTensor, inplacely.

Returns
UniTensor
Note
Compare to Transpose(), this fucntion is inplace function.
See also
Transpose()

◆ truncate() [1/2]

UniTensor cytnx::UniTensor::truncate ( const cytnx_int64 bond_idx,
const cytnx_uint64 dim 
) const
inline

truncate bond dimension of the UniTensor by the given bond index and dimension.

Parameters
[in]bond_idxthe bond index.
[in]dimthe dimension to be truncated.
Returns
[UniTensor]
Note
compare to truncate_(const cytnx_int64 &bond_idx, const cytnx_uint64 &dim), this function will return a new UniTensor object.
See also
UniTensor::truncate_(const cytnx_int64 &bond_idx, const cytnx_uint64 &dim)

◆ truncate() [2/2]

UniTensor cytnx::UniTensor::truncate ( const std::string &  label,
const cytnx_uint64 dim 
) const
inline

truncate bond dimension of the UniTensor by the given bond label and dimension.

Parameters
[in]labelthe bond label.
[in]dimthe dimension to be truncated.
Returns
[UniTensor]
Note
compare to truncate_(const std::string &bond_idx, const cytnx_uint64 &dim), this function will return a new UniTensor object.
See also
UniTensor::truncate_(const std::string &bond_idx, const cytnx_uint64 &dim)

◆ truncate_() [1/2]

UniTensor & cytnx::UniTensor::truncate_ ( const cytnx_int64 bond_idx,
const cytnx_uint64 dim 
)
inline

truncate bond dimension of the UniTensor by the given bond index and dimension.

Parameters
[in]bond_idxthe bond index.
[in]dimthe dimension to be truncated.
Returns
[UniTensor]
Note
compare to truncate(const cytnx_int64 &bond_idx, const cytnx_uint64 &dim), this is inplace function and will modify the current UniTensor object.

◆ truncate_() [2/2]

UniTensor & cytnx::UniTensor::truncate_ ( const std::string &  label,
const cytnx_uint64 dim 
)
inline

truncate bond dimension of the UniTensor by the given bond label and dimension.

Parameters
[in]labelthe bond label.
[in]dimthe dimension to be truncated.
Returns
[UniTensor]
Note
compare to truncate(const std::string &bond_idx, const cytnx_uint64 &dim), this is inplace function and will modify the current UniTensor object.

◆ uniform() [1/2]

static UniTensor cytnx::UniTensor::uniform ( const cytnx_uint64 Nelem,
const double low,
const double high,
const std::vector< std::string > &  in_labels = {},
const unsigned int seed = cytnx::random::__static_random_device(),
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
static

Generate a one-bond UniTensor with all elements are random numbers sampled from a uniform distribution.

Generate a UniTensor with all elements are random numbers sampled from a uniform distribution. The low bound is low and the high bound is high.

Parameters
[in]Nelemthe number of elements.
[in]lowthe low bound of the uniform distribution.
[in]highthe high bound of the uniform distribution.
[in]in_labelsthe labels of the UniTensor.
[in]seedthe seed of the random generator.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
random::uniform(const cytnx_uint64 &Nelem, const double &low, const double &high, const int &device, const unsigned int &seed, const unsigned int &dtype)

◆ uniform() [2/2]

static UniTensor cytnx::UniTensor::uniform ( const std::vector< cytnx_uint64 > &  shape,
const double low,
const double high,
const std::vector< std::string > &  in_labels = {},
const unsigned int seed = cytnx::random::__static_random_device(),
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
static

Generate a UniTensor with all elements are random numbers sampled from a uniform distribution.

Generate a UniTensor with all elements are random numbers sampled from a uniform distribution. The low bound is low and the high bound is high.

Parameters
[in]shapethe shape of the UniTensor.
[in]lowthe low bound of the uniform distribution.
[in]highthe high bound of the uniform distribution.
[in]in_labelsthe labels of the UniTensor.
[in]seedthe seed of the random generator.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
random::uniform(const std::vector< cytnx_uint64 > &shape, const double &low, const double &high, const int &device, const unsigned int &seed, const unsigned int &dtype)

Generate a UniTensor with all elements are random numbers sampled from a uniform distribution.

Generate a UniTensor with all elements are random numbers sampled from a uniform distribution. The low bound is low and the high bound is high.

Parameters
[in]shapethe shape of the UniTensor.
[in]lowthe low bound of the uniform distribution.
[in]highthe high bound of the uniform distribution.
[in]in_labelsthe labels of the UniTensor.
[in]seedthe seed of the random generator.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
random::uniform(const std::vector< cytnx_uint64 > &shape, const double &low, const double &high, const int &device, const unsigned int &seed, const unsigned int &dtype)

◆ uniform_()

void cytnx::UniTensor::uniform_ ( const double low = 0,
const double high = 1,
const unsigned int seed = cytnx::random::__static_random_device() 
)

Generate a UniTensor with all elements are random numbers sampled from a uniform distribution, inplacely.

This function provides an inplacely way to generate a UniTensor with all elements are random numbers sampled from a uniform distribution. The low bound is low and the high bound is high.

Parameters
[in]lowthe low bound of the uniform distribution.
[in]highthe high bound of the uniform distribution.
[in]seedthe seed of the random generator.
See also
random::uniform_(UniTensor &in, const double &low, const double &high, const unsigned int &seed)

◆ uten_type()

int cytnx::UniTensor::uten_type ( ) const
inline

Return the UniTensor type (cytnx::UTenType) of the UniTensor.

The function return the UniTensor type of the UniTensor.

Returns
int
See also
uten_type_str()

◆ uten_type_str()

std::string cytnx::UniTensor::uten_type_str ( ) const
inline

Return the UniTensor type (cytnx::UTenType) of the UniTensor in 'string' form.

Returns
std::string
See also
uten_type()

◆ zeros() [1/2]

static UniTensor cytnx::UniTensor::zeros ( const cytnx_uint64 Nelem,
const std::vector< std::string > &  in_labels = {},
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate a one-bond UniTensor with all elements set to zero.

Parameters
[in]Nelemthe number of elements.
[in]in_labelsthe labels of the UniTensor.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
zeros(const cytnx_uint64 &Nelem, const unsigned int &dtype, const int &device)

◆ zeros() [2/2]

static UniTensor cytnx::UniTensor::zeros ( const std::vector< cytnx_uint64 > &  shape,
const std::vector< std::string > &  in_labels = {},
const unsigned int dtype = Type.Double,
const int device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate a UniTensor with all elements set to zero.

Parameters
[in]shapethe shape of the UniTensor.
[in]in_labelsthe labels of the UniTensor.
[in]dtypethe data type of the UniTensor, see cytnx::Type for more information.
[in]devicethe device type of the UniTensor, see cytnx::Device for more information.
[in]namethe name of the UniTensor.
Returns
[UniTensor]
See also
zeros(const std::vector< cytnx_uint64 > &Nelem, const unsigned int &dtype, const int &device)

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