Cytnx v1.0.0
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 from a 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.
 
UniTensorInit (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 a UniTensor, in-place.
 
UniTensorset_name (const std::string &in)
 
UniTensorset_label_ (const cytnx_int64 &idx, const std::string &new_label)
 Set a new label for bond at the assigned index, in-place.
 
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, in-place.
 
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_label (const cytnx_int64 &idx, const std::string &new_label)
 
UniTensorset_label (const cytnx_int64 &idx, const char *new_label)
 
UniTensorset_label (const std::string &old_label, const std::string &new_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)
 
UniTensorset_labels (const std::initializer_list< char * > &new_labels)
 
UniTensorset_rowrank_ (const cytnx_uint64 &new_rowrank)
 Set the rowrank 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.
 
bool is_void () const
 Return whether the UniTensor is uninitialized.
 
bool is_scalar () const
 whether the UniTensor is an initialized rank-0 scalar UniTensor
 
cytnx_uint64 size () const
 Return the total number of logical elements in the UniTensor.
 
bool is_empty () const
 whether the UniTensor is initialized and has no logical elements
 
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.
 
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.
 
std::vector< boolsignflip () const
 Get the sign information of a fermionic UniTensor.
 
bool is_blockform () const
 Check whether the UniTensor is in block form.
 
UniTensorto_ (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.
 
UniTensorrelabel_ (const std::vector< std::string > &new_labels)
 Set new labels for all the bonds.
 
UniTensorrelabels_ (const std::vector< std::string > &new_labels)
 
UniTensor relabel (const std::vector< std::string > &new_labels) const
 relabel all of the labels in UniTensor.
 
UniTensor relabels (const std::vector< std::string > &new_labels) const
 
UniTensor relabel (const std::initializer_list< char * > &new_labels) const
 relables all of the labels in UniTensor.
 
UniTensor relabels (const std::initializer_list< char * > &new_labels) const
 
UniTensorrelabel_ (const std::initializer_list< char * > &new_labels)
 
UniTensorrelabels_ (const std::initializer_list< char * > &new_labels)
 
UniTensor relabel (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.
 
UniTensor relabels (const std::vector< std::string > &old_labels, const std::vector< std::string > &new_labels) const
 
UniTensorrelabel_ (const std::vector< std::string > &old_labels, const std::vector< std::string > &new_labels)
 relabel part or all of the labels in UniTensor by given new labels
 
UniTensorrelabels_ (const std::vector< std::string > &old_labels, const std::vector< std::string > &new_labels)
 
UniTensor relabel (const std::initializer_list< char * > &old_labels, const std::initializer_list< char * > &new_labels) const
 
UniTensor relabels (const std::initializer_list< char * > &old_labels, const std::initializer_list< char * > &new_labels) const
 
UniTensorrelabel_ (const std::initializer_list< char * > &old_labels, const std::initializer_list< char * > &new_labels)
 
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
 rebabel the legs in the UniTensor by given index.
 
UniTensorrelabel_ (const cytnx_int64 &inx, const std::string &new_label)
 rebable the legs in the UniTensor by given index.
 
UniTensorrelabel_ (const std::string &old_label, const std::string &new_label)
 relabel the legs in the UniTensor by a given label.
 
UniTensor relabel (const std::string &old_label, const std::string &new_label) const
 relabel the legs in the UniTensor by a given label.
 
UniTensor astype (const unsigned int &dtype) const
 Return a new UniTensor whose elements are casted to a different data type.
 
UniTensor permute (const std::vector< cytnx_int64 > &mapper, const cytnx_int64 &rowrank=-1) const
 permute the legs of the UniTensor
 
UniTensor permute (const std::vector< std::string > &mapper, const cytnx_int64 &rowrank=-1) const
 permute the legs of the UniTensor by labels
 
UniTensor permute (const std::initializer_list< char * > &mapper, const cytnx_int64 &rowrank=-1) const
 
UniTensorpermute_ (const std::vector< cytnx_int64 > &mapper, const cytnx_int64 &rowrank=-1)
 permute the legs of the UniTensor, inplacely.
 
UniTensorpermute_ (const std::vector< std::string > &mapper, const cytnx_int64 &rowrank=-1)
 permute the legs of the UniTensor, inplacely.
 
UniTensor permute_nosignflip (const std::vector< cytnx_int64 > &mapper, const cytnx_int64 &rowrank=-1) const
 permute the legs of the UniTensor without sign flips
 
UniTensor permute_nosignflip (const std::vector< std::string > &mapper, const cytnx_int64 &rowrank=-1) const
 permute the legs of the UniTensor by labels without sign flips
 
UniTensor permute_nosignflip (const std::initializer_list< char * > &mapper, const cytnx_int64 &rowrank=-1) const
 
UniTensorpermute_nosignflip_ (const std::vector< cytnx_int64 > &mapper, const cytnx_int64 &rowrank=-1)
 permute the legs of the UniTensor without fermionic sign flips, inplacely.
 
UniTensorpermute_nosignflip_ (const std::vector< std::string > &mapper, const cytnx_int64 &rowrank=-1)
 permute the legs of the UniTensor without fermionic sign flips, inplacely.
 
UniTensor twist (const std::string &label) const
 Apply a twist (or braids/self-swap) operation to a given bond; No effect for bosonic tensors; for a fermionic tensor, this means that a signflip occurs for all blocks where the bond has odd fermion parity.
 
UniTensor twist (const cytnx_int64 &idx) const
 Apply a twist (or braids/self-swap) operation to a given bond; No effect for bosonic tensors; for a fermionic tensor, this means that a signflip occurs for all blocks where the bond has odd fermion parity.
 
UniTensortwist_ (const std::string &label)
 Inline version.
 
UniTensortwist_ (const cytnx_int64 &idx)
 Inline version.
 
UniTensor fermion_twists () const
 Apply twists to all right bonds (>= rowrank) with bond type BD_KET.
 
UniTensorfermion_twists_ ()
 Inline version.
 
UniTensor contiguous () const
 Make the UniTensor contiguous by coalescing the memory (storage).
 
UniTensorcontiguous_ ()
 Make the UniTensor contiguous by coalescing the memory (storage), inplacely.
 
UniTensor apply () const
 Apply fermionic signflips to the UniTensor, such that all elements calling signflip() on the output tensor will result in all elements to be false.
 
UniTensorapply_ ()
 Apply fermionic signflips to the UniTensor, inplacely. Subsequently, all elements returned by signflip() are false.
 
void print_diagram (const bool &bond_info=false) const
 Plot the diagram of the UniTensor.
 
void print_blocks (const bool &full_info=true) const
 Print all blocks of the UniTensor.
 
void print_block (const cytnx_int64 &idx, const bool &full_info=true) const
 Print out the block of the UniTensor with a given block index number.
 
UniTensorgroup_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 a specific location.
 
template<class T >
const Tat (const std::vector< cytnx_uint64 > &locator) const
 Get an element at a 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 a specific location.
 
Scalar::Sproxy at (const std::vector< cytnx_uint64 > &locator)
 Get an element at a 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 block 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 the block for the given block 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 the 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 the 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)
 
UniTensorput_block (const Tensor &in, const cytnx_uint64 &idx=0)
 Put the block into the UniTensor with given index.
 
UniTensorput_block (const Tensor &in, const cytnx_uint64 &idx, const bool &force)
 
UniTensorput_block (const Tensor &in_tens, const std::vector< cytnx_int64 > &qidx)
 Put the block into the UniTensor with given quantum number.
 
UniTensorput_block (const Tensor &in_tens, const std::vector< cytnx_int64 > &qidx, const bool &force)
 
UniTensorput_block (Tensor &in, const std::vector< std::string > &lbls, const std::vector< cytnx_int64 > &qidx)
 Put the block into the UniTensor with given quantum indices, will copy the input tensor.
 
UniTensorput_block (Tensor &in, const std::vector< std::string > &lbls, const std::vector< cytnx_int64 > &qidx, const bool &force)
 
UniTensorput_block_ (Tensor &in, const cytnx_uint64 &idx=0)
 Put the block into the UniTensor with given index, inplacely.
 
UniTensorput_block_ (Tensor &in, const std::vector< cytnx_int64 > &qidx)
 Put the block into the UniTensor with given quantum indices, inplacely.
 
UniTensorput_block_ (Tensor &in, const std::vector< cytnx_int64 > &qidx, const bool &force)
 
UniTensorput_block_ (Tensor &in, const std::vector< std::string > &lbls, const std::vector< cytnx_int64 > &qidx)
 Put the block into the UniTensor with given quantum indices, inplacely.
 
UniTensorput_block_ (Tensor &in, const std::vector< std::string > &lbls, const std::vector< cytnx_int64 > &qidx, const bool &force)
 
UniTensor get (const std::vector< Accessor > &accessors) const
 get elements using Accessor (C++ API) / slices (python API)
 
UniTensor operator[] (const std::vector< cytnx::Accessor > &accessors) const
 get elements using Accessor (C++ API) / slices (python API)
 
UniTensor operator[] (const std::initializer_list< cytnx::Accessor > &accessors) const
 
UniTensor operator[] (const std::vector< cytnx_int64 > &accessors) const
 
UniTensor operator[] (const std::initializer_list< cytnx_int64 > &accessors) const
 
UniTensorset (const std::vector< Accessor > &accessors, const Tensor &rhs)
 set elements using Accessor (C++ API) / slices (python API)
 
UniTensorset (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.
 
UniTensorreshape_ (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.
 
UniTensorto_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)
 
void combineBonds (const std::vector< cytnx_int64 > &indicators, const bool &force=false)
 
UniTensorcombineBond_ (const std::vector< std::string > &indicators, const bool &force=false)
 Combine the sevral bonds of the UniTensor, in-place.
 
UniTensor combineBond (const std::vector< std::string > &indicators, const bool &force=false) const
 Combine the sevral bonds of the UniTensor, out-of-place.
 
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.
 
Scalar 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 Inv (double clip=-1.) const
 Element-wise (pseudo-)inverse.
 
UniTensorInv_ (double clip=-1.)
 Element-wise (pseudo-)inverse, inplacely.
 
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 trace of the UniTensor.
 
UniTensor Trace (const cytnx_int64 &a=0, const cytnx_int64 &b=1) const
 Take the partial trace of the UniTensor.
 
UniTensorTrace_ (const std::string &a, const std::string &b)
 Take the partial trace of the UniTensor, inplacely.
 
UniTensorTrace_ (const cytnx_int64 &a=0, const cytnx_int64 &b=1)
 Take the partial trace of 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, in-place.
 
UniTensortag ()
 
UniTensor Pow (const double &p) const
 Take the power p of all elements.
 
UniTensorPow_ (const double &p)
 Take the power p of all elements, inplacely.
 
bool elem_exists (const std::vector< cytnx_uint64 > &locator) const
 Given the locator, check if the element exists.
 
template<class T >
T get_elem (const std::vector< cytnx_uint64 > &locator) const
 
template<class T2 >
UniTensorset_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, bool force=false, cytnx_double tol=0.)
 Copy data from a UniTensor of different type, in-place.
 
UniTensorconvert_from (const UniTensor &rhs, bool force=false, cytnx_double tol=0.)
 
UniTensornormal_ (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.
 
UniTensoruniform_ (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 std::vector< cytnx_uint64 > &shape, const std::vector< std::string > &in_labels={}, unsigned int dtype=Type.Double, int device=Device.cpu, const std::string &name="")
 Generate a UniTensor with all elements set to zero.
 
static UniTensor zeros (std::initializer_list< cytnx_uint64 > shape, const std::vector< std::string > &in_labels={}, unsigned int dtype=Type.Double, int device=Device.cpu, const std::string &name="")
 
static UniTensor identity (cytnx_uint64 dim, const std::vector< std::string > &in_labels={}, cytnx_bool is_diag=false, unsigned int dtype=Type.Double, int device=Device.cpu, const std::string &name="")
 Generate an identity UniTensor with two bonds.
 
static UniTensor eye (cytnx_uint64 dim, const std::vector< std::string > &in_labels={}, cytnx_bool is_diag=false, unsigned int dtype=Type.Double, 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={}, unsigned int dtype=Type.Double, int device=Device.cpu, const std::string &name="")
 Generate a UniTensor with all elements set to one.
 
static UniTensor ones (std::initializer_list< cytnx_uint64 > shape, const std::vector< std::string > &in_labels={}, unsigned int dtype=Type.Double, int device=Device.cpu, const std::string &name="")
 
static UniTensor arange (cytnx_int64 Nelem, const std::vector< std::string > &in_labels={}, const std::string &name="")
 Create a rank-1 UniTensor with incremental unsigned integer elements in the range [0,Nelem).
 
static UniTensor arange (cytnx_double start, cytnx_double end, cytnx_double step=1, const std::vector< std::string > &in_labels={}, unsigned int dtype=Type.Double, int device=Device.cpu, const std::string &name="")
 Create a rank-1 UniTensor with incremental elements in the range [start,end) with given step-size step between elements.
 
static UniTensor linspace (cytnx_double start, cytnx_double end, cytnx_uint64 Nelem, bool endpoint=true, const std::vector< std::string > &in_labels={}, unsigned int dtype=Type.Double, 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 requires the input in_tensor to be 1D.
[in]rowrankthe rowrank of the resulting UniTensor
Note
  1. The constructed UniTensor will have the 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 the UniTensor is a referece to the input Tensor. That is, they share the same memory. If the elements of the UniTensor are changed, the original Tensor is also changed and vice-versa. Use Tensor.clone() if a shared view is not desired.

Example:

C++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
int main(int argc, char* argv[]) {
Tensor T = zeros({4, 4});
UniTensor CyT = UniTensor(T, false, 2); // create un-tagged CyTensor from Tensor
CyT.print_diagram();
std::cout << "before:" << std::endl;
std::cout << T << std::endl;
std::cout << CyT << std::endl;
// Note that it is a shared view, so a change to CyT will affect Tensor T.
CyT.at<cytnx_double>({0, 0}) = 1.456;
std::cout << "after:" << std::endl;
std::cout << T << std::endl;
std::cout << CyT << std::endl;
// If we want a new instance of memery, use clone at initialize:
std::cout << "[non-share example]" << std::endl;
UniTensor CyT_nonshare = UniTensor(T.clone(), false, 2);
std::cout << "before:" << std::endl;
std::cout << T << std::endl;
std::cout << CyT_nonshare << std::endl;
CyT_nonshare.at<cytnx_double>({1, 1}) = 2.345;
std::cout << "after" << std::endl;
std::cout << T << std::endl; // T is unchanged!
std::cout << CyT_nonshare << std::endl;
return 0;
}
an tensor (multi-dimensional array)
Definition Tensor.hpp:41
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:2775
static UniTensor zeros(const std::vector< cytnx_uint64 > &shape, const std::vector< std::string > &in_labels={}, unsigned int dtype=Type.Double, int device=Device.cpu, const std::string &name="")
Generate a UniTensor with all elements set to zero.
Definition UniTensor.hpp:5908
int device() const
Return the device of the UniTensor.
Definition UniTensor.hpp:3265
Definition Accessor.hpp:12

output>

-----------------------
tensor Name :
tensor Rank : 2
block_form  : false
is_diag     : False
on device   : cytnx device: CPU
            -------------
           /             \
     0 ____| 4           |
           |             |
     1 ____| 4           |
           \             /
            -------------
before:

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]


-------- start of print ---------
Tensor name:
Tensor name:
is_diag    : False
contiguous : True

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]



after:

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]


-------- start of print ---------
Tensor name:
Tensor name:
is_diag    : False
contiguous : True

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]



[non-share example]
before:

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]


-------- start of print ---------
Tensor name:
Tensor name:
is_diag    : False
contiguous : True

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]



after

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]


-------- start of print ---------
Tensor name:
Tensor name:
is_diag    : False
contiguous : True

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 2.34500e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]

Python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
T = zeros([4,4])
CyT = UniTensor(T).set_rowrank_(2) #create un-tagged UniTensor from Tensor
CyT.print_diagram()
print("before:")
print(T)
print(CyT)
#Note that it is a shared view, so a change to CyT will affect Tensor T.
CyT.set_elem([0,0],1.456)
print("after")
print(T)
print(CyT)
#If we want a new instance of memery, use clone at initialize:
print("[non-share example]")
CyT_nonshare = UniTensor(T.clone()).set_rowrank_(2)
print("before:")
print(T)
print(CyT_nonshare)
CyT_nonshare.set_elem([1,1],2.345)
print("after")
print(T) # T is unchanged!
print(CyT_nonshare)

output>

-----------------------
tensor Name :
tensor Rank : 2
block_form  : false
is_diag     : False
on device   : cytnx device: CPU
          --------
         /        \
   0 ____| 4      |
         |        |
   1 ____| 4      |
         \        /
          --------
before:

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]



-------- start of print ---------
Tensor name:
Tensor name:
is_diag    : False
contiguous : True

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]




after

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]



-------- start of print ---------
Tensor name:
Tensor name:
is_diag    : False
contiguous : True

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]




[non-share example]
before:

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]



-------- start of print ---------
Tensor name:
Tensor name:
is_diag    : False
contiguous : True

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]




after

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]



-------- start of print ---------
Tensor name:
Tensor name:
is_diag    : False
contiguous : True

Total elem: 16
type  : Double (Float64)
cytnx device: CPU
Shape : (4,4)
[[1.45600e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 2.34500e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]
 [0.00000e+00 0.00000e+00 0.00000e+00 0.00000e+00 ]]

◆ 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
Compared 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
Compared to Add_(const UniTensor&), this function will create a new UniTensor.
internal/advanced: not a TN operation; python surface removed per #934; see operator+(const UniTensor&, const UniTensor&) in include/linalg.hpp for the full rationale.
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
Compared 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
Compared to Add(const UniTensor&)const, this is an inplace function.
internal/advanced: not a TN operation; python surface removed per #934; see operator+(const UniTensor&, const UniTensor&) in include/linalg.hpp for the full rationale.
See also
Add_(const Scalar&), Add(const UniTensor&)const, Add(const Scalar&)const , operator+=(const UniTensor&), operator+=(const Scalar&), operator+

◆ apply()

UniTensor cytnx::UniTensor::apply ( ) const
inline

Apply fermionic signflips to the UniTensor, such that all elements calling signflip() on the output tensor will result in all elements to be false.

Warning
Blocks that need to be flipped are copied and inverted. Blocks where no signflip has to be applied remain. Therefore, these correspond to a shared view and changing these blocks on the output tensor will affect the elements of the input tensor as well.
See also
apply_()

◆ apply_()

UniTensor & cytnx::UniTensor::apply_ ( )
inline

Apply fermionic signflips to the UniTensor, inplacely. Subsequently, all elements returned by signflip() are false.

See also
apply()

◆ arange() [1/2]

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

Create a rank-1 UniTensor with incremental elements in the range [start,end) with given step-size step between elements.

The elements are start, start + step, start + 2 * step, ... The last element is the largest one that is smaller than end.

Parameters
[in]startstart value of the range.
[in]endend value of the range (exclusive).
[in]stepstep-size between subsequent elements in the range.
[in]in_labelsthe label 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 ( cytnx_int64  Nelem,
const std::vector< std::string > &  in_labels = {},
const std::string &  name = "" 
)
inlinestatic

Create a rank-1 UniTensor with incremental unsigned integer elements in the range [0,Nelem).

The elements are 0, 1, 2, ..., Nelem - 1.

Parameters
[in]Nelemnumber of incremental elements.
[in]in_labelsthe label 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 std::vector<std::string> &in_labels, const unsigned int &dtype, const int &device, const std::string &name)
arange(const cytnx_int64 &Nelem)

◆ astype()

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

Return a new UniTensor whose elements are casted to a 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 a specific location.

Parameters
[in]locatorthe location of the element we want to access.
Note
this API is only for C++.
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ at() [2/8]

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

Get an element at a specific location.

see more information at user guide 6.3.5.

Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ at() [3/8]

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

Get an element at a specific location.

Parameters
[in]locatorthe location of the element we want to access.
Note
this API is only for C++.
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ at() [4/8]

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

Get an element at a specific location.

see more information at user guide 6.3.5.

Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ 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()

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

◆ combineBond()

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

Combine the sevral bonds of the UniTensor, out-of-place.

Parameters
[in]indicatorsthe labels of the legs 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.)
Returns
UniTensor a new UniTensor with the bonds combined; this UniTensor is unchanged.
See also
combineBond_(const std::vector<std::string> &indicators, const bool &force)

◆ combineBond_()

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

Combine the sevral bonds of the UniTensor, in-place.

Parameters
[in]indicatorsthe labels of the legs 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.)
Returns
UniTensor& (self)
See also
combineBond(const std::vector<std::string> &indicators, const bool &force) const

◆ 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

◆ 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
Compared to Conj_(), this function 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
Compared to Conj(), this function is an inplace function.
See also
Conj()

◆ contiguous()

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

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

See also
contiguous_()
Warning
If the input tensor is not contiguous, then the data will be stored in new memory; otherwise, the input tensor is returned and no cloning of the data happens.

◆ contiguous_()

UniTensor & 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 legs 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,
bool  force = false,
cytnx_double  tol = 0. 
)
inline
Deprecated:
This function is deprecated. Please use
convert_from_(const UniTensor &rhs, bool force, cytnx_double tol)
instead.

◆ convert_from_()

UniTensor & cytnx::UniTensor::convert_from_ ( const UniTensor rhs,
bool  force = false,
cytnx_double  tol = 0. 
)
inline

Copy data from a UniTensor of different type, in-place.

For example, if uTB is a BlockUniTensor and uTD is a DenseUniTensor of the same shape, then uTD.convert_from_(uTB) makes uTD a sparse copy of uTB.

Parameters
[in]rhsthe UniTensor to copy from
[in]forceif true, the compatibility of the input and output tensor structure is not checked strictly; elements that do not exist in the output tensor are ignored in the input tensor, even if they are not zero or small.
[in]tolapplies if a denser UniTensor is converted to a sparser tensor structure; if an element in the output tensor does not exist, the absolute value of the element in the input tensor has to be <= tol. Otherwise an error is thrown. This is overwritten by force = true.
Returns
[UniTensor] a reference to this UniTensor

◆ Dagger()

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

Take the conjugate transpose to the UniTensor.

Returns
UniTensor
Note
This function inverts the order of all indices.
Compared to Dagger_(), this function will create a new UniTensor object.
For fermionic UniTensors, the index order is reversed without sign flips.
See also
Dagger_(), Transpose()

◆ Dagger_()

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

Take the conjugate transpose to the UniTensor, inplacely.

Returns
UniTensor&
Note
This function inverts the order of all indices.
Compared to Dagger(), this is an inplace function.
For fermionic UniTensors, the index order is reversed without sign flips.
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
Compared 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
Compared to Div_(const UniTensor&), this function will create a new UniTensor.
internal/advanced: not a TN operation; python surface removed per #934; see operator+(const UniTensor&, const UniTensor&) in include/linalg.hpp for the full rationale.
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
Compared 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
Compared to Div(const UniTensor&)const, this is an inplace function.
internal/advanced: not a TN operation; python surface removed per #934; see operator+(const UniTensor&, const UniTensor&) in include/linalg.hpp for the full rationale.
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

Given 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 ( cytnx_uint64  dim,
const std::vector< std::string > &  in_labels = {},
cytnx_bool  is_diag = false,
unsigned int  dtype = Type.Double,
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 two 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
The resulting UniTensor has two bonds. The data is one-dimensional (two-dimensional) if is_diag is true (false).
See also
cytnx::UniTensor::identity
Note
This function is a alias of cytnx::UniTensor::identity().

◆ fermion_twists()

UniTensor cytnx::UniTensor::fermion_twists ( ) const
inline

Apply twists to all right bonds (>= rowrank) with bond type BD_KET.

For bosonic tensors, nothing changes. For fermions, this makes sure that bra- and ket-states can be contracted correctly. For example, a scalar product <A|B> between ket states A and B represented by fermionic tensors with incoming and outgoing legs, can be calculated correctly by contract(Adag.fermion_twists_(), B). This example asumes that Adag is the dagger of A and has rowrank=0, while B has maximal rowrank. Applying fermion_twists_ to B would have no effect in this case and is thus safe to do. Similarly, this can be applied to linear operators. If M is an operator, then its first rowrank indices correspond to ket bonds and are not affected by fermion_twists_. For the remaining bonds, a twist is applied if they are not of type BD_BRA. The combination of this method to bra states, ket states and linear operators in a Hilbert space, together with contractions, ensures that scalar products can be executed as desired.

Warning
The rowrank must be set correctly before applying this method.

◆ fermion_twists_()

UniTensor & cytnx::UniTensor::fermion_twists_ ( )
inline

Inline version.

See also
fermion_twists()
Warning
The rowrank must be set correctly before applying this method.

◆ get()

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

get elements using Accessor (C++ API) / slices (python API)

Parameters
[in]accessorsthe Accessor (C++ API) / slices (python API) to get the elements.
Returns
[UniTensor]
See also
Tensor::get, UniTensor::operator[]
Note
  1. The return will be a new UniTensor instance, which does not share memory with the current UniTensor.
  2. Equivalently, one can also use the [] operator to access elements.
  3. For diagonal UniTensors, the accessor list can have either one element (to address the diagonal elements), or two elements (in this case, the output will be a non-diagonal UniTensor).

◆ 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 block index.

Parameters
[in]idxthe index of the block we want to get
Returns
Tensor
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ 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
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ 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 the block for the given block index.

Parameters
[in]idxinput the index you want to get the corresponding block
Returns
const Tensor&
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ 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 the 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&
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ 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 the 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.
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ 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>
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ 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.
Warning
For fermions, the signflip is not included and has to be multiplied by the user! The reason behind this is that several UniTensors in different permutations can share the same memory. Use signflip() to get the sign structure for each block.

◆ 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_()

UniTensor & 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 ( cytnx_uint64  dim,
const std::vector< std::string > &  in_labels = {},
cytnx_bool  is_diag = false,
unsigned int  dtype = Type.Double,
int  device = Device.cpu,
const std::string &  name = "" 
)
inlinestatic

Generate an identity UniTensor with two bonds.

Parameters
[in]dimthe dimension of the diagnal.
[in]in_labelsthe two 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
The resulting UniTensor has two bonds. The data is one-dimensional (two-dimensional) if is_diag is true (false).

◆ Init() [1/2]

UniTensor & 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 from a cytnx::Tensor.

Parameters
[in]in_tensora cytnx::Tensor
[in]is_diagwhether the input Tensor in_tensor is a diagonal Tensor. this requires the input in_tensor to be 1D.
[in]rowrankthe rowrank of the resulting UniTensor.
[in]nameuser-specified name of the UniTensor.
Note
  1. The constructed UniTensor will have the 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 the UniTensor is a referece to the input Tensor. That is, they share the same memory. If the elements of the UniTensor are changed, the original Tensor is also changed and vice-versa. Use Tensor.clone() if a shared view is not desired.
See also
UniTensor(const Tensor &, const bool &, const cytnx_int64 &)

◆ Inv()

UniTensor cytnx::UniTensor::Inv ( double  clip = -1.) const

Element-wise (pseudo-)inverse.

This function performs an element-wise inverse with clip. If \( |T_\text{in}[i]| \le \mathrm{clip} \), then the new element is set to zero.

\[ T_\text{out}[i] = \left\{ \begin{array}{ll} 1/(T_\text{in}[i]) & \mathrm{if} \ |T_\text{in}[i]| > \mathrm{clip} \\ 0 & \mathrm{otherwise} \end{array} \right. \]

Parameters
[in]clipelmements with absolute value <= clip are set to zero, corresponding to the pseudo-inverse; default: -1 (no clipping)
Returns
UniTensor
Note
  1. For complex type UniTensors, the norm \( \sqrt{Re^2 + Im^2} \) is used to determine the clip.
  2. If Tin is integer type, it will automatically be promoted to Type.Double.
  3. For symmetric UniTensors, only the elements in the blocks are inverted.
Compared to Inv_(double clip), this function does not modify the input UniTensor but returns a new UniTensor.
See also
Inv_(double clip)

◆ Inv_()

UniTensor & cytnx::UniTensor::Inv_ ( double  clip = -1.)

Element-wise (pseudo-)inverse, inplacely.

This function performs an element-wise inverse with clip. If \( |T_\text{in}[i]| \le \mathrm{clip} \), then the new element is set to zero.

\[ T_\text{in}[i] \rightarrow \left\{ \begin{array}{ll} 1/(T_\text{in}[i]) & \mathrm{if} \ |T_\text{in}[i]| > \mathrm{clip} \\ 0 & \mathrm{otherwise} \end{array} \right. \]

Parameters
[in]clipelmements with absolute value <= clip are set to zero, corresponding to the pseudo-inverse; default: -1 (no clipping)
Returns
UniTensor
Note
  1. For complex type UniTensors, the norm \( \sqrt{Re^2 + Im^2} \) is used to determine the clip.
  2. If Tin is integer type, it will automatically be promoted to Type.Double.
  3. For symmetric UniTensors, only the elements in the blocks are inverted.
Compared to UniTensor Inv(const UniTensor &Tin, double clip), this is an inplace function, which modifies the input UniTensor.
See also
Inv(double clip) const

◆ 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_empty()

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

whether the UniTensor is initialized and has no logical elements

◆ is_scalar()

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

whether the UniTensor is an initialized rank-0 scalar UniTensor

Returns
[bool] true if the UniTensor has rank 0 and is initialized

◆ 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

◆ is_void()

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

Return whether the UniTensor is uninitialized.

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 ( cytnx_double  start,
cytnx_double  end,
cytnx_uint64  Nelem,
bool  endpoint = true,
const std::vector< std::string > &  in_labels = {},
unsigned int  dtype = Type.Double,
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
Compared 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
Compared to Mul_(const UniTensor&), this function will create a new UniTensor.
internal/advanced: not a TN operation; python surface removed per #934; see operator+(const UniTensor&, const UniTensor&) in include/linalg.hpp for the full rationale.
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
Compared 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
Compared to Mul(const UniTensor&)const, this is an inplace function.
internal/advanced: not a TN operation; python surface removed per #934; see operator+(const UniTensor&, const UniTensor&) in include/linalg.hpp for the full rationale.
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
Deprecated:
Use norm() instead, which returns a Scalar directly.

◆ norm()

Scalar cytnx::UniTensor::norm ( ) const
inline

Return the norm of the UniTensor.

norm() return the 2-norm of the UniTensor \(UT\) as a Scalar carrying the UniTensor's own precision (Float for Float/ComplexFloat input, Double otherwise), so x /= x.norm() stays dtype-preserving rather than promoting a Float UniTensor to Double.

\[ ||UT||_2 \]

Returns
Scalar

◆ 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_()

UniTensor & 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
Compared to normalize_(), this function will return new UniTensor object.
See also
normalize_()

◆ normalize_()

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

normalize the UniTensor, inplacely.

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

◆ ones() [1/2]

static UniTensor cytnx::UniTensor::ones ( const std::vector< cytnx_uint64 > &  shape,
const std::vector< std::string > &  in_labels = {},
unsigned int  dtype = Type.Double,
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)

◆ ones() [2/2]

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

◆ 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

◆ operator[]() [1/4]

UniTensor cytnx::UniTensor::operator[] ( const std::initializer_list< cytnx::Accessor > &  accessors) const
inline

◆ operator[]() [2/4]

UniTensor cytnx::UniTensor::operator[] ( const std::initializer_list< cytnx_int64 > &  accessors) const
inline

◆ operator[]() [3/4]

UniTensor cytnx::UniTensor::operator[] ( const std::vector< cytnx::Accessor > &  accessors) const
inline

get elements using Accessor (C++ API) / slices (python API)

See also
get()

◆ operator[]() [4/4]

UniTensor cytnx::UniTensor::operator[] ( const std::vector< cytnx_int64 > &  accessors) const
inline

◆ 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)
Warning
It is recommended to use permute(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank) instead

◆ permute() [2/3]

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

permute the legs of the UniTensor

Parameters
[in]mapperthe mapper of the permutation by bond indices
[in]rowrankthe new rowrank after the permutation
Returns
UniTensor
Warning
It is recommended to use permute(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank) instead

◆ permute() [3/3]

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

permute the legs of the UniTensor by labels

Parameters
[in]mapperthe mapper of the permutation by labels
[in]rowrankthe row rank
Returns
UniTensor

◆ permute_() [1/2]

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

permute the legs of the UniTensor, inplacely.

Parameters
[in]mapperthe mapper of the permutation by labels
[in]rowrankthe row rank after the permutation
Warning
It is recommended to use permute_(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank) instead

◆ permute_() [2/2]

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

permute the legs of the UniTensor, inplacely.

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

◆ permute_nosignflip() [1/3]

UniTensor cytnx::UniTensor::permute_nosignflip ( const std::initializer_list< char * > &  mapper,
const cytnx_int64 rowrank = -1 
) const
inline
See also
permute_nosignflip(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank)
Warning
It is recommended to use permute_nosignflip(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank) instead

◆ permute_nosignflip() [2/3]

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

permute the legs of the UniTensor without sign flips

The indices are permuted, but no fermionic sign flips occur. Use with care! This is usually not intended, since fermionic permutations create sign flips! This should typically only be used to compare tensors in different sign conventions with each other.

Parameters
[in]mapperthe mapper of the permutation by indices
[in]rowrankthe new rowrank after the permutation
Returns
UniTensor
Warning
It is recommended to use permute_nosignflip(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank) instead
Usually, the signs should change when permuting a fermionic UniTensor. Use permute instead, unless you are really sure you want to permute without signflips!

◆ permute_nosignflip() [3/3]

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

permute the legs of the UniTensor by labels without sign flips

The indices are permuted, but no fermionic sign flips occur. Use with care! This is usually not intended, since fermionic permutations create sign flips! This should typically only be used to compare tensors in different sign conventions with each other.

Parameters
[in]mapperthe mapper of the permutation by labels
[in]rowrankthe row rank
Returns
UniTensor
Warning
Usually, the signs should change when permuting a fermionic UniTensor. Use permute_ instead, unless you are really sure you want to permute without signflips!

◆ permute_nosignflip_() [1/2]

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

permute the legs of the UniTensor without fermionic sign flips, inplacely.

The indices are permuted, but no fermionic sign flips occur. Use with care! This is usually not intended, since fermionic permutations create sign flips! This should typically only be used to compare tensors in different sign conventions with each other.

Parameters
[in]mapperthe mapper of the permutation by indices
[in]rowrankthe row rank after the permutation
Warning
It is recommended to use permute_(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank) instead
Usually, the signs should change when permuting a fermionic UniTensor. Use permute_ instead, unless you are really sure you want to permute without signflips!

◆ permute_nosignflip_() [2/2]

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

permute the legs of the UniTensor without fermionic sign flips, inplacely.

The indices are permuted, but no fermionic sign flips occur. Use with care! This is usually not intended, since fermionic permutations create sign flips! This should typically only be used to compare tensors in different sign conventions with each other.

Parameters
[in]mapperthe mapper of the permutation by labels
[in]rowrankthe row rank after the permutation
See also
permute(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank = -1)
Warning
Usually, the signs should change when permuting a fermionic UniTensor. Use permute instead, unless you are really sure you want to permute without signflips!

◆ Pow()

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

Take the power p of all elements.

\[ T_\text{out}[i] = (T_\text{in}[i])^p \]

Parameters
[in]pthe power to take
Precondition
If this is a real UniTensor containing negative elements, then p must be an integer.
Note
For symmetric UniTensors, only the elements in the blocks are inverted.
Warning
If p < 0 an inverse has to be taken. If elements could be zero (or close to it), use Inv(double clip) const for a pseudo-inverse instead.
For fermionic UniTensors, the sign structure of the blocks remains unchanged. This way, permute commutes with Pow. This can lead to unexpected behavior since T.Pow(2.0) can differ by signs from T * T.
Note
Compared UniTensor &Pow_(const double &p), this function does not modify the input UniTensor but returns a new UniTensor.
See also
UniTensor &Pow_(const double &p)

◆ Pow_()

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

Take the power p of all elements, inplacely.

\[ T_\text{in}[i] \rightarrow (T_\text{in}[i])^p \]

Parameters
[in]pthe power to take
Precondition
If this is a real UniTensor containing negative elements, then p must be an integer.
Note
For symmetric UniTensors, only the elements in the blocks are inverted.
Warning
If p < 0 an inverse has to be taken. If elements could be zero (or close to it), use Inv_(double clip) for a pseudo-inverse instead.
For fermionic UniTensors, the sign structure of the blocks remains unchanged. This way, permute commutes with Pow_. This can lead to unexpected behavior since T.Pow_(2.0) can differ by signs from T * T.
Note
Compared UniTensor Pow(const double &p) const, this is an inplace function, which modifies the input UniTensor.
See also
UniTensor &Pow(const double &p) const

◆ print_block()

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

Print out the block of the UniTensor with a given block index number.

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 blocks of 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) const
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/6]

UniTensor & cytnx::UniTensor::put_block ( const Tensor in,
const cytnx_uint64 idx,
const bool force 
)
inline
Deprecated:
This function is deprecated. Please use
put_block(const Tensor &in, const cytnx_uint64 &idx)
instead.

◆ put_block() [2/6]

UniTensor & 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.
Warning
For fermions, the signflip is not included and has to be multiplied by the user! Use signflip() to get the sign, and multiply the block by -1 if the corresponding signflip is true/ODD. The reason behind this is that several UniTensors in different permutations can share the same memory.

◆ put_block() [3/6]

UniTensor & cytnx::UniTensor::put_block ( const Tensor in_tens,
const std::vector< cytnx_int64 > &  qidx 
)
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
For fermions, the signflip is not included and has to be multiplied by the user! Use signflip() to get the sign, and multiply the block by -1 if the corresponding signflip is true/ODD. The reason behind this is that several UniTensors in different permutations can share the same memory.

◆ put_block() [4/6]

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

◆ put_block() [5/6]

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

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

Warning
For fermions, the signflip is not included and has to be multiplied by the user! Use signflip() to get the sign, and multiply the block by -1 if the corresponding signflip is true/ODD. The reason behind this is that several UniTensors in different permutations can share the same memory.

◆ put_block() [6/6]

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

◆ put_block_() [1/5]

UniTensor & 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)
Warning
For fermions, the signflip is not included and has to be multiplied by the user! Use signflip() to get the sign, and multiply the block by -1 if the corresponding signflip is true/ODD. The reason behind this is that several UniTensors in different permutations can share the same memory.

◆ put_block_() [2/5]

UniTensor & cytnx::UniTensor::put_block_ ( Tensor in,
const std::vector< cytnx_int64 > &  qidx 
)
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
For fermions, the signflip is not included and has to be multiplied by the user! Use signflip() to get the sign, and multiply the block by -1 if the corresponding signflip is true/ODD. The reason behind this is that several UniTensors in different permutations can share the same memory.

◆ put_block_() [3/5]

UniTensor & cytnx::UniTensor::put_block_ ( Tensor in,
const std::vector< cytnx_int64 > &  qidx,
const bool force 
)
inline
Deprecated:
This function is deprecated. Please use
put_block_(Tensor &in, const std::vector<cytnx_int64> &qidx)
instead.

◆ put_block_() [4/5]

UniTensor & cytnx::UniTensor::put_block_ ( Tensor in,
const std::vector< std::string > &  lbls,
const std::vector< cytnx_int64 > &  qidx 
)
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.
Warning
For fermions, the signflip is not included and has to be multiplied by the user! Use signflip() to get the sign, and multiply the block by -1 if the corresponding signflip is true/ODD. The reason behind this is that several UniTensors in different permutations can share the same memory.

◆ put_block_() [5/5]

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

◆ rank()

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

Return the rank of the UniTensor.

Returns
cytnx_uint64

◆ relabel() [1/6]

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

rebabel the legs in the UniTensor by given index.

This function will relabel the legs 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). Compared 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/6]

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

◆ relabel() [3/6]

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

◆ relabel() [4/6]

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

relabel the legs in the UniTensor by a given label.

This function will relabel the legs 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). Compared 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() [5/6]

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

relabel 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.

◆ relabel() [6/6]

UniTensor cytnx::UniTensor::relabel ( 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.

◆ relabel_() [1/6]

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

rebable the legs in the UniTensor by given index.

This function will relabel the legs 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/6]

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

◆ relabel_() [3/6]

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

◆ relabel_() [4/6]

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

relabel the legs in the UniTensor by a given label.

This function will relabel the legs 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)

◆ relabel_() [5/6]

UniTensor & cytnx::UniTensor::relabel_ ( 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. Compared to relabel(const std::vector<std::string> &new_labels) const, this function set the new label to itself.

◆ relabel_() [6/6]

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

relabel 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. Compared to relabel(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
relabel(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.

◆ 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
Deprecated:
This function is deprecated. Please use
UniTensor relabel(const std::vector<std::string> &new_labels) const
instead.

◆ relabels() [4/4]

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

◆ relabels_() [1/4]

UniTensor & cytnx::UniTensor::relabels_ ( const std::initializer_list< char * > &  new_labels)
inline
Deprecated:
This function is deprecated. Please use
UniTensor &relabel_(const std::initializer_list<char *> &new_labels)
instead.

◆ 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
Deprecated:
This function is deprecated. Please use
UniTensor &relabel_(const std::vector<std::string> &new_labels)
instead.

◆ relabels_() [4/4]

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

◆ 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_()

UniTensor & 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]

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

set elements using Accessor (C++ API) / slices (python API)

Parameters
[in]accessorsthe Accessor (C++ API) / slices (python API) to set the elements.
[in]rhsthe tensor containing the values to set.
Returns
[UniTensor]
See also
Tensor::set, UniTensor::operator[], UniTensor::get
Note
  1. The return will be a new UniTensor instance, which does not share memory with the current UniTensor.
  2. Equivalently, one can also use the [] operator to access elements.
  3. For diagonal UniTensors, the accessor list can have either one element (to address the diagonal elements; rhs must be one-dimensional), or two elements (in this case, the output will be a non-diagonal UniTensor; rhs must be two-dimensional).

◆ set() [2/2]

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

◆ set_elem()

template<class T2 >
UniTensor & 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_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_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, in-place.

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. Compared 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, in-place.

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. Compared 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
Deprecated:
This function is deprecated. Please use
UniTensor &relabel_(const std::initializer_list<char *> &new_labels)
instead.

◆ set_labels() [2/2]

UniTensor & cytnx::UniTensor::set_labels ( const std::vector< std::string > &  new_labels)
inline
Deprecated:
This function is deprecated. Please use
UniTensor &relabel_(const std::vector<std::string> &new_labels)
instead.

◆ set_name()

UniTensor & cytnx::UniTensor::set_name ( const std::string &  in)
inline
Deprecated:
This function is deprecated. Please use set_name_(const std::string &in) instead.

◆ set_name_()

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

Set the name of a UniTensor, in-place.

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& (self)

◆ 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 rowrank 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>

◆ signflip()

std::vector< bool > cytnx::UniTensor::signflip ( ) const
inline

Get the sign information of a fermionic UniTensor.

Length is the number of blocks in the UniTensor. If the return is true, the sign of the elements of the corresponding block needs to be flipped.

Returns
std::vector<bool>

◆ size()

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

Return the total number of logical elements in the UniTensor.

For block UniTensors this is the dense size implied by the bond dimensions, not the number of physically stored block coefficients.

Returns
[cytnx_uint64] 1 for a rank-0 scalar, 0 for a void UniTensor or any zero extent.

◆ 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
Compared 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
Compared to Sub_(const UniTensor&), this function will create a new UniTensor.
internal/advanced: not a TN operation; python surface removed per #934; see operator+(const UniTensor&, const UniTensor&) in include/linalg.hpp for the full rationale.
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
Compared 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
Compared to Sub(const UniTensor&)const, this is an inplace function.
internal/advanced: not a TN operation; python surface removed per #934; see operator+(const UniTensor&, const UniTensor&) in include/linalg.hpp for the full rationale.
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
Deprecated:
This function is deprecated. Please use tag_() instead.

◆ tag_()

UniTensor & cytnx::UniTensor::tag_ ( )
inline

Set the UniTensor as a tagged UniTensor, in-place.

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_()

UniTensor & 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.

Converts a UniTensor with is_diag = true to one with is_diag = false by expanding each block into a (diagonal) matrix.

Note
If the input tensor is already non-diagonal (is_diag = false), the input is returned. So every manipulation on the returned tensor will change the input tensor. Call clone() on the result if an independent copy is required.
Returns
UniTensor
See also
to_dense_(), is_diag()

◆ to_dense_()

UniTensor & 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 trace of the UniTensor.

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

Parameters
[in]alabel 1
[in]blabel 2
Returns
UniTensor
Note
Compared to Trace_(), this function 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 trace of the UniTensor.

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

Parameters
[in]alabel 1
[in]blabel 2
Returns
UniTensor
Note
Compared to Trace_(), this function 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 trace of 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
Compared 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 trace of 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
Compared 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 takes the transpose of a UniTensor: 1) The order of the indices is inverted. 2) Incoming legs become outgoing ones, and vice versa. 3) The rowrank is set to rank - old rowrank, such that left indices become right indices and vice versa.

Returns
UniTensor
Note
This function does not only exchange left- and right indices, but inverts the order of all indices.
Compared to Transpose_(), this function will return new UniTensor object.
See also
Transpose_()

◆ Transpose_()

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

Take the transpose of the UniTensor, inplacely.

Returns
UniTensor
Note
This function inverts the order of all indices.
Compared to Transpose(), this function is an 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
Compared 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
Compared 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
Compared 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
Compared to truncate(const std::string &bond_idx, const cytnx_uint64 &dim), this is inplace function and will modify the current UniTensor object.

◆ twist() [1/2]

UniTensor cytnx::UniTensor::twist ( const cytnx_int64 idx) const
inline

Apply a twist (or braids/self-swap) operation to a given bond; No effect for bosonic tensors; for a fermionic tensor, this means that a signflip occurs for all blocks where the bond has odd fermion parity.

Parameters
[in]idxbond index on which the twist shall be applied
Note
This always applies the twist to the bond, ignoring its direction or whether they are incoming or outgoing bonds.

◆ twist() [2/2]

UniTensor cytnx::UniTensor::twist ( const std::string &  label) const
inline

Apply a twist (or braids/self-swap) operation to a given bond; No effect for bosonic tensors; for a fermionic tensor, this means that a signflip occurs for all blocks where the bond has odd fermion parity.

Parameters
[in]labelbond label on which the twist shall be applied
Note
This always applies the twist to the bond, ignoring its direction or whether they are incoming or outgoing bonds.

◆ twist_() [1/2]

UniTensor & cytnx::UniTensor::twist_ ( const cytnx_int64 idx)
inline

Inline version.

Parameters
[in]idxbond index on which the twist shall be applied
See also
twist(const cytnx_int64 &idx)

◆ twist_() [2/2]

UniTensor & cytnx::UniTensor::twist_ ( const std::string &  label)
inline

Inline version.

Parameters
[in]labelbond label on which the twist shall be applied
See also
twist(const std::string &label)

◆ 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_()

UniTensor & 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 std::vector< cytnx_uint64 > &  shape,
const std::vector< std::string > &  in_labels = {},
unsigned int  dtype = Type.Double,
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)

◆ zeros() [2/2]

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

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