Reference
TensorAlgebra.AbstractAlgorithm — Type
TensorAlgebra.AbstractAlgorithmSupertype for algorithm objects that select how an operation is performed, for example subtypes of ContractAlgorithm. An instance passes through TensorAlgebra.select_algorithm unchanged.
TensorAlgebra.ConjBroadcasted — Type
ConjBroadcasted(parent)Lazy conjugate of parent in a LinearBroadcasted expression, produced when a broadcast applies conj. Its axes are the conjugated axes of parent. It is not an AbstractArray, so it can also wrap a non-array operand such as a TensorMap.
TensorAlgebra.ContractAlgorithm — Type
ContractAlgorithmSupertype of contraction algorithms, passed as the alg keyword of contract and related functions. A new algorithm implements contractpermopadd! with the algorithm as its first argument.
TensorAlgebra.LinearBroadcasted — Type
LinearBroadcastedAbstract supertype for lazy linear broadcast expressions. Analogous to Base.Broadcast.Broadcasted but restricted to linear operations.
TensorAlgebra.MatricizeContract — Type
MatricizeContract()Contract by matricizing both operands and multiplying the matrices. The default algorithm for AbstractArray operands.
TensorAlgebra.PermutedDims — Type
PermutedDims(parent, perm)Lazy permuted-dims wrapper of parent by the permutation perm. Unlike Base.PermutedDimsArray, perm is stored in a field rather than a type parameter, so it constructs cheaply from a runtime permutation.
TensorAlgebra.TensorOperationsContract — Type
TensorOperationsContract(; backend = nothing, allocator = nothing)Contract using TensorOperations, with backend selecting the contraction kernel and allocator the allocator for temporary tensors (e.g. TensorOperations.ManualAllocator()). A nothing field uses TensorOperations' default. Only usable with TensorOperations loaded.
TensorAlgebra.add! — Method
add!(dest, src)dest .+= src.
TensorAlgebra.allocate_output — Function
allocate_output(f, args...)Allocate the destination that f writes its result into when called with args.
TensorAlgebra.allocate_project — Method
allocate_project(raw, axes_codomain, axes_domain) -> destAllocate the destination that projecting raw onto axes_codomain/axes_domain fills.
project projects into exactly the given axes, so raw must not have more axes than they account for. To append a derived flux-carrying auxiliary axis for a charge-shifting operator or a non-invariant state, use project_aux instead.
TensorAlgebra.bipartition — Method
bipartition(t::Tuple, length1::Val) -> (t1, t2)
bipartition(t::Tuple, perm1::Tuple, perm2::Tuple) -> (t1, t2)Split t into two tuples. The first form takes the first length1 entries as t1 and the rest as t2. The second form returns t1 = t[perm1...] and t2 = t[perm2...].
TensorAlgebra.bipermutedims! — Method
bipermutedims!(dest, a, perm_codomain, perm_domain)In-place counterpart of bipermutedims: write the permuted a into dest.
TensorAlgebra.bipermutedims — Method
bipermutedims(a, perm_codomain, perm_domain)Return permutedims(a, (perm_codomain..., perm_domain...)) in new storage, with the dimensions perm_codomain in the codomain and perm_domain in the domain.
TensorAlgebra.bipermutedimsadd! — Method
bipermutedimsadd!(dest, src, perm_codomain, perm_domain, α, β) -> destdest = β * dest + α * permutedims(src, (perm_codomain..., perm_domain...)).
TensorAlgebra.bipermutedimsconj! — Method
bipermutedimsconj!(dest, isconj::Bool, a, perm_codomain, perm_domain) -> destbipermutedimsop! with op = isconj ? conj : identity.
TensorAlgebra.bipermutedimsconj — Method
bipermutedimsconj(isconj::Bool, a, perm_codomain, perm_domain) -> destbipermutedimsop with op = isconj ? conj : identity.
TensorAlgebra.bipermutedimsconjadd! — Method
bipermutedimsconjadd!(dest, isconj::Bool, src, perm_codomain, perm_domain, α, β) -> destbipermutedimsopadd! with op = isconj ? conj : identity.
TensorAlgebra.bipermutedimsconjadd — Method
bipermutedimsconjadd(b, isconj::Bool, a, perm_codomain, perm_domain, α, β) -> destbipermutedimsopadd with op = isconj ? conj : identity.
TensorAlgebra.bipermutedimsconjscale! — Method
bipermutedimsconjscale!(dest, isconj::Bool, a, perm_codomain, perm_domain, α) -> destbipermutedimsopscale! with op = isconj ? conj : identity.
TensorAlgebra.bipermutedimsconjscale — Method
bipermutedimsconjscale(isconj::Bool, a, perm_codomain, perm_domain, α) -> destbipermutedimsopscale with op = isconj ? conj : identity.
TensorAlgebra.bipermutedimsop! — Method
bipermutedimsop!(dest, op, a, perm_codomain, perm_domain)In-place counterpart of bipermutedimsop: write op.(a) permuted into dest.
TensorAlgebra.bipermutedimsop — Method
bipermutedimsop(op, a, perm_codomain, perm_domain)Return op.(permutedims(a, (perm_codomain..., perm_domain...))) in new storage, where op is identity or conj, with the dimensions perm_codomain in the codomain and perm_domain in the domain.
TensorAlgebra.bipermutedimsopadd! — Method
bipermutedimsopadd!(dest, op, src, perm_codomain, perm_domain, α, β) -> destdest = β * dest + α * permutedims(op.(src), (perm_codomain..., perm_domain...)), where op is identity or conj. Overload this to customize permuting.
TensorAlgebra.bipermutedimsopadd — Method
bipermutedimsopadd(b, op, a, perm_codomain, perm_domain, α, β) -> destReturn β * b + α * op.(permutedims(a, (perm_codomain..., perm_domain...))) in new storage, the out-of-place counterpart of bipermutedimsopadd!, with the element type promoted over all arguments.
TensorAlgebra.bipermutedimsopscale! — Method
bipermutedimsopscale!(dest, op, a, perm_codomain, perm_domain, α) -> destIn-place counterpart of bipermutedimsopscale: write α * op.(a) permuted into dest.
TensorAlgebra.bipermutedimsopscale — Method
bipermutedimsopscale(op, a, perm_codomain, perm_domain, α) -> destReturn α * op.(permutedims(a, (perm_codomain..., perm_domain...))) in new storage, as in bipermutedimsop, with the element type promoted over α.
TensorAlgebra.check_input — Function
check_input(f, args...)Throw an error if args are not valid arguments to f. Generally the innermost function, such as an in-place one like contractpermopadd!, calls it.
TensorAlgebra.conjop — Method
conjop(isconj::Bool)The op matching isconj: conj if isconj is true, otherwise identity. The inverse of isopconj.
TensorAlgebra.contract! — Method
contract!(a_dest, labels_dest, a1, labels1, a2, labels2; alg = nothing) -> a_destOverwrite a_dest, with dimensions labeled by labels_dest, with the contraction of a1 and a2 over their shared labels.
See also contract and contractadd!.
TensorAlgebra.contract — Method
contract(a1, labels1, a2, labels2; alg = nothing) -> a_dest, labels_destContract the arrays over the labels they share, returning the result along with the labels of its dimensions. A label appearing on two operands is summed over, one appearing on a single operand survives, and labels_dest reports the surviving labels in the order the result carries them.
julia> using TensorAlgebra: contract
julia> a, b = randn(2, 3), randn(3, 4);
julia> ab, labels = contract(a, (:i, :j), b, (:j, :k));
julia> labels
2-element Vector{Symbol}:
:i
:k
julia> ab ≈ a * b
trueSee also contractalign to name the output dimensions and get back just the array.
TensorAlgebra.contractadd! — Method
contractadd!(a_dest, labels_dest, a1, labels1, a2, labels2, α, β; alg = nothing) -> a_desta_dest = β * a_dest + α * a1 * a2, contracting over the labels shared by a1 and a2, with labels_dest labeling the dimensions of a_dest.
See also contract!.
TensorAlgebra.contractalign — Method
contractalign(labels_dest, a1, labels1, a2, labels2; alg = nothing) -> a_destContract the input arrays over the shared labels, aligning the output array according to the specified destination labels labels_dest. labels_dest must match the uncontracted labels, i.e. issetequal(labels_dest, symdiff(labels1, labels2)) must be true.
julia> using TensorAlgebra: contractalign
julia> a, b = randn(2, 3), randn(3, 4);
julia> contractalign((:k, :i), a, (:i, :j), b, (:j, :k)) ≈ permutedims(a * b, (2, 1))
trueTensorAlgebra.contractconj! — Method
contractconj!(a_dest, labels_dest, isconj1::Bool, a1, labels1, isconj2::Bool, a2, labels2;
alg = nothing) -> a_destcontractop! with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractconj — Method
contractconj(isconj1::Bool, a1, labels1, isconj2::Bool, a2, labels2; alg = nothing)
-> a_dest, labels_destcontractop with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractconjadd! — Method
contractconjadd!(a_dest, labels_dest, isconj1::Bool, a1, labels1,
isconj2::Bool, a2, labels2, α, β; alg = nothing) -> a_destcontractopadd! with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractconjalign — Method
contractconjalign(labels_dest, isconj1::Bool, a1, labels1, isconj2::Bool, a2, labels2;
alg = nothing) -> a_destcontractopalign with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractop! — Method
contractop!(a_dest, labels_dest, op1, a1, labels1, op2, a2, labels2; alg = nothing) -> a_destOverwrite a_dest with the contraction of op1.(a1) and op2.(a2) as in contract!. Each op is identity or conj.
See also contractopadd!.
TensorAlgebra.contractop — Method
contractop(op1, a1, labels1, op2, a2, labels2; alg = nothing) -> a_dest, labels_destContract op1.(a1) with op2.(a2) over the labels they share, as in contract. Each op is identity or conj.
TensorAlgebra.contractopadd! — Method
contractopadd!(a_dest, labels_dest, op1, a1, labels1, op2, a2, labels2, α, β;
alg = nothing) -> a_desta_dest = β * a_dest + α * op1.(a1) * op2.(a2), contracting over the labels shared by a1 and a2, with labels_dest labeling the dimensions of a_dest. Each op is identity or conj.
TensorAlgebra.contractopalign — Method
contractopalign(labels_dest, op1, a1, labels1, op2, a2, labels2; alg = nothing) -> a_destContract op1.(a1) with op2.(a2) over the labels they share, with the dimensions of the result ordered by labels_dest, as in contractalign. Each op is identity or conj.
TensorAlgebra.contractperm! — Method
contractperm!(a_dest, perm_dest_codomain, perm_dest_domain,
a1, perm1_codomain, perm1_domain,
a2, perm2_codomain, perm2_domain; alg = nothing) -> a_destOverwrite a_dest with the contraction of a1 and a2 as in contractpermalign.
See also contractperm and contractpermadd!.
TensorAlgebra.contractperm — Method
contractperm(a1, perm1_codomain, perm1_domain, a2, perm2_codomain, perm2_domain;
alg = nothing) -> a_destContract a1 with a2 over the dimensions perm1_domain of a1 and perm2_codomain of a2. The result has the dimensions perm1_codomain of a1 as its codomain and perm2_domain of a2 as its domain.
See also contractpermalign.
TensorAlgebra.contractpermadd! — Method
contractpermadd!(a_dest, perm_dest_codomain, perm_dest_domain,
a1, perm1_codomain, perm1_domain,
a2, perm2_codomain, perm2_domain, α, β; alg = nothing) -> a_desta_dest = β * a_dest + α * a1 * a2, contracting over the dimensions perm1_domain of a1 and perm2_codomain of a2, with the dimensions of a_dest ordered by the destination permutations.
See also contractperm!.
TensorAlgebra.contractpermalign — Method
contractpermalign(perm_dest_codomain, perm_dest_domain,
a1, perm1_codomain, perm1_domain,
a2, perm2_codomain, perm2_domain; alg = nothing) -> a_destContract a1 with a2 over the dimensions perm1_domain of a1 and perm2_codomain of a2, with the result's dimensions in the order given by the destination permutations.
TensorAlgebra.contractpermconj! — Method
contractpermconj!(a_dest, perm_dest_codomain, perm_dest_domain,
isconj1::Bool, a1, perm1_codomain, perm1_domain,
isconj2::Bool, a2, perm2_codomain, perm2_domain; alg = nothing) -> a_destcontractpermop! with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractpermconj — Method
contractpermconj(isconj1::Bool, a1, perm1_codomain, perm1_domain,
isconj2::Bool, a2, perm2_codomain, perm2_domain; alg = nothing) -> a_destcontractpermop with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractpermconjadd! — Method
contractpermconjadd!(a_dest, perm_dest_codomain, perm_dest_domain,
isconj1::Bool, a1, perm1_codomain, perm1_domain,
isconj2::Bool, a2, perm2_codomain, perm2_domain, α, β;
alg = nothing) -> a_dest
contractpermconjadd!(alg::ContractAlgorithm, a_dest, perm_dest_codomain, perm_dest_domain,
isconj1::Bool, a1, perm1_codomain, perm1_domain,
isconj2::Bool, a2, perm2_codomain, perm2_domain, α, β) -> a_destcontractpermopadd! with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractpermconjalign — Method
contractpermconjalign(perm_dest_codomain, perm_dest_domain,
isconj1::Bool, a1, perm1_codomain, perm1_domain,
isconj2::Bool, a2, perm2_codomain, perm2_domain; alg = nothing)
-> a_destcontractpermopalign with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractpermconjscale! — Method
contractpermconjscale!(a_dest, perm_dest_codomain, perm_dest_domain,
isconj1::Bool, a1, perm1_codomain, perm1_domain,
isconj2::Bool, a2, perm2_codomain, perm2_domain, α;
alg = nothing) -> a_destcontractpermopscale! with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractpermconjscalealign — Method
contractpermconjscalealign(perm_dest_codomain, perm_dest_domain,
isconj1::Bool, a1, perm1_codomain, perm1_domain,
isconj2::Bool, a2, perm2_codomain, perm2_domain, α;
alg = nothing) -> a_destcontractpermopscalealign with op1 = isconj1 ? conj : identity and op2 = isconj2 ? conj : identity.
TensorAlgebra.contractpermop! — Method
contractpermop!(a_dest, perm_dest_codomain, perm_dest_domain,
op1, a1, perm1_codomain, perm1_domain,
op2, a2, perm2_codomain, perm2_domain; alg = nothing) -> a_destOverwrite a_dest with the contraction of op1.(a1) and op2.(a2) as in contractperm!. Each op is identity or conj.
See also contractpermopadd!.
TensorAlgebra.contractpermop — Method
contractpermop(op1, a1, perm1_codomain, perm1_domain, op2, a2, perm2_codomain, perm2_domain;
alg = nothing) -> a_destContract op1.(a1) with op2.(a2) as in contractperm. Each op is identity or conj.
TensorAlgebra.contractpermopadd! — Method
contractpermopadd!(a_dest, perm_dest_codomain, perm_dest_domain,
op1, a1, perm1_codomain, perm1_domain,
op2, a2, perm2_codomain, perm2_domain, α, β; alg = nothing) -> a_dest
contractpermopadd!(alg::ContractAlgorithm, a_dest, perm_dest_codomain, perm_dest_domain,
op1, a1, perm1_codomain, perm1_domain,
op2, a2, perm2_codomain, perm2_domain, α, β) -> a_desta_dest = β * a_dest + α * op1.(a1) * op2.(a2), contracting over the dimensions perm1_domain of a1 and perm2_codomain of a2, with the dimensions of a_dest ordered by the destination permutations. Each op is identity or conj.
Contraction backends overload the second form, which takes the ContractAlgorithm first.
TensorAlgebra.contractpermopalign — Method
contractpermopalign(perm_dest_codomain, perm_dest_domain,
op1, a1, perm1_codomain, perm1_domain,
op2, a2, perm2_codomain, perm2_domain; alg = nothing) -> a_destContract op1.(a1) with op2.(a2) as in contractpermalign. Each op is identity or conj.
TensorAlgebra.contractpermopscale! — Method
contractpermopscale!(a_dest, perm_dest_codomain, perm_dest_domain,
op1, a1, perm1_codomain, perm1_domain,
op2, a2, perm2_codomain, perm2_domain, α; alg = nothing) -> a_destIn-place counterpart of contractpermopscalealign: overwrite a_dest with α times the contraction of op1.(a1) with op2.(a2).
TensorAlgebra.contractpermopscalealign — Method
contractpermopscalealign(perm_dest_codomain, perm_dest_domain,
op1, a1, perm1_codomain, perm1_domain,
op2, a2, perm2_codomain, perm2_domain, α; alg = nothing) -> a_destReturn α times the contraction of op1.(a1) with op2.(a2) as in contractpermopalign, with the element type promoted over α.
TensorAlgebra.data — Method
data(a)The underlying storage of a, found by calling parent repeatedly until it returns its input. A wrapper returns the storage it ultimately wraps, and a plain array returns itself.
Examples
julia> import TensorAlgebra
julia> a = [1.0 2.0; 3.0 4.0];
julia> TensorAlgebra.data(transpose(a)) === a
true
julia> TensorAlgebra.data(a) === a
trueTensorAlgebra.datatype — Method
datatype(a) -> TypeThe type of the underlying storage of a, typeof(data(a)).
Examples
julia> import TensorAlgebra
julia> TensorAlgebra.datatype([1.0 2.0; 3.0 4.0])
Matrix{Float64} (alias for Array{Float64, 2})
julia> TensorAlgebra.datatype(transpose([1.0 2.0; 3.0 4.0]))
Matrix{Float64} (alias for Array{Float64, 2})TensorAlgebra.default_algorithm — Method
TensorAlgebra.default_algorithm(f, args::Tuple)
TensorAlgebra.default_algorithm(f, Args::Type{<:Tuple})The algorithm that f uses for the arguments args when the caller doesn't pass one. Overload it on the arguments or on their types: the form taking the arguments forwards to the type form by default.
TensorAlgebra.dot — Method
TensorAlgebra.dot(a, labels_a, b, labels_b)Compute the inner product of a and b after permuting the dimensions of b to match the labels of a. Each operand must have one unique label per dimension, and both label sets must match.
Examples
julia> import TensorAlgebra
julia> a = [1 2; 3 4];
b = [5 6; 7 8];
julia> TensorAlgebra.dot(a, (:i, :j), b, (:j, :i))
69TensorAlgebra.dotperm — Method
dotperm(a, b, perm)Compute the inner product of a and b after applying the dimension permutation perm to b. The permuted axes must match: axes(a, i) == axes(b, perm[i]).
Examples
julia> import TensorAlgebra
julia> TensorAlgebra.dotperm([1 2; 3 4], [5 6; 7 8], (2, 1))
69See also dot.
TensorAlgebra.dual — Function
dual(a)Returns the dual of the axis a. Falls back to returning a unchanged for AbstractUnitRange.
See also isdual.
TensorAlgebra.eig_full — Function
eig_full(A, labels_A, labels_codomain, labels_domain; kwargs...) -> D, V
eig_full(A, perm_codomain, perm_domain; kwargs...) -> D, V
eig_full(A, ndims_codomain::Val; kwargs...) -> D, VCompute the eigenvalue decomposition of a generic N-dimensional array interpreted as a general (non-Hermitian) linear map from the domain to the codomain dimensions. The output eltype is always <:Complex. The partition is specified either via labels or directly through a bi-permutation.
See also MatrixAlgebraKit.eig_full!.
TensorAlgebra.eig_trunc — Function
eig_trunc(A, labels_A, labels_codomain, labels_domain; trunc, kwargs...) -> D, V
eig_trunc(A, perm_codomain, perm_domain; trunc, kwargs...) -> D, V
eig_trunc(A, ndims_codomain::Val; trunc, kwargs...) -> D, VTruncated general eigenvalue decomposition, like eig_full but keeping only the eigenvalues selected by the trunc strategy.
See also MatrixAlgebraKit.eig_trunc!.
TensorAlgebra.eig_vals — Function
eig_vals(A, labels_A, labels_codomain, labels_domain; kwargs...) -> D
eig_vals(A, perm_codomain, perm_domain; kwargs...) -> D
eig_vals(A, ndims_codomain::Val; kwargs...) -> DCompute the eigenvalues of a generic N-dimensional array interpreted as a general (non-Hermitian) linear map from the domain to the codomain dimensions. The output is a vector of eigenvalues with <:Complex eltype.
See also MatrixAlgebraKit.eig_vals!.
TensorAlgebra.eigh_full — Function
eigh_full(A, labels_A, labels_codomain, labels_domain; kwargs...) -> D, V
eigh_full(A, perm_codomain, perm_domain; kwargs...) -> D, V
eigh_full(A, ndims_codomain::Val; kwargs...) -> D, VCompute the eigenvalue decomposition of a generic N-dimensional array interpreted as a Hermitian linear map from the domain to the codomain dimensions. The partition is specified either via labels or directly through a bi-permutation.
See also MatrixAlgebraKit.eigh_full!.
TensorAlgebra.eigh_trunc — Function
eigh_trunc(A, labels_A, labels_codomain, labels_domain; trunc, kwargs...) -> D, V
eigh_trunc(A, perm_codomain, perm_domain; trunc, kwargs...) -> D, V
eigh_trunc(A, ndims_codomain::Val; trunc, kwargs...) -> D, VTruncated Hermitian eigenvalue decomposition, like eigh_full but keeping only the eigenvalues selected by the trunc strategy.
See also MatrixAlgebraKit.eigh_trunc!.
TensorAlgebra.eigh_vals — Function
eigh_vals(A, labels_A, labels_codomain, labels_domain; kwargs...) -> D
eigh_vals(A, perm_codomain, perm_domain; kwargs...) -> D
eigh_vals(A, ndims_codomain::Val; kwargs...) -> DCompute the eigenvalues of a generic N-dimensional array interpreted as a Hermitian linear map from the domain to the codomain dimensions. The output is a vector of eigenvalues.
See also MatrixAlgebraKit.eigh_vals!.
TensorAlgebra.fill — Function
TensorAlgebra.zeros([T,] axes) -> A
TensorAlgebra.ones([T,] axes) -> A
TensorAlgebra.randn([rng,] [T,] axes) -> A
TensorAlgebra.rand([rng,] [T,] axes) -> A
TensorAlgebra.fill(v, axes) -> AConstruct an array with the given axes, a tuple of axes, filled with zeros, ones, normally-distributed values, uniformly-distributed values, or the value v. Unlike Base.randn and Base.rand, randn and rand accept Base.OneTo axes as well as integer dimensions.
See also zeros_map.
TensorAlgebra.fill_map — Function
zeros_map([T,] axes_codomain, axes_domain) -> M
ones_map([T,] axes_codomain, axes_domain) -> M
randn_map([rng,] [T,] axes_codomain, axes_domain) -> M
rand_map([rng,] [T,] axes_codomain, axes_domain) -> M
fill_map(v, axes_codomain, axes_domain) -> MConstruct an array shaped as a linear map from axes_domain to axes_codomain, filled with zeros (zeros_map), ones (ones_map), normally-distributed values (randn_map), uniformly-distributed values (rand_map), or the value v (fill_map), with element type T (defaulting to Float64, and taken from v for fill_map). As with similar_map, the domain axes are given un-dualized and are stored dualized.
TensorAlgebra.flattenlinear — Method
flattenlinear(bc::Broadcasted) -> LinearBroadcastedLike tryflattenlinear, but throw an ArgumentError when the expression is not linear instead of returning nothing.
TensorAlgebra.hasbipartition — Method
TensorAlgebra.hasbipartition(a) -> BoolWhether a's type stores an intrinsic codomain/domain split, so that ndims_codomain reports a split a genuinely carries rather than the all-codomain fallback. A TensorMap returns true and an array returns false.
TensorAlgebra.infer_aux_space — Method
infer_aux_space(raw, axes_codomain, axes_domain) -> auxDerive the auxiliary axis the *_aux projection verbs append as the last domain axis, so the projected result is symmetry-allowed. raw carries the trailing slice axis whose space is derived.
TensorAlgebra.invsqrth_safe — Function
invsqrth_safe(A, labels_A, labels_codomain, labels_domain; kwargs...) -> P
invsqrth_safe(A, perm_codomain, perm_domain; kwargs...) -> P
invsqrth_safe(A, ndims_codomain::Val; kwargs...) -> PPseudo-inverse square root of a generic N-dimensional array, interpreting it as a Hermitian positive semi-definite linear map from the domain to the codomain dimensions. The result carries the same codomain and domain axes as A. Eigenvalues below tolerance are clamped to zero (Moore-Penrose convention). The input must be Hermitian: project with project_hermitian first if it is Hermitian only up to numerical noise.
Keyword arguments
alg: forwarded toMatrixAlgebraKit.eigh_full.atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(A)))^(3//4)whenatol = 0, else0.
See also sqrth_safe, sqrth_invsqrth_safe, and MatrixAlgebra.invsqrth_safe.
TensorAlgebra.isdual — Function
isdual(a) -> BoolReturns true or false depending on if the axis a is dual. Falls back to false for AbstractUnitRange.
See also dual.
TensorAlgebra.isidentitybiperm — Method
isidentitybiperm(perm_codomain, perm_domain) -> BoolWhether the bipartitioned permutation (perm_codomain, perm_domain) is the identity, that is, whether (perm_codomain..., perm_domain...) is (1, 2, ..., n).
TensorAlgebra.isopconj — Method
isopconj(op) -> BoolWhether op is conj, for converting an op argument to the isconj flag taken by the conj forms such as bipermutedimsconjadd!. Throws an ArgumentError unless op is identity or conj. The inverse of conjop.
TensorAlgebra.isoutputview — Method
isoutputview(matricizeop, op, a, perm_codomain, perm_domain) -> BoolWhether matricizeop(op, a, perm_codomain, perm_domain) returns a result sharing memory with a. Defaults to false. Overload it together with matricizeopview, which builds the view.
TensorAlgebra.isprojected — Method
isprojected(dest, src, ndims_codomain::Val; kwargs...) -> Bool
isprojected(dest, src; kwargs...) -> BoolWhether the projected dest still represents src within the isapprox tolerance, that is, whether the projection that produced dest discarded only a negligible component of src. src is compared against unproject(dest, ndims_codomain), and keyword arguments are forwarded to isapprox. The two-argument form uses the codomain rank of dest.
TensorAlgebra.label_type — Method
label_type(::Type{L}) -> TypeThe label type to use when deriving a contraction.
Deriving a contraction makes several passes comparing labels, so a label type that is costly to compare can map here to a cheaper integer type: the labels are matched to integers by equality pattern, the bookkeeping runs on the integers, and the derived labels are mapped back. The default is the identity label_type(::Type{L}) = L, so the bookkeeping runs on the labels as-is. A label type with expensive equality opts in by defining e.g.
TensorAlgebra.label_type(::Type{MyLabel}) = IntTensorAlgebra.left_null — Function
left_null(A, labels_A, labels_codomain, labels_domain; kwargs...) -> N
left_null(A, perm_codomain, perm_domain; kwargs...) -> N
left_null(A, ndims_codomain::Val; kwargs...) -> NCompute the left nullspace of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions. These can be specified either via their labels or directly through a bi-permutation. The output satisfies N' * A ≈ 0 and N' * N ≈ I.
Keyword arguments
atol::Real=0: absolute tolerance for the nullspace computation.rtol::Real=0: relative tolerance for the nullspace computation.kind::Symbol: specify the kind of decomposition used to compute the nullspace. The options are:qr,:qrposand:svd. The former two require0 == atol == rtol. The default is:qrposifatol == rtol == 0, and:svdotherwise.
TensorAlgebra.left_orth — Function
left_orth(A, labels_A, labels_codomain, labels_domain; kwargs...) -> V, C
left_orth(A, perm_codomain, perm_domain; kwargs...) -> V, C
left_orth(A, ndims_codomain::Val; kwargs...) -> V, CCompute the left orthogonal decomposition of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions. These can be specified either via their labels or directly through a bi-permutation.
Keyword arguments
- Keyword arguments are passed on directly to MatrixAlgebraKit.
See also MatrixAlgebraKit.left_orth!.
TensorAlgebra.left_polar — Function
left_polar(A, labels_A, labels_codomain, labels_domain; kwargs...) -> W, P
left_polar(A, perm_codomain, perm_domain; kwargs...) -> W, P
left_polar(A, ndims_codomain::Val; kwargs...) -> W, PCompute the left polar decomposition of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions. These can be specified either via their labels or directly through a bi-permutation.
Keyword arguments
- Keyword arguments are passed on directly to MatrixAlgebraKit.
See also MatrixAlgebraKit.left_polar!.
TensorAlgebra.linearbroadcasted — Function
linearbroadcasted(f, args...)Construct a LinearBroadcasted subtype from function f and arguments. Analogous to Base.Broadcast.broadcasted(f, args...).
Examples
linearbroadcasted(*, 2.0, a) # ScaledBroadcasted(2.0, a)
linearbroadcasted(conj, a) # ConjBroadcasted(a)
linearbroadcasted(+, a, b) # AddBroadcasted(a, b)TensorAlgebra.lq_compact — Function
lq_compact(A, labels_A, labels_codomain, labels_domain; kwargs...) -> L, Q
lq_compact(A, perm_codomain, perm_domain; kwargs...) -> L, Q
lq_compact(A, ndims_codomain::Val; kwargs...) -> L, QCompute the compact LQ decomposition of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions, where L is square. The partition is specified either via labels or directly through a bi-permutation.
Keyword arguments
positive::Bool=false: specify if the diagonal ofLshould be positive, leading to a unique decomposition.- Other keywords are passed on directly to MatrixAlgebraKit.
See also MatrixAlgebraKit.lq_compact!.
TensorAlgebra.lq_full — Function
lq_full(A, labels_A, labels_codomain, labels_domain; kwargs...) -> L, Q
lq_full(A, perm_codomain, perm_domain; kwargs...) -> L, Q
lq_full(A, ndims_codomain::Val; kwargs...) -> L, QCompute the full LQ decomposition of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions, where Q is unitary. The partition is specified either via labels or directly through a bi-permutation.
Keyword arguments
positive::Bool=false: specify if the diagonal ofLshould be positive, leading to a unique decomposition.- Other keywords are passed on directly to MatrixAlgebraKit.
See also MatrixAlgebraKit.lq_full!.
TensorAlgebra.matricize — Method
matricize(a, perm_codomain, perm_domain) -> m
matricize(a, ndims_codomain::Val) -> mmatricizeop with op = identity.
TensorAlgebra.matricizeconj! — Method
matricizeconj!(dest, isconj::Bool, a, perm_codomain, perm_domain) -> destmatricizeop! with op = isconj ? conj : identity. Overload this together with allocate_output, which allocates dest.
TensorAlgebra.matricizeconj — Method
matricizeconj(isconj::Bool, a, perm_codomain, perm_domain) -> m
matricizeconj(isconj::Bool, a, ndims_codomain::Val) -> mmatricizeop with op = isconj ? conj : identity.
TensorAlgebra.matricizeconjcopy — Method
matricizeconjcopy(isconj::Bool, a, perm_codomain, perm_domain) -> mmatricizeopcopy with op = isconj ? conj : identity.
TensorAlgebra.matricizeconjview — Method
matricizeconjview(isconj::Bool, a, perm_codomain, perm_domain) -> mmatricizeopview with op = isconj ? conj : identity.
TensorAlgebra.matricizeop! — Method
matricizeop!(dest, op, a, perm_codomain, perm_domain) -> destWrite the matricization of op.(a) into the matrix dest. op is identity or conj.
TensorAlgebra.matricizeop — Method
matricizeop(op, a, perm_codomain, perm_domain) -> m
matricizeop(op, a, ndims_codomain::Val) -> mMatricize op.(a), fusing the codomain dimensions perm_codomain into rows and the domain dimensions perm_domain into columns. op is identity or conj. The result may share a's memory.
See also matricizeopcopy, matricizeopview and unmatricize.
TensorAlgebra.matricizeopcopy — Method
matricizeopcopy(op, a, perm_codomain, perm_domain) -> mMatricize op.(a) into new storage that the caller owns. op is identity or conj.
TensorAlgebra.matricizeopview — Method
matricizeopview(op, a, perm_codomain, perm_domain) -> mMatricize op.(a) as a matrix sharing a's memory. op is identity or conj. Overload this for the arguments where isoutputview returns true.
TensorAlgebra.ndims_codomain — Method
TensorAlgebra.ndims_codomain(a) -> Int
TensorAlgebra.ndims_domain(a) -> IntThe codomain and domain ranks of a's intrinsic split, for a type that stores one. An array has no intrinsic split, so it is all codomain with an empty domain. A type that stores a split overloads ndims_codomain and hasbipartition.
TensorAlgebra.ndims_domain — Method
TensorAlgebra.ndims_codomain(a) -> Int
TensorAlgebra.ndims_domain(a) -> IntThe codomain and domain ranks of a's intrinsic split, for a type that stores one. An array has no intrinsic split, so it is all codomain with an empty domain. A type that stores a split overloads ndims_codomain and hasbipartition.
TensorAlgebra.one — Function
TensorAlgebra.one(A, labels_A, labels_codomain, labels_domain) -> Id
TensorAlgebra.one(A, perm_codomain, perm_domain) -> Id
TensorAlgebra.one(A, ndims_codomain::Val) -> IdConstruct the identity operator tensor whose shape mirrors A, interpreted as a linear map from the domain to the codomain dimensions. The codomain and domain partition is specified either via labels or directly through a bi-permutation, and the fused codomain and domain sizes must match. A is treated as a shape prototype and is not mutated.
This is a separate function from Base.one, so qualify it as TensorAlgebra.one(A, ...).
See also MatrixAlgebra.one!.
Examples
julia> using LinearAlgebra: I
julia> using TensorAlgebra: TensorAlgebra, matricize
julia> A = randn(2, 3, 2, 3);
julia> Id = TensorAlgebra.one(A, (:a, :b, :c, :d), (:a, :b), (:c, :d));
julia> matricize(Id, (1, 2), (3, 4)) ≈ I
trueTensorAlgebra.ones — Function
TensorAlgebra.zeros([T,] axes) -> A
TensorAlgebra.ones([T,] axes) -> A
TensorAlgebra.randn([rng,] [T,] axes) -> A
TensorAlgebra.rand([rng,] [T,] axes) -> A
TensorAlgebra.fill(v, axes) -> AConstruct an array with the given axes, a tuple of axes, filled with zeros, ones, normally-distributed values, uniformly-distributed values, or the value v. Unlike Base.randn and Base.rand, randn and rand accept Base.OneTo axes as well as integer dimensions.
See also zeros_map.
TensorAlgebra.ones_map — Function
zeros_map([T,] axes_codomain, axes_domain) -> M
ones_map([T,] axes_codomain, axes_domain) -> M
randn_map([rng,] [T,] axes_codomain, axes_domain) -> M
rand_map([rng,] [T,] axes_codomain, axes_domain) -> M
fill_map(v, axes_codomain, axes_domain) -> MConstruct an array shaped as a linear map from axes_domain to axes_codomain, filled with zeros (zeros_map), ones (ones_map), normally-distributed values (randn_map), uniformly-distributed values (rand_map), or the value v (fill_map), with element type T (defaulting to Float64, and taken from v for fill_map). As with similar_map, the domain axes are given un-dualized and are stored dualized.
TensorAlgebra.output_axes — Function
output_axes(f, args...) -> (axes_codomain, axes_domain)The codomain and domain axes of the result of f called with args.
TensorAlgebra.permuteddims — Method
permuteddims(a, perm)Lazy permutedims. For an AbstractArray this is a Base.PermutedDimsArray view, and for any other operand it is a PermutedDims wrapper.
TensorAlgebra.permutedims! — Method
TensorAlgebra.permutedims!(dest, a, perm)
TensorAlgebra.permutedims!(dest, a, perm_codomain, perm_domain)In-place counterpart of TensorAlgebra.permutedims: write the permuted a into dest. The permutation is either flat or split into perm_codomain and perm_domain.
TensorAlgebra.permutedims — Method
TensorAlgebra.permutedims(a, perm)
TensorAlgebra.permutedims(a, perm_codomain, perm_domain)Out-of-place permutation of a. A flat perm gives an all-codomain result, and a permutation split into perm_codomain and perm_domain also splits the result. A dense operand ignores the split and stores the result flat.
TensorAlgebra.permutedimsadd! — Method
permutedimsadd!(dest, src, perm, α, β)
permutedimsadd!(dest, src, perm_codomain, perm_domain, α, β)dest = β * dest + α * permutedims(src, perm), with the permutation either flat or split into perm_codomain and perm_domain.
TensorAlgebra.permutedimsconj! — Method
permutedimsconj!(dest, isconj::Bool, src, perm) -> dest
permutedimsconj!(dest, isconj::Bool, src, perm_codomain, perm_domain) -> destpermutedimsop! with op = isconj ? conj : identity.
TensorAlgebra.permutedimsconj — Method
permutedimsconj(isconj::Bool, src, perm) -> dest
permutedimsconj(isconj::Bool, src, perm_codomain, perm_domain) -> destpermutedimsop with op = isconj ? conj : identity.
TensorAlgebra.permutedimsconjadd! — Method
permutedimsconjadd!(dest, isconj::Bool, src, perm, α, β) -> dest
permutedimsconjadd!(dest, isconj::Bool, src, perm_codomain, perm_domain, α, β) -> destpermutedimsopadd! with op = isconj ? conj : identity.
TensorAlgebra.permutedimsop! — Method
permutedimsop!(dest, op, src, perm)
permutedimsop!(dest, op, src, perm_codomain, perm_domain)Overwrite dest with permutedims(op.(src), perm), where op is identity or conj, with the permutation either flat or split into perm_codomain and perm_domain.
TensorAlgebra.permutedimsop — Method
permutedimsop(op, src, perm) -> dest
permutedimsop(op, src, perm_codomain, perm_domain) -> destReturn op.(permutedims(src, perm)) in new storage, where op is identity or conj. A flat perm gives an all-codomain result, and with perm_codomain and perm_domain the dimensions perm_codomain are in the codomain and perm_domain in the domain.
TensorAlgebra.permutedimsopadd! — Method
permutedimsopadd!(dest, op, src, perm, α, β) -> dest
permutedimsopadd!(dest, op, src, perm_codomain, perm_domain, α, β) -> destdest = β * dest + α * permutedims(op.(src), perm), where op is identity or conj. The permutation is either flat or split into perm_codomain and perm_domain, as in bipermutedimsopadd!.
TensorAlgebra.project! — Method
project!(dest, src; kwargs...) -> destIn-place checked projection: project src into the restricted space of dest and verify that only a negligible component was discarded, throwing an InexactError otherwise. Keyword arguments are forwarded to the isapprox tolerance check. See projectto! for the unchecked version and project for the allocating form.
TensorAlgebra.project — Method
project(raw, axes_codomain, axes_domain; kwargs...) -> dest
project(raw, axes; kwargs...) -> destProject raw into a symmetry-restricted array shaped as a map from axes_domain to axes_codomain, verifying that only a negligible component of raw is discarded and throwing an InexactError otherwise. Keyword arguments are forwarded to the isapprox tolerance check, and the default tolerances are subject to change in future versions. See tryproject for a nullable version and unchecked_project for an unchecked version.
raw must not have more axes than axes_codomain/axes_domain account for: project projects into exactly the given axes. To append a derived flux-carrying auxiliary axis (for a charge-shifting operator or a non-invariant state), use project_aux. The two-argument form takes a flat list of axes and is equivalent to an empty domain.
TensorAlgebra.project_aux — Method
project_aux(raw, axes_codomain, axes_domain; kwargs...) -> dest
project_aux(raw, axes; kwargs...) -> destProject raw and append a derived auxiliary domain axis carrying its flux, giving a symmetry-allowed result whose squeezed data is the input (the flux-canceling MPO-virtual-leg idiom). Unlike project, which projects into exactly the given axes, project_aux derives the extra leg (see infer_aux_space). raw may have the physical rank (a single operator or state, its flux on a length-1 leg) or one trailing slice axis (an operator multiplet as laid out by stack). Like project, it verifies that only a negligible component is discarded. See unchecked_project_aux and tryproject_aux for unchecked and nullable versions.
TensorAlgebra.project_hermitian — Function
project_hermitian(A, labels_A, labels_codomain, labels_domain; kwargs...) -> H
project_hermitian(A, perm_codomain, perm_domain; kwargs...) -> H
project_hermitian(A, ndims_codomain::Val; kwargs...) -> HHermitian part (M + M') / 2 of a generic N-dimensional array, interpreting it as a linear map M from the domain to the codomain dimensions. The result carries the same codomain and domain axes as A.
See also MatrixAlgebraKit.project_hermitian.
TensorAlgebra.projectto! — Method
projectto!(dest, src) -> destProject src into the restricted space of dest without checking which components may have been projected out. The sizes of src and dest may differ only by trailing length-1 axes. See project! for a checked version.
TensorAlgebra.qr_compact — Function
qr_compact(A, labels_A, labels_codomain, labels_domain; kwargs...) -> Q, R
qr_compact(A, perm_codomain, perm_domain; kwargs...) -> Q, R
qr_compact(A, ndims_codomain::Val; kwargs...) -> Q, RCompute the compact QR decomposition of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions, where R is square. The partition is specified either via labels or directly through a bi-permutation.
Keyword arguments
positive::Bool=false: specify if the diagonal ofRshould be positive, leading to a unique decomposition.- Other keywords are passed on directly to MatrixAlgebraKit.
See also MatrixAlgebraKit.qr_compact!.
TensorAlgebra.qr_full — Function
qr_full(A, labels_A, labels_codomain, labels_domain; kwargs...) -> Q, R
qr_full(A, perm_codomain, perm_domain; kwargs...) -> Q, R
qr_full(A, ndims_codomain::Val; kwargs...) -> Q, RCompute the full QR decomposition of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions, where Q is unitary. The partition is specified either via labels or directly through a bi-permutation.
Keyword arguments
positive::Bool=false: specify if the diagonal ofRshould be positive, leading to a unique decomposition.- Other keywords are passed on directly to MatrixAlgebraKit.
See also MatrixAlgebraKit.qr_full!.
TensorAlgebra.rand — Function
TensorAlgebra.zeros([T,] axes) -> A
TensorAlgebra.ones([T,] axes) -> A
TensorAlgebra.randn([rng,] [T,] axes) -> A
TensorAlgebra.rand([rng,] [T,] axes) -> A
TensorAlgebra.fill(v, axes) -> AConstruct an array with the given axes, a tuple of axes, filled with zeros, ones, normally-distributed values, uniformly-distributed values, or the value v. Unlike Base.randn and Base.rand, randn and rand accept Base.OneTo axes as well as integer dimensions.
See also zeros_map.
TensorAlgebra.rand_map — Function
zeros_map([T,] axes_codomain, axes_domain) -> M
ones_map([T,] axes_codomain, axes_domain) -> M
randn_map([rng,] [T,] axes_codomain, axes_domain) -> M
rand_map([rng,] [T,] axes_codomain, axes_domain) -> M
fill_map(v, axes_codomain, axes_domain) -> MConstruct an array shaped as a linear map from axes_domain to axes_codomain, filled with zeros (zeros_map), ones (ones_map), normally-distributed values (randn_map), uniformly-distributed values (rand_map), or the value v (fill_map), with element type T (defaulting to Float64, and taken from v for fill_map). As with similar_map, the domain axes are given un-dualized and are stored dualized.
TensorAlgebra.randn — Function
TensorAlgebra.zeros([T,] axes) -> A
TensorAlgebra.ones([T,] axes) -> A
TensorAlgebra.randn([rng,] [T,] axes) -> A
TensorAlgebra.rand([rng,] [T,] axes) -> A
TensorAlgebra.fill(v, axes) -> AConstruct an array with the given axes, a tuple of axes, filled with zeros, ones, normally-distributed values, uniformly-distributed values, or the value v. Unlike Base.randn and Base.rand, randn and rand accept Base.OneTo axes as well as integer dimensions.
See also zeros_map.
TensorAlgebra.randn_map — Function
zeros_map([T,] axes_codomain, axes_domain) -> M
ones_map([T,] axes_codomain, axes_domain) -> M
randn_map([rng,] [T,] axes_codomain, axes_domain) -> M
rand_map([rng,] [T,] axes_codomain, axes_domain) -> M
fill_map(v, axes_codomain, axes_domain) -> MConstruct an array shaped as a linear map from axes_domain to axes_codomain, filled with zeros (zeros_map), ones (ones_map), normally-distributed values (randn_map), uniformly-distributed values (rand_map), or the value v (fill_map), with element type T (defaulting to Float64, and taken from v for fill_map). As with similar_map, the domain axes are given un-dualized and are stored dualized.
TensorAlgebra.right_null — Function
right_null(A, labels_A, labels_codomain, labels_domain; kwargs...) -> Nᴴ
right_null(A, perm_codomain, perm_domain; kwargs...) -> Nᴴ
right_null(A, ndims_codomain::Val; kwargs...) -> NᴴCompute the right nullspace of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions. These can be specified either via their labels or directly through a bi-permutation. The output satisfies A * Nᴴ' ≈ 0 and Nᴴ * Nᴴ' ≈ I.
Keyword arguments
atol::Real=0: absolute tolerance for the nullspace computation.rtol::Real=0: relative tolerance for the nullspace computation.kind::Symbol: specify the kind of decomposition used to compute the nullspace. The options are:lq,:lqposand:svd. The former two require0 == atol == rtol. The default is:lqposifatol == rtol == 0, and:svdotherwise.
TensorAlgebra.right_orth — Function
right_orth(A, labels_A, labels_codomain, labels_domain; kwargs...) -> C, V
right_orth(A, perm_codomain, perm_domain; kwargs...) -> C, V
right_orth(A, ndims_codomain::Val; kwargs...) -> C, VCompute the right orthogonal decomposition of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions. These can be specified either via their labels or directly through a bi-permutation.
Keyword arguments
- Keyword arguments are passed on directly to MatrixAlgebraKit.
See also MatrixAlgebraKit.right_orth!.
TensorAlgebra.right_polar — Function
right_polar(A, labels_A, labels_codomain, labels_domain; kwargs...) -> P, W
right_polar(A, perm_codomain, perm_domain; kwargs...) -> P, W
right_polar(A, ndims_codomain::Val; kwargs...) -> P, WCompute the right polar decomposition of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions. These can be specified either via their labels or directly through a bi-permutation.
Keyword arguments
- Keyword arguments are passed on directly to MatrixAlgebraKit.
See also MatrixAlgebraKit.right_polar!.
TensorAlgebra.scalar — Function
scalar(a)The single scalar held by a zero-dimensional a, the equivalent of a[].
Examples
julia> import TensorAlgebra
julia> TensorAlgebra.scalar(fill(3.0))
3.0TensorAlgebra.scale! — Method
scale!(a::AbstractArray, β::Number) -> aIn-place scaling: multiply every entry of a by β.
TensorAlgebra.scaleadd! — Method
scaleadd!(dest, src, α, β)dest = β * dest + α * src.
TensorAlgebra.select_algorithm — Method
TensorAlgebra.select_algorithm(f, alg, args::Tuple)The algorithm that f uses for the arguments args, given the alg the caller passed. An alg of nothing gives TensorAlgebra.default_algorithm, an AbstractAlgorithm is returned unchanged, and anything else is an error.
TensorAlgebra.similar_map — Method
similar_map(prototype, [T,] axes_codomain, axes_domain) -> MAllocate an array shaped as a linear map from axes_domain to axes_codomain with element type T (defaulting to eltype(prototype)), using prototype to determine the array backend. The domain axes are given un-dualized and are stored dualized, so for an AbstractArray the result has axes (axes_codomain..., conj.(axes_domain)...).
Examples
julia> using TensorAlgebra: similar_map
julia> cod, dom = (Base.OneTo(2), Base.OneTo(3)), (Base.OneTo(4), Base.OneTo(5));
julia> M = similar_map(randn(3), Float32, cod, dom);
julia> eltype(M), size(M)
(Float32, (2, 3, 4, 5))TensorAlgebra.sqrth_invsqrth_safe — Function
sqrth_invsqrth_safe(A, labels_A, labels_codomain, labels_domain; kwargs...) -> P, Pinv
sqrth_invsqrth_safe(A, perm_codomain, perm_domain; kwargs...) -> P, Pinv
sqrth_invsqrth_safe(A, ndims_codomain::Val; kwargs...) -> P, PinvSquare root and pseudo-inverse square root of a generic N-dimensional array (see sqrth_safe and invsqrth_safe), from a single eigendecomposition. Both results carry the same codomain and domain axes as A.
Keyword arguments
alg: forwarded toMatrixAlgebraKit.eigh_full.atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(A)))^(3//4)whenatol = 0, else0.
See also MatrixAlgebra.sqrth_invsqrth_safe.
TensorAlgebra.sqrth_safe — Function
sqrth_safe(A, labels_A, labels_codomain, labels_domain; kwargs...) -> P
sqrth_safe(A, perm_codomain, perm_domain; kwargs...) -> P
sqrth_safe(A, ndims_codomain::Val; kwargs...) -> PSquare root of a generic N-dimensional array, interpreting it as a Hermitian positive semi-definite linear map from the domain to the codomain dimensions. The result carries the same codomain and domain axes as A. Eigenvalues below tolerance are clamped to zero. The input must be Hermitian: project with project_hermitian first if it is Hermitian only up to numerical noise.
Keyword arguments
alg: forwarded toMatrixAlgebraKit.eigh_full.atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(A)))^(3//4)whenatol = 0, else0.
See also invsqrth_safe, sqrth_invsqrth_safe, and MatrixAlgebra.sqrth_safe.
TensorAlgebra.svd_compact — Function
svd_compact(A, labels_A, labels_codomain, labels_domain; kwargs...) -> U, S, Vᴴ
svd_compact(A, perm_codomain, perm_domain; kwargs...) -> U, S, Vᴴ
svd_compact(A, ndims_codomain::Val; kwargs...) -> U, S, VᴴCompute the compact (thin) SVD of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions, where U and Vᴴ are isometric. The partition is specified either via labels or directly through a bi-permutation.
See also MatrixAlgebraKit.svd_compact!.
TensorAlgebra.svd_full — Function
svd_full(A, labels_A, labels_codomain, labels_domain; kwargs...) -> U, S, Vᴴ
svd_full(A, perm_codomain, perm_domain; kwargs...) -> U, S, Vᴴ
svd_full(A, ndims_codomain::Val; kwargs...) -> U, S, VᴴCompute the full (thick) SVD of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions, where U and Vᴴ are unitary. The partition is specified either via labels or directly through a bi-permutation.
See also MatrixAlgebraKit.svd_full!.
TensorAlgebra.svd_trunc — Function
svd_trunc(A, labels_A, labels_codomain, labels_domain; trunc, kwargs...) -> U, S, Vᴴ, ϵ
svd_trunc(A, perm_codomain, perm_domain; trunc, kwargs...) -> U, S, Vᴴ, ϵ
svd_trunc(A, ndims_codomain::Val; trunc, kwargs...) -> U, S, Vᴴ, ϵCompute the truncated SVD of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions. The partition is specified either via labels or directly through a bi-permutation. In addition to the factors, returns the truncation error ϵ, the 2-norm of the discarded singular values.
Keyword arguments
trunc: truncation strategy, passed on toMatrixAlgebraKit.svd_trunc.- Other keywords are passed on directly to MatrixAlgebraKit.
Examples
julia> using TensorAlgebra: svd_trunc, contractalign
julia> A = randn(4, 4);
julia> U, S, Vᴴ, ϵ = svd_trunc(A, (:i, :j), (:i,), (:j,));
julia> SV = contractalign((:u, :j), S, (:u, :v), Vᴴ, (:v, :j));
julia> contractalign((:i, :j), U, (:i, :u), SV, (:u, :j)) ≈ A
true
julia> isapprox(ϵ, 0; atol = 1e-10)
trueSee also MatrixAlgebraKit.svd_trunc!.
TensorAlgebra.svd_vals — Function
svd_vals(A, labels_A, labels_codomain, labels_domain) -> S
svd_vals(A, perm_codomain, perm_domain) -> S
svd_vals(A, ndims_codomain::Val) -> SCompute the singular values of a generic N-dimensional array, by interpreting it as a linear map from the domain to the codomain dimensions. The partition is specified either via labels or directly through a bi-permutation. The output is a vector of singular values.
See also MatrixAlgebraKit.svd_vals!.
TensorAlgebra.to_range — Method
TensorAlgebra.to_range(space)Convert a description of a space into a default range type, returning the range unchanged if it already is one.
- an
Integerlength ->Base.OneTo - an existing
AbstractUnitRange-> itself
Other packages extend this for richer spaces, for example GradedArrays converts a vector of sector-to-multiplicity pairs into a graded range.
TensorAlgebra.tr — Method
TensorAlgebra.tr(A, labels_A, labels_codomain, labels_domain)
TensorAlgebra.tr(A, perm_codomain, perm_domain)
TensorAlgebra.tr(A, ndims_codomain::Val)Trace of a generic N-dimensional array A interpreted as a linear map from its domain to its codomain dimensions. The partition is specified via labels, a bi-permutation, or directly as the codomain rank.
This is a separate function from LinearAlgebra.tr, taking a codomain/domain partition rather than a bare matrix.
Examples
julia> import TensorAlgebra
julia> A = randn(2, 2, 2, 2);
julia> TensorAlgebra.tr(A, (:i, :j, :k, :l), (:i, :k), (:j, :l)) ≈
sum(A[i, i, k, k] for i in 1:2, k in 1:2)
trueTensorAlgebra.trivialrange — Method
TensorAlgebra.trivialrange(R::Type{<:AbstractUnitRange}[, n::Integer])
TensorAlgebra.trivialrange(r::AbstractUnitRange[, n::Integer])Return the identity range for fusing ranges of type R: a one-dimensional range t for which fusing t with any other range of the same family leaves that range unchanged. Defaults to Base.OneTo(1), and for a graded range it is a charge-0 one-dimensional sector.
With a length n, return the n-dimensional analogue: n copies of the identity range stacked into one range (for a graded range, a charge-0 sector of dimension n).
TensorAlgebra.tryflattenlinear — Method
tryflattenlinear(bc::Broadcasted) -> LinearBroadcasted or nothingRecursively convert a Broadcasted tree to a LinearBroadcasted tree. Returns nothing if any node is not linear (as determined by islinearbroadcast).
Broadcast styles call this from Base.copy(::Broadcasted{MyStyle}) to opt into linear broadcasting at materialization time.
TensorAlgebra.tryproject — Method
tryproject(raw, axes_codomain, axes_domain; kwargs...) -> Union{dest, Nothing}
tryproject(raw, axes; kwargs...) -> Union{dest, Nothing}Like project, but return nothing instead of throwing when more than a negligible component of raw would be discarded. Useful for branching on whether raw is symmetry-allowed in the given axes, e.g. projecting a state as invariant and falling back to deriving an auxiliary flux-carrying leg:
@something tryproject(v, (cod,)) project_aux(v, (cod,))Keyword arguments are forwarded to the isapprox tolerance check.
TensorAlgebra.tryproject_aux — Method
tryproject_aux(raw, axes_codomain, axes_domain; kwargs...) -> Union{dest, Nothing}
tryproject_aux(raw, axes; kwargs...) -> Union{dest, Nothing}The nullable sibling of project_aux: derive and append the auxiliary axis, returning nothing instead of throwing when more than a negligible component of raw would be discarded.
TensorAlgebra.twist! — Method
twist!(a::AbstractArray, dims) -> aIn-place twist of a over the axes in dims, which scales a by the product of the sector twists of those axes (-1 for odd-parity fermionic charges, +1 otherwise). For an array without sector data, such as a plain Array, this is a no-op.
TensorAlgebra.unchecked_project — Method
unchecked_project(raw, axes_codomain, axes_domain) -> dest
unchecked_project(raw, axes) -> destProject raw into a symmetry-restricted array shaped as a map from axes_domain to axes_codomain, without checking which components are discarded: entries of raw outside the symmetry-allowed structure are dropped without inspection. Most callers want project, which verifies that nothing was discarded, or tryproject, which returns nothing instead of throwing. The two-argument form takes a flat list of axes and is equivalent to an empty domain.
TensorAlgebra.unchecked_project_aux — Method
unchecked_project_aux(raw, axes_codomain, axes_domain) -> dest
unchecked_project_aux(raw, axes) -> destThe unchecked sibling of project_aux: derive and append the auxiliary axis, then project without verifying which components are discarded.
TensorAlgebra.ungrade — Method
TensorAlgebra.ungrade(r)Return the plain range underlying the axis r, stripping any added structure such as a grading. A plain AbstractUnitRange is returned unchanged. For example, a graded range maps to the Base.OneTo of its total dimension.
Examples
julia> import TensorAlgebra
julia> TensorAlgebra.ungrade(2:5)
2:5TensorAlgebra.unmatricize — Function
unmatricize(m, axes_codomain, axes_domain) -> aUnfold the matrix m into an array with axes (axes_codomain..., conj.(axes_domain)...), undoing matricize with the dimensions in order.
TensorAlgebra.unmatricize! — Method
unmatricize!(a_dest, m, perm_codomain, perm_domain) -> a_dest
unmatricize!(a_dest, m, ndims_codomain::Val) -> a_destOverwrite a_dest with the array whose matricization with (perm_codomain, perm_domain) is m.
See also unmatricizeadd!.
TensorAlgebra.unmatricizeadd! — Method
unmatricizeadd!(a_dest, m, perm_codomain, perm_domain, α, β) -> a_desta_dest = β * a_dest + α * a, where a is the array whose matricization with (perm_codomain, perm_domain) is m.
TensorAlgebra.unproject — Method
unproject(a, ndims_codomain::Val) -> rawInverse of project: recover the dense array that project maps to a, given the codomain rank ndims_codomain as a Val. It satisfies
unproject(project(raw, axes_codomain, axes_domain), Val(length(axes_codomain))) ≈ rawTensorAlgebra.zero! — Method
zero!(a::AbstractArray) -> aIn-place zero: set every entry of a to zero.
TensorAlgebra.zeros — Function
TensorAlgebra.zeros([T,] axes) -> A
TensorAlgebra.ones([T,] axes) -> A
TensorAlgebra.randn([rng,] [T,] axes) -> A
TensorAlgebra.rand([rng,] [T,] axes) -> A
TensorAlgebra.fill(v, axes) -> AConstruct an array with the given axes, a tuple of axes, filled with zeros, ones, normally-distributed values, uniformly-distributed values, or the value v. Unlike Base.randn and Base.rand, randn and rand accept Base.OneTo axes as well as integer dimensions.
See also zeros_map.
TensorAlgebra.zeros_map — Function
zeros_map([T,] axes_codomain, axes_domain) -> M
ones_map([T,] axes_codomain, axes_domain) -> M
randn_map([rng,] [T,] axes_codomain, axes_domain) -> M
rand_map([rng,] [T,] axes_codomain, axes_domain) -> M
fill_map(v, axes_codomain, axes_domain) -> MConstruct an array shaped as a linear map from axes_domain to axes_codomain, filled with zeros (zeros_map), ones (ones_map), normally-distributed values (randn_map), uniformly-distributed values (rand_map), or the value v (fill_map), with element type T (defaulting to Float64, and taken from v for fill_map). As with similar_map, the domain axes are given un-dualized and are stored dualized.
TensorAlgebra.MatrixAlgebra.invsqrt_diag_safe — Method
invsqrt_diag_safe(D; atol=0, rtol=eps(real(eltype(D)))^(3//4)) -> D^(-1//2)Inverse square root of a diagonal-structured matrix D, treating diagonal entries below tolerance as zero (Moore-Penrose convention). Equivalent to pow_diag_safe(D, -1//2; atol, rtol).
Keyword arguments
atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(D)))^(3//4)whenatol = 0, else0.
TensorAlgebra.MatrixAlgebra.invsqrth_safe — Method
invsqrth_safe(M; alg=nothing, atol=0, rtol=eps(real(eltype(M)))^(3//4)) -> M^(-1//2)Inverse square root of a Hermitian positive semi-definite matrix. Equivalent to powh_safe(M, -1//2; alg, atol, rtol).
Keyword arguments
alg: forwarded toMatrixAlgebraKit.eigh_full.atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(M)))^(3//4)whenatol = 0, else0.
TensorAlgebra.MatrixAlgebra.one! — Method
MatrixAlgebra.one!(m) -> mFill m with the identity in place.
TensorAlgebra.MatrixAlgebra.pow_diag_safe! — Method
pow_diag_safe!(Dp, D, p, tol) -> DpIn-place version of pow_diag_safe: write the clamped powers of D's diagonal onto Dp, where entries d with abs(d) < tol become zero and the rest become d^p. Dp must be diagonal-structured with the same structure as D.
TensorAlgebra.MatrixAlgebra.pow_diag_safe — Method
pow_diag_safe(D, p; atol=0, rtol=eps(real(eltype(D)))^(3//4)) -> D^p
pow_diag_safe(D, p, tol) -> D^pRaise a diagonal-structured matrix D to the power p. Diagonal entries d with abs(d) < tol are clamped to zero before exponentiation, where tol = max(atol, rtol * norm(D, Inf)) (the largest-magnitude entry, which is the largest-magnitude diagonal entry for a diagonal-structured matrix). The three-argument form takes tol directly. Negative d above tol cause d^p to error for fractional p (e.g. p = 1//2) and pass through for integer p. Errors if isdiag(D) is false.
Keyword arguments
atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(D)))^(3//4)whenatol = 0, else0.
TensorAlgebra.MatrixAlgebra.powh_safe — Method
powh_safe(M, p; alg=nothing, atol=0, rtol=eps(real(eltype(M)))^(3//4)) -> M^pRaise a Hermitian positive semi-definite matrix to the power p. For diagonal-structured M (isdiag(M) == true), dispatches to pow_diag_safe and skips the eigendecomposition. Otherwise computes via M = V * D * V' as V * pow_diag_safe(D, p; atol, rtol) * V'.
The input must be Hermitian (as for MatrixAlgebraKit.eigh_full): project with MatrixAlgebraKit.project_hermitian first if it is Hermitian only up to numerical noise.
Keyword arguments
alg: forwarded toMatrixAlgebraKit.eigh_full.atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(M)))^(3//4)whenatol = 0, else0.
TensorAlgebra.MatrixAlgebra.sqrt_diag_safe — Method
sqrt_diag_safe(D; atol=0, rtol=eps(real(eltype(D)))^(3//4)) -> D^(1//2)Square root of a diagonal-structured matrix D, equivalent to pow_diag_safe(D, 1//2; atol, rtol).
Keyword arguments
atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(D)))^(3//4)whenatol = 0, else0.
TensorAlgebra.MatrixAlgebra.sqrth_invsqrth_safe — Method
sqrth_invsqrth_safe(M; alg=nothing, atol=0, rtol=eps(real(eltype(M)))^(3//4)) -> M^(1//2), M^(-1//2)Square root and pseudo-inverse square root of a Hermitian positive semi-definite matrix, from a single eigendecomposition. Equivalent to (sqrth_safe(M; ...), invsqrth_safe(M; ...)) but with the eigendecomposition computed once. Eigenvalues below tolerance are clamped to zero in both factors (Moore-Penrose convention for the inverse).
The input must be Hermitian (as for MatrixAlgebraKit.eigh_full): project with MatrixAlgebraKit.project_hermitian first if it is Hermitian only up to numerical noise.
Keyword arguments
alg: forwarded toMatrixAlgebraKit.eigh_full.atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(M)))^(3//4)whenatol = 0, else0.
TensorAlgebra.MatrixAlgebra.sqrth_safe — Method
sqrth_safe(M; alg=nothing, atol=0, rtol=eps(real(eltype(M)))^(3//4)) -> M^(1//2)Square root of a Hermitian positive semi-definite matrix. Equivalent to powh_safe(M, 1//2; alg, atol, rtol).
Keyword arguments
alg: forwarded toMatrixAlgebraKit.eigh_full.atol::Real: absolute clamping threshold. Default0.rtol::Real: relative clamping threshold. Defaulteps(real(eltype(M)))^(3//4)whenatol = 0, else0.
TensorAlgebra.MatrixAlgebra.truncdegen — Method
truncdegen(trunc::TruncationStrategy; atol::Real=0, rtol::Real=0)Modify a truncation strategy so that if the truncation falls within a degenerate subspace, the entire subspace gets truncated as well. A value val is considered degenerate if norm(val - truncval) ≤ max(atol, rtol * norm(truncval)) where truncval is the largest value truncated by the original truncation strategy trunc.
For now, this truncation strategy assumes the spectrum being truncated has already been reverse sorted and the strategy being wrapped outputs a contiguous subset of values including the largest one. It also only truncates for now, so may not respect if a minimum dimension was requested in the strategy being wrapped. These restrictions may be lifted in the future or provided through a different truncation strategy.