Reference

TensorAlgebra.LinearBroadcastedType
LinearBroadcasted

Abstract supertype for lazy linear broadcast expressions. Analogous to Base.Broadcast.Broadcasted but restricted to linear operations.

Materializes via the protocol: copy(lb) = copyto!(similar(lb), lb) copyto!(dest, lb) → add!(dest, lb, 1, 0)

source
TensorAlgebra.bipermutedimsopadd!Method
bipermutedimsopadd!(dest, op, src, perm_codomain, perm_domain, α, β)

dest = β * dest + α * permutedims(op.(src), (perm_codomain..., perm_domain...)).

This is the primary overload point for downstream array types that want to implement op-aware bipartitioned permutation + accumulation (e.g., fuse conj into the copy, or use lazy wrappers like StridedView with op metadata).

The op is an element-wise linear map (e.g., identity, conj).

The default implementation flattens the bipartitioned permutation, applies op element-wise, permutes, then accumulates via broadcasting with Strided.jl optimization when possible.

source
TensorAlgebra.eigenFunction
eigen(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> D, V
eigen(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> D, V
eigen(A::AbstractArray, ndims_codomain::Val; kwargs...) -> D, V
eigen(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> D, V

Compute the eigenvalue 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

  • ishermitian::Bool: specify if the matrix is Hermitian, which can be used to speed up the computation. If false, the output eltype will always be <:Complex.
  • trunc: Truncation keywords for eig(h)_trunc.
  • Other keywords are passed on directly to MatrixAlgebraKit.

See also MatrixAlgebraKit.eig_full!, MatrixAlgebraKit.eig_trunc!, MatrixAlgebraKit.eig_vals!, MatrixAlgebraKit.eigh_full!, MatrixAlgebraKit.eigh_trunc!, and MatrixAlgebraKit.eigh_vals!.

source
TensorAlgebra.eigvalsFunction
eigvals(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> D
eigvals(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> D
eigvals(A::AbstractArray, ndims_codomain::Val; kwargs...) -> D
eigvals(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> D

Compute the eigenvalues 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 is a vector of eigenvalues.

Keyword arguments

  • ishermitian::Bool: specify if the matrix is Hermitian, which can be used to speed up the computation. If false, the output eltype will always be <:Complex.
  • Other keywords are passed on directly to MatrixAlgebraKit.

See also MatrixAlgebraKit.eig_vals! and MatrixAlgebraKit.eigh_vals!.

source
TensorAlgebra.factorizeFunction
factorize(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> X, Y
factorize(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> X, Y
factorize(A::AbstractArray, ndims_codomain::Val; kwargs...) -> X, Y
factorize(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> X, Y

Compute the 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

  • orth::Symbol=:left: specify the orthogonality of the decomposition. Currently only :left and :right are supported.
  • Other keywords are passed on directly to MatrixAlgebraKit.
source
TensorAlgebra.gram_eigh_fullFunction
gram_eigh_full(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> X
gram_eigh_full(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> X
gram_eigh_full(A::AbstractArray, ndims_codomain::Val; kwargs...) -> X
gram_eigh_full(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> X

Gram factorization of a generic N-dimensional array, interpreting it as a Hermitian positive semi-definite linear map from the domain to the codomain dimensions. Returns X such that A ≈ X' * X (contracted on the rank leg).

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(A)))^(3//4) when atol = 0, else 0.

Examples

julia> using TensorAlgebra: contract, gram_eigh_full

julia> B = randn(3, 2, 2);

julia> A = contract((:a, :b, :c, :d), conj(B), (:r, :a, :b), B, (:r, :c, :d));

julia> X = gram_eigh_full(A, (:a, :b, :c, :d), (:a, :b), (:c, :d));

julia> A ≈ contract((:a, :b, :c, :d), conj(X), (:r, :a, :b), X, (:r, :c, :d))
true

See also gram_eigh_full_with_pinv and MatrixAlgebra.gram_eigh_full.

source
TensorAlgebra.gram_eigh_full_with_pinvFunction
gram_eigh_full_with_pinv(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> X, Y
gram_eigh_full_with_pinv(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> X, Y
gram_eigh_full_with_pinv(A::AbstractArray, ndims_codomain::Val; kwargs...) -> X, Y
gram_eigh_full_with_pinv(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> X, Y

Like gram_eigh_full, but additionally returns Y ≈ pinv(X) such that X * Y ≈ I on the rank subspace.

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(A)))^(3//4) when atol = 0, else 0.

Examples

julia> using LinearAlgebra: I

julia> using TensorAlgebra: contract, gram_eigh_full_with_pinv

julia> B = randn(8, 2, 2);

julia> A = contract((:a, :b, :c, :d), conj(B), (:r, :a, :b), B, (:r, :c, :d));

julia> X, Y = gram_eigh_full_with_pinv(A, (:a, :b, :c, :d), (:a, :b), (:c, :d));

julia> A ≈ contract((:a, :b, :c, :d), conj(X), (:r, :a, :b), X, (:r, :c, :d))
true

julia> contract((:r, :s), X, (:r, :a, :b), Y, (:a, :b, :s)) ≈ I
true

See also MatrixAlgebra.gram_eigh_full_with_pinv.

source
TensorAlgebra.islinearbroadcastMethod
islinearbroadcast(f, args...) -> Bool

Per-node trait: can (f, args...) be expressed as a LinearBroadcasted? Extensible by downstream packages for additional linear operations.

source
TensorAlgebra.left_nullFunction
left_null(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> N
left_null(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> N
left_null(A::AbstractArray, ndims_codomain::Val; kwargs...) -> N
left_null(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> N

Compute 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, :qrpos and :svd. The former two require 0 == atol == rtol. The default is :qrpos if atol == rtol == 0, and :svd otherwise.
source
TensorAlgebra.left_orthFunction
left_orth(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> V, C
left_orth(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> V, C
left_orth(A::AbstractArray, ndims_codomain::Val; kwargs...) -> V, C
left_orth(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> V, C

Compute 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!.

source
TensorAlgebra.left_polarFunction
left_polar(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> W, P
left_polar(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> W, P
left_polar(A::AbstractArray, ndims_codomain::Val; kwargs...) -> W, P
left_polar(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> W, P

Compute 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!.

source
TensorAlgebra.linearbroadcastedFunction
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)
source
TensorAlgebra.lqFunction
lq(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> L, Q
lq(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> L, Q
lq(A::AbstractArray, ndims_codomain::Val; kwargs...) -> L, Q
lq(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> L, Q

Compute the LQ 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

  • full::Bool=false: select between a "full" or a "compact" decomposition, where Q is unitary or L is square, respectively.
  • positive::Bool=false: specify if the diagonal of L should be positive, leading to a unique decomposition.
  • Other keywords are passed on directly to MatrixAlgebraKit.

See also MatrixAlgebraKit.lq_full! and MatrixAlgebraKit.lq_compact!.

source
TensorAlgebra.matricizeopMethod
matricizeop(op, a, perm_codomain, perm_domain)

Matricize a with element-wise operation op folded in. Returns a matrix representing op.(matricize(a, perm_codomain, perm_domain)).

Has "maybe alias" semantics: the result may be a view/wrapper aliasing a or a fresh copy, depending on the fusion style and array type. The caller should treat the result as read-only.

source
TensorAlgebra.permutedimsopMethod
permutedimsop(op, src, perm_codomain, perm_domain)

Non-mutating version of bipermutedimsopadd!: returns op.(permutedims(src, (perm_codomain..., perm_domain...))).

source
TensorAlgebra.permutedimsopadd!Method
permutedimsopadd!(dest, op, src, perm, α, β)

dest = β * dest + α * permutedims(op.(src), perm).

This is the single materialization primitive for LinearBroadcasted types. Downstream array types should implement bipermutedimsopadd! for the bipartitioned permutation version; this flat-permutation overload forwards to it with perm_domain = ().

source
TensorAlgebra.qrFunction
qr(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> Q, R
qr(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> Q, R
qr(A::AbstractArray, ndims_codomain::Val; kwargs...) -> Q, R
qr(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> Q, R

Compute the QR 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

  • full::Bool=false: select between a "full" or a "compact" decomposition, where Q is unitary or R is square, respectively.
  • positive::Bool=false: specify if the diagonal of R should be positive, leading to a unique decomposition.
  • Other keywords are passed on directly to MatrixAlgebraKit.

See also MatrixAlgebraKit.qr_full! and MatrixAlgebraKit.qr_compact!.

source
TensorAlgebra.right_nullFunction
right_null(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> Nᴴ
right_null(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> Nᴴ
right_null(A::AbstractArray, ndims_codomain::Val::Val; kwargs...) -> Nᴴ
right_null(A::AbstractArray, biperm::AbstractBlockPermutation{2}; 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, :lqpos and :svd. The former two require 0 == atol == rtol. The default is :lqpos if atol == rtol == 0, and :svd otherwise.
source
TensorAlgebra.right_orthFunction
right_orth(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> C, V
right_orth(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> C, V
right_orth(A::AbstractArray, ndims_codomain::Val; kwargs...) -> C, V
right_orth(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> C, V

Compute 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!.

source
TensorAlgebra.right_polarFunction
right_polar(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> P, W
right_polar(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> P, W
right_polar(A::AbstractArray, ndims_codomain::Val; kwargs...) -> P, W
right_polar(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> P, W

Compute 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!.

source
TensorAlgebra.svdFunction
svd(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) -> U, S, Vᴴ
svd(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}; kwargs...) -> U, S, Vᴴ
svd(A::AbstractArray, ndims_codomain::Val; kwargs...) -> U, S, Vᴴ
svd(A::AbstractArray, biperm::AbstractBlockPermutation{2}; kwargs...) -> U, S, Vᴴ

Compute the SVD 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

  • full::Bool=false: select between a "thick" or a "thin" decomposition, where both U and Vᴴ are unitary or isometric.
  • trunc: Truncation keywords for svd_trunc. Not compatible with full=true.
  • Other keywords are passed on directly to MatrixAlgebraKit.

See also MatrixAlgebraKit.svd_full!, MatrixAlgebraKit.svd_compact!, and MatrixAlgebraKit.svd_trunc!.

source
TensorAlgebra.svdvalsFunction
svdvals(A::AbstractArray, labels_A, labels_codomain, labels_domain) -> S
svdvals(A::AbstractArray, perm_codomain::Tuple{Vararg{Int}}, perm_domain::Tuple{Vararg{Int}}) -> S
svdvals(A::AbstractArray, ndims_codomain::Val) -> S
svdvals(A::AbstractArray, biperm::AbstractBlockPermutation{2}) -> S

Compute the singular values 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 is a vector of singular values.

See also MatrixAlgebraKit.svd_vals!.

source
TensorAlgebra.tryflattenlinearMethod
tryflattenlinear(bc::Broadcasted) -> LinearBroadcasted or nothing

Recursively convert a Broadcasted tree to a LinearBroadcasted tree. Returns nothing if any node is not linear (as determined by islinearbroadcast).

Analogous to Broadcast.flatten for Broadcasted trees, but converts to LinearBroadcasted subtypes via linearbroadcasted.

Downstream styles call this from Base.copy(::Broadcasted{MyStyle}) to opt into linear broadcasting at materialization time.

source
TensorAlgebra.MatrixAlgebra.gram_eigh_fullFunction
gram_eigh_full(A::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(A)))^(3//4)) -> X
gram_eigh_full!!(A::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(A)))^(3//4)) -> X

Gram factorization of a Hermitian positive semi-definite matrix via its eigendecomposition: returns X = sqrth_safe(D; atol, rtol) * V' such that A ≈ X' * X, where A = V * D * V'. Eigenvalues below tol (see pow_diag_safe) are clamped to zero. The !! variant may destroy A.

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(A)))^(3//4) when atol = 0, else 0.

Examples

julia> using TensorAlgebra.MatrixAlgebra: gram_eigh_full

julia> B = [1.0 0.5; 0.5 2.0];

julia> A = B' * B;

julia> X = gram_eigh_full(A);

julia> X' * X ≈ A
true

See also gram_eigh_full_with_pinv.

source
TensorAlgebra.MatrixAlgebra.gram_eigh_full!!Function
gram_eigh_full(A::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(A)))^(3//4)) -> X
gram_eigh_full!!(A::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(A)))^(3//4)) -> X

Gram factorization of a Hermitian positive semi-definite matrix via its eigendecomposition: returns X = sqrth_safe(D; atol, rtol) * V' such that A ≈ X' * X, where A = V * D * V'. Eigenvalues below tol (see pow_diag_safe) are clamped to zero. The !! variant may destroy A.

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(A)))^(3//4) when atol = 0, else 0.

Examples

julia> using TensorAlgebra.MatrixAlgebra: gram_eigh_full

julia> B = [1.0 0.5; 0.5 2.0];

julia> A = B' * B;

julia> X = gram_eigh_full(A);

julia> X' * X ≈ A
true

See also gram_eigh_full_with_pinv.

source
TensorAlgebra.MatrixAlgebra.gram_eigh_full_with_pinvFunction
gram_eigh_full_with_pinv(A::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(A)))^(3//4)) -> X, Y
gram_eigh_full_with_pinv!!(A::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(A)))^(3//4)) -> X, Y

Like gram_eigh_full, but additionally returns Y = V * invsqrth_safe(D; atol, rtol) ≈ pinv(X) so that X * Y ≈ I on the rank subspace. Eigenvalues below tol are clamped to zero in both factors. The !! variant may destroy A.

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(A)))^(3//4) when atol = 0, else 0.

Examples

julia> using LinearAlgebra: I

julia> using TensorAlgebra.MatrixAlgebra: gram_eigh_full_with_pinv

julia> B = [1.0 0.5; 0.5 2.0];

julia> A = B' * B;

julia> X, Y = gram_eigh_full_with_pinv(A);

julia> X' * X ≈ A
true

julia> X * Y ≈ I
true
source
TensorAlgebra.MatrixAlgebra.gram_eigh_full_with_pinv!!Function
gram_eigh_full_with_pinv(A::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(A)))^(3//4)) -> X, Y
gram_eigh_full_with_pinv!!(A::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(A)))^(3//4)) -> X, Y

Like gram_eigh_full, but additionally returns Y = V * invsqrth_safe(D; atol, rtol) ≈ pinv(X) so that X * Y ≈ I on the rank subspace. Eigenvalues below tol are clamped to zero in both factors. The !! variant may destroy A.

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(A)))^(3//4) when atol = 0, else 0.

Examples

julia> using LinearAlgebra: I

julia> using TensorAlgebra.MatrixAlgebra: gram_eigh_full_with_pinv

julia> B = [1.0 0.5; 0.5 2.0];

julia> A = B' * B;

julia> X, Y = gram_eigh_full_with_pinv(A);

julia> X' * X ≈ A
true

julia> X * Y ≈ I
true
source
TensorAlgebra.MatrixAlgebra.invsqrt_diag_safeMethod
invsqrt_diag_safe(D::AbstractMatrix; 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. Default 0.
  • rtol::Real: relative clamping threshold. Default eps(real(eltype(D)))^(3//4) when atol = 0, else 0.
source
TensorAlgebra.MatrixAlgebra.invsqrth_safeMethod
invsqrth_safe(M::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(M)))^(3//4)) -> M^(-1//2)

Inverse square root of an approximately Hermitian positive semi-definite matrix. Equivalent to powh_safe(M, -1//2; alg, atol, rtol).

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(M)))^(3//4) when atol = 0, else 0.

source
TensorAlgebra.MatrixAlgebra.pow_diag_safeMethod
pow_diag_safe(D::AbstractMatrix, p; atol=0, rtol=eps(real(eltype(D)))^(3//4)) -> D^p

Raise a diagonal-structured matrix D to the power p. Diagonal entries d of MAK.diagview(D) with abs(d) < tol are clamped to zero before exponentiation, where tol = max(atol, rtol * maximum(abs, diagview(D))). Negative d above tol cause d^p to error for fractional p (e.g. p = 1//2) and pass through for integer p, so the operation itself enforces the PSD precondition per-power. Errors if isdiag(D) is false.

The implementation extracts entries via MAK.diagview and rebuilds via MAK.diagonal, so types extending those (e.g. graded or block diagonal) automatically extend sqrt_diag_safe, invsqrt_diag_safe, and the powh_safe family.

Keyword arguments

  • atol::Real: absolute clamping threshold. Default 0.
  • rtol::Real: relative clamping threshold. Default eps(real(eltype(D)))^(3//4) when atol = 0, else 0.
source
TensorAlgebra.MatrixAlgebra.powh_safeMethod
powh_safe(M::AbstractMatrix, p; alg=nothing, atol=0, rtol=eps(real(eltype(M)))^(3//4)) -> M^p

Raise an approximately 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'.

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(M)))^(3//4) when atol = 0, else 0.

source
TensorAlgebra.MatrixAlgebra.sqrt_diag_safeMethod
sqrt_diag_safe(D::AbstractMatrix; 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. Default 0.
  • rtol::Real: relative clamping threshold. Default eps(real(eltype(D)))^(3//4) when atol = 0, else 0.
source
TensorAlgebra.MatrixAlgebra.sqrth_safeMethod
sqrth_safe(M::AbstractMatrix; alg=nothing, atol=0, rtol=eps(real(eltype(M)))^(3//4)) -> M^(1//2)

Square root of an approximately Hermitian positive semi-definite matrix. Equivalent to powh_safe(M, 1//2; alg, atol, rtol).

Keyword arguments

  • alg: forwarded to MatrixAlgebraKit.eigh_full.

  • atol::Real: absolute clamping threshold. Default 0.

  • rtol::Real: relative clamping threshold. Default eps(real(eltype(M)))^(3//4) when atol = 0, else 0.

source
TensorAlgebra.MatrixAlgebra.truncdegenMethod
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.

source