SyTen
syten::STensorImpl Namespace Reference

Contains all ‘smart’ tensor related classes and functions. More...

Namespaces

namespace  Autodiff
 Contains classes and functions to deal with autodifferentiation of STensor objects.
 

Classes

class  SBasis
 A smart basis class. More...
 
struct  SBasisId
 Identifier for a unique basis including its prime level. More...
 
class  STensor
 Implementation for syten::STensor. More...
 
class  STensorProxy
 The STensorProxy class is essentially a constant reference to another, pre-existing tensor. More...
 

Typedefs

template<Rank... Ranks>
using STensorStorage = std::variant< Tensor< Ranks >... >
 Internal storage type for the variant of the STensor. More...
 

Functions

STensor add_dummy_leg (STensor const &in, SBasis vacuum)
 Inserts an additional leg with basis vacuum into the tensor. More...
 
STensor apply_parities (STensor in, ConstSpan< Bool > parities)
 Applies parity operators on every tensor leg. More...
 
SBasisId applyCombinator (STensor &in, SBasisId which)
 Applies a combinator to the requested leg and returns the new SBasis. More...
 
SRDef avgAbs (STensor const &in)
 Forward overload. More...
 
STensor BSolution (STensor const &I, std::array< SBasisId, 2 > const &order, SDef const t)
 
STensor change_fermionic_order (STensor in, ConstSpan< Index > to_this)
 Changes the fermionic order of the tensor to the specified ordering. More...
 
SBasis combine_bases (SBasis const &a, SBasis const &b)
 Returns a combined basis constructed from bases a and b as it occurs during a subspace expansion, something akin to a + b. More...
 
std::tuple< STensor, std::array< SBasis, 2 > > commutator (STensorProxy A, STensorProxy B, ConstSpan< SBasis > const &AIds, ConstSpan< SBasis > const &BIds)
 Calculates the commutation of tensors A and B with respect to the requested legs, i.e. More...
 
STensorProxy conj (STensor const &in, EliminateZeros const elimzeros=EliminateZeros::No, SourceLocation const &loc=SourceLocation::current())
 Creates a proxy which knows to complex-conjugate the input tensor when requested. More...
 
STensor constructE (STensor const &I, SBasisId const &right)
 
std::tuple< Index, STensor, STensor, SBasisdelinearise (STensor const &in, SBasisId const &uncombined, std::vector< Index > leading_dimensions=std::vector< Index >(), bool relax_if_necessary=false)
 Delinarisation decomposition for STensor. More...
 
STensor demerge (STensor const &in, SBasis const &f1, SBasis const &f2, Index maxBlocksize=Maximum(), SRDef ratio=1., Index minBlocksize=1, bool ethereal=true, SourceLocation const &loc=SourceLocation::current())
 Given a tensor and two bases, constructs the merged bases of the two and then splits that basis of the tensor in back into bases f1 and f2. More...
 
DenseTensor< 2 > dense (STensor t)
 Converts rank 2 STensor into rank 2 DenseTensor. More...
 
std::vector< SDefdense (STensor t, bool const)
 Converts and returns as data inside as row-major vector. More...
 
std::tuple< STensor, STensor, SBasisdeparallelise (STensor const &in, SBasisId const &uncombined)
 Deparallelisation decomposition for STensor. More...
 
Vec< SDefdiagonal (STensor const &in, bool const order=true)
 Returns the diagonal entries of the rank-2 input tensor. More...
 
void diagonal_signs_to_largest (STensor &in)
 Finds the diagonal element with the largest amplitude and sets every element whose real part does not have the same sign as this element to zero. More...
 
std::tuple< STensor, STensor, SBasisIdeigen_sym (STensor in, SBasisId basis_to_keep, SourceLocation const &loc=SourceLocation::current())
 Given a rank-2 tensor X with two bases a and b, this function when called as eigen_sym(X, [a|b]) returns a tuple U,D,c such that U * D * conj(project(U, [a|b], [b|a]).unprime(c)) is equal to X. More...
 
STensor exp (STensor in, SBasisId const &rightLeg, SDef scalar=1., bool const exact=true, bool const b=false)
 Overload which also needs to know the right leg (i.e the one first applied to the state) of the matrix, because this information is needed for the AD. More...
 
STensor exp (STensor in, SDef scalar=1.)
 Takes the exponential of a hermitian rank-2 tensor multiplied by a scalar prefactor by direct exponentiation after mapping it to matrix form (outgoing leg first, incoming leg second in fermionic order). More...
 
std::tuple< STensor, SBasisexpand (STensor const &a, STensor const &b)
 Constructs an expanded tensor in which a is placed first and b is placed second. More...
 
std::tuple< STensor, Vec< SBasis > > expand (STensor const &a, STensor const &b, ConstSpan< Pair< SBasis, SBasis > > expandees)
 Constructs an expanded tensor in which a is placed first and b is placed second. More...
 
STensor ferm_trace (STensor const &in)
 Computes the fermionic trace of the given tensor, i.e. More...
 
SBasis filterBasis (SBasis const &input, Basis const &site, Basis const &target, Index const remainingSites)
 Filters SBasis object w.r.t. More...
 
std::tuple< STensor, SBasisIdflip_in_product (STensor const &in, SBasisId const &which)
 Flips the direction of basis which using insertIOSplitHalf. More...
 
std::tuple< STensor, SBasisIdflip_on_tensor (STensor const &in, SBasisId const &which)
 Flips the direction of basis which using insertIOFullHalf. More...
 
std::tuple< STensor, SBasisgen_comb (SBasis b1)
 Return a Combinator and the generated adjointed basis. More...
 
std::tuple< STensor, SBasisgen_combinator (SBasis const &b1)
 Returns a combinator/new basis tuple based on the input basis b1. More...
 
std::tuple< STensor, SBasisgen_ii (SBasis b1)
 Returns an input/input node and the generated adjointed basis. More...
 
std::tuple< STensor, SBasisgen_io (SBasis const &b1)
 Returns an input/output node tensor and the second, generated basis. More...
 
STensor gen_io_prime (SBasis const &b1)
 Returns an input/output node tensor where the second basis is merely the prime of the first basis. More...
 
std::tuple< STensor, SBasisgen_merge (SBasis const &b1, SBasis const &b2, Index maxBlocksize=std::numeric_limits< Index >::max(), SRDef ratio=1., Index minBlocksize=1, bool ethereal=false)
 Returns a fusing or splitting half-isometry and the generated new basis. More...
 
SBasisId gen_merge_id (SBasisId const &f1, SBasisId const &f2, Index maxBlocksize=std::numeric_limits< Index >::max(), SRDef ratio=1., Index minBlocksize=1)
 Returns the SBasisId used to identify the merged bases. More...
 
std::tuple< STensor, SBasisgen_oo (SBasis b1)
 Returns an output/output node and the generated adjointed basis. More...
 
STensor hadamard (STensor const &a, STensor b)
 Takes the Hadamard product of two rank-2 tensors. More...
 
STensor hadamard_inv_diffdiff (STensor const &s, STensor x, SBasisId const &j_basis, SBasisId const &i_basis, bool minus)
 Given a diagonal square tensor s and a square tensor x, approximates \( x_i^j \left( \frac{1}{s_j - s_i} \pm \frac{1}{s_j + s_i} \right) \). More...
 
STensor herm_to_symmetrise (STensor in)
 Takes the hermitian conjugate and adapts the bases such that addition with the input tensor results in a symmetric tensor. More...
 
STensor hermitize_by_copy (STensor in, SBasisId row_id, SBasisId col_id)
 Hermitizes the input tensor by copying the elements from the upper triangular part complex-conjugated to the lower triangular part. More...
 
STensor imag (STensor in)
 Sets the real part of the input tensor to zero. More...
 
std::tuple< STensor, SBasisinsertIOFullHalf (STensor &in, SBasis const &which)
 Flips the which-th leg of the tensor. More...
 
SBasis intersection (SBasis const &a, SBasis const &b)
 Returns the intersection of two bases. More...
 
STensor invert_diagonal (STensor in)
 Inverts the diagonal entries of the rank-2 input tensor. More...
 
STensor log (STensor in)
 Takes the natural logarithm of a rank 0 STensor. More...
 
STensor log2 (STensor in)
 Takes the 2 logarithm of a rank 0 STensor. More...
 
STensor make_zero (STensor const &in)
 Creates a zero tensor of the same shape as in. More...
 
STensor make_zero (STensorProxy const &in)
 Creates a zero tensor of the same shape as in. More...
 
std::tuple< STensor, SBasismerge (STensor const &in, SBasisId const &f1, SBasisId const &f2, Index maxBlocksize=Maximum(), SRDef ratio=1., Index minBlocksize=1, bool ethereal=true, SourceLocation const &loc=SourceLocation::current())
 Merges the bases f1 and f2 of tensor in. More...
 
STensor MSeries (STensor const &I, std::array< SBasisId, 2 > const &order, SDef const t)
 
STensor multi_transpose (STensor in, ConstSpan< Index > perm)
 Creates a copy of the input tensor and transposes it according to the permutation perm. More...
 
STensor multi_transpose (STensor in, ConstSpan< SBasis > to_match_this_basis)
 Creates a copy of the input tensor and transposes it such that its computational layout matches the order given in to_match_this_basis. More...
 
STensor norm (STensor const &t, SourceLocation const &loc=SourceLocation::current())
 Returns the norm of a tensor as a rank-0 STensor. More...
 
void normalise (STensor &in)
 Normalises the supplied tensor in-place. More...
 
STensor normalised (STensor in)
 Returns the STensor normalised to one. More...
 
STensor normSqd (STensor const &t, SourceLocation const &loc=SourceLocation::current())
 Returns the squared norm of a tensor. More...
 
std::ostreamoperator<< (std::ostream &out, SBasis const &sb)
 
std::ostreamoperator<< (std::ostream &out, SBasisId const &id)
 
STensor overlap (STensor const &a, STensor const &b, SourceLocation const &loc=SourceLocation::current())
 Takes the overlap of two STensor objects. More...
 
STensorProxy parity (STensor const &, SBasisId const &, SourceLocation const &loc=SourceLocation::current())
 Apply a parity operator to an existing STensor leg, creating an STensorProxy. More...
 
STensorProxy parity (STensorProxy const &, SBasisId const &)
 Apply a parity operator to an existing STensor leg. More...
 
STensor parityEqualDirs (STensor inp)
 Applies parity to all legs with the same direction. More...
 
STensor prod (SDef const &value, STensorProxy const &tensor)
 Scales the tensor tensor by the scalar value value. More...
 
STensor prod (STensorProxy const &a, STensorProxy const &b, SourceLocation const &loc=SourceLocation::current())
 Contracts tensors a and b over all common indices. More...
 
STensor prod (STensorProxy const &tensor, SDef const &value)
 Scales the tensor tensor by the scalar value value. More...
 
template<Rank ra, Rank rb, Rank... nums>
STensor prod_impl (SourceLocation const &loc, STensorProxy const &a, STensorProxy const &b, std::index_sequence< nums... >={})
 Helper for STensor-STensor products. More...
 
template<Rank ra, Rank rb, Rank rc>
STensor prod_impl_impl (SourceLocation const &location, STensorProxy const &a, STensorProxy const &b, std::array< int, ra > const &c_a, std::array< int, rb > const &c_b, Vec< SBasis > result_basis, Vec< Index > ferm_r)
 Second helper for STensor-STensor products. More...
 
STensor project (STensor input, SBasisId const &which, SBasis const &onto, bool nowarn=false)
 Projects the which basis of tensor input onto the sectors onto. More...
 
STensor project_state (STensor input, SBasisId const &which, Sector const &sec, Index const n)
 Projects the which basis of tensor input onto the n-th state (1-indexed) of the sector sec. More...
 
STensorProxy proxy (STensor const &, EliminateZeros const elimzeros=EliminateZeros::No, SourceLocation const &loc=SourceLocation::current())
 Create a proxy over an existing STensor. More...
 
std::tuple< SRDef, STensorpseudo_invert (STensor const &in)
 Inverts the tensor using a SVD and returns the condition number of the result, which is obtained as the ratio of the largest and smallest inverted singular value. More...
 
std::tuple< STensor, STensor, SBasisqr (STensor const &in, SBasisId const &uncombined, DecompRescaleCGC const rescaleCGC=DecompRescaleCGC::Yes, FullQR const full=FullQR::n(), SourceLocation const &loc=SourceLocation::current())
 QR decomposition for STensor. More...
 
STensor randomise_blocks (STensor inp)
 Randomises dense blocks. More...
 
STensor real (STensor in)
 Sets the imaginary part of the input tensor to zero. More...
 
void registry_delete_stensor (STensor const *obj)
 Entry point to remove an STensor from the registry if syten::EnvVars::stensor_registry is true. More...
 
void registry_delete_stensor_impl (STensor const *obj)
 Implementation to delete an STensor from the registry. More...
 
void registry_enter_stensor (STensor const *obj)
 Entry point to add an STensor to the registry if syten::EnvVars::stensor_registry is true. More...
 
void registry_enter_stensor_impl (STensor const *obj)
 Implementation to add an STensor to the registry. More...
 
void registry_printout ()
 Prints information about all current STensor objects. More...
 
STensor remove_dummy_leg (STensor const &in, SBasisId to_be_removed)
 Constructs a new syten::STensor object which does not have the leg with Id to_be_removed. More...
 
template<Rank... Ranks>
constexpr bool sanity_check_stensor_rank (std::index_sequence< Ranks... >={})
 Triggered via static_assert, sanity-checks that the SYTEN_STENSOR_RANKS and SYTEN_STENSOR_MAX_RANK macros are defined properly. More...
 
SRDef snorm (STensor const &t, SourceLocation const &loc=SourceLocation::current())
 Returns the norm of a tensor as a standard scalar. More...
 
void sort (STensor &t)
 Sorts STensor (hopefully) uniquely. More...
 
STensor sqrt (STensor in)
 Takes the square root of a diagonal rank-2 or rank-0 tensor after mapping it to matrix form (outgoing leg first, incoming leg second in fermionic order). More...
 
SBasis sum (Basis const &b1, Basis const &b2, SBasisId const &id)
 Applies sum for normal Bases to SBases. More...
 
std::tuple< SRDef, STensor, STensor, STensor, SBasis, SBasissvd (STensor const &in, SBasisId const &uncombined, Truncation const &trunc=Truncation(), DecompRescaleCGC const rescaleCGC=DecompRescaleCGC::Yes, GaugeFixSVD gf=GaugeFixSVD::n(), SourceLocation const &loc=SourceLocation::current())
 SVD decomposition for STensor. More...
 
std::tuple< SRDef, STensor, STensor, STensor, SBasis, SBasissvd (STensor in, std::vector< SBasisId > const &uncombined, Direction const a, Truncation const &trunc=Truncation(), DecompRescaleCGC const rescaleCGC=DecompRescaleCGC::Yes, GaugeFixSVD gf=GaugeFixSVD::n(), SourceLocation const &loc=SourceLocation::current())
 This is an useful overload for splitting tensors into two by defining a partition of legs. More...
 
STensor trace (STensor const &in)
 Calculates the trace of a tensor. More...
 
std::tuple< STensor, SBasiszero_expand (STensor a, SBasis const &inner, SBasis const &zero)
 Constructs a zero-expanded tensor, expanding the leg inner by sectors as described in zero. More...
 
void zero_expand_nc (STensor &a, SBasis const &inner, SBasis const &zero)
 Constructs a zero-expanded tensor, expanding the leg inner by sectors as described in zero. More...
 
std::tuple< STensor, SBasiszero_expand_sam (STensor a, SBasis const &inner, SBasis const &zero)
 Constructs a zero-expanded tensor, expanding the leg inner by sectors as described in zero. More...
 
Stream operators
std::string summarise (STensor const &arg)
 Summarises the STensor in a string (bases etc.) More...
 
std::ostreamoperator<< (std::ostream &out, STensor const &arg)
 Complete output for a STensor. More...
 
Addition and subtraction of two STensor
STensor operator+ (STensor a, STensor b)
 Addition of two STensors. More...
 
STensor operator+ (STensor a, SDef const &b)
 Addition of a Scalar and an STensor, only valid for rank-0 tensors. More...
 
STensor operator+ (SDef const &a, STensor b)
 Addition of a Scalar and an STensor, only valid for rank-0 tensors. More...
 
STensoroperator+= (STensor &a, STensor b)
 Addition of one STensor onto another. More...
 
STensoroperator+= (STensor &a, SDef const &b)
 Addition of a Scalar onto an STensor. More...
 
STensor operator- (STensor a, STensor b)
 Subtraction of two STensors. More...
 
STensoroperator-= (STensor &a, STensor b)
 Subtraction of one STensor from another. More...
 
void addScaled (STensor &a, STensor b, SDef const &s)
 Fused multiply-add for an STensor, adds b scaled by the factor s to a in-place. More...
 
Multiplication of two STensor and scalar multiplication.
STensor operator* (STensorProxy const &a, STensorProxy const &b)
 Multiplication of two STensor and/or STensorProxy. More...
 
STensor operator* (STensorProxy const &a, SDef const &b)
 Scaling of one STensor or STensorProxy by a scalar. More...
 
STensor operator* (SDef const &b, STensorProxy const &a)
 Scaling of one STensor or STensorProxy by a scalar. More...
 
STensor operator/ (STensorProxy const &a, SDef const &b)
 Division of a STensor or STensorProxy by a scalar. More...
 
STensor operator/ (STensorProxy const &a, STensorProxy const &b)
 Division of one STensor or STensorProxy by another. More...
 
STensoroperator*= (STensor &a, STensorProxy const &b)
 Multiplication of one STensor by another or STensorProxy. More...
 
STensoroperator*= (STensor &a, SDef const &b)
 Scaling of one STensor by a scalar. More...
 
STensoroperator/= (STensor &a, SDef const &b)
 Division of a STensor by a scalar. More...
 
STensoroperator/= (STensor &a, STensorProxy const &b)
 Division of a STensor by another or a STensorProxy. More...
 
Comparison operators for STensor objects.
bool operator== (STensor const &a, STensor const &b)
 Equality comparison of two STensor objects. More...
 
bool operator== (STensor const &a, SDef const &b)
 Equality comparison of an STensor and a scalar. More...
 
bool operator== (SDef const &b, STensor const &a)
 Equality comparison of an STensor and a scalar. More...
 
bool operator!= (STensor const &a, STensor const &b)
 Non-equality comparison of two STensor objects. More...
 
bool operator!= (STensor const &a, SDef const &b)
 Non-equality comparison of an STensor and a scalar. More...
 
bool operator!= (SDef const &a, STensor const &b)
 Non-equality comparison of an STensor and a scalar. More...
 

Variables

std::unordered_map< STensor const *, std::chrono::time_point< std::chrono::high_resolution_clock > > registry
 Registry of all currently-existing STensor objects. More...
 

Detailed Description

Contains all ‘smart’ tensor related classes and functions.

Classes are injected into the main namespace, functions found via ADL.