Reference

Base.oneMethod
Base.one(a::AbstractNamedDimsArray, dimnames_codomain, dimnames_domain) -> Id

Return an identity-operator-shaped named array sharing a's dimension names, codomain/domain partition, and element type. The fused codomain and domain sizes must match. a is treated as a shape prototype and is not mutated.

The identity acts as the multiplicative identity for NamedDimsArrays.apply: it contracts on the domain names and renames the resulting codomain names back to the domain names, leaving the input unchanged.

Examples

julia> using NamedDimsArrays: apply, namedoneto, operator

julia> i, j, k, l = namedoneto.((2, 3, 2, 3), ("i", "j", "k", "l"));

julia> a = randn(i, j, k, l);

julia> Id = operator(one(a, (i, j), (k, l)), ("i", "j"), ("k", "l"));

julia> v = randn(k, l);

julia> apply(Id, v) ≈ v
true
source
Base.oneMethod
Base.one(op::AbstractNamedDimsOperator) -> Id

Return the identity operator with the same codomain/domain names and shape as op. op is treated as a shape prototype and is not mutated.

The identity acts as the multiplicative identity for NamedDimsArrays.apply: it contracts on the domain names and renames the resulting codomain names back to the domain names, leaving the input unchanged.

Examples

julia> using NamedDimsArrays: apply, namedoneto, operator

julia> i, j, k, l = namedoneto.((2, 3, 2, 3), ("i", "j", "k", "l"));

julia> op = operator(randn(i, j, k, l), ("i", "j"), ("k", "l"));

julia> Id = one(op);

julia> v = randn(k, l);

julia> apply(Id, v) ≈ v
true
source
NamedDimsArrays.dimnametypeFunction
dimnametype(a::AbstractNamedDimsArray)
dimnametype(type::Type{<:AbstractNamedDimsArray})

The type of an individual dimension name of a. The primary method dispatches on the array type, and dimnametype(a) forwards to dimnametype(typeof(a)).

Examples

julia> a = nameddims(zeros(2, 3), (:i, :j));

julia> dimnametype(a)
Symbol

julia> dimnametype(typeof(a))
Symbol
source
NamedDimsArrays.nameddimsMethod
nameddims(a::AbstractArray, inds)

Construct a named dimensions array from an denamed array a and named dimensions inds.

source
NamedDimsArrays.similar_operatorMethod
similar_operator(prototype, [T,] unnamed_domain_axes, [codomain_names,] domain_names) -> op
similar_operator(prototype, [T,] named_domain_axes) -> op

Allocate an operator-shaped named array with undefined data, with the user-supplied side as the domain (input) and a matching codomain (output). Element type defaults to eltype(prototype). Codomain names default to fresh randname-generated names. The first form takes unnamed (raw) axes and explicit names, the second takes already-named axes and reuses their names as the domain. Storage layout (including the bra/ket flip on the domain side for graded axes) is delegated to TensorAlgebra.similar_map.

source
TensorAlgebra.gram_eigh_fullMethod
TensorAlgebra.gram_eigh_full(a::AbstractNamedDimsArray, dimnames_codomain, dimnames_domain; kwargs...) -> x

Gram factorization of a Hermitian positive semi-definite named array a, returning x such that a ≈ x * x_cod, where x_cod is conj(x) with its domain dimension names replaced by the corresponding codomain names. x carries the domain dimension names of a (matching the convention that the stored factor labels a vector in a's input space) and a fresh trailing rank name.

kwargs are forwarded to TensorAlgebra.gram_eigh_full on the underlying unnamed array (e.g. atol, rtol).

Examples

julia> using NamedDimsArrays: dimnames, namedoneto, replacedimnames

julia> using TensorAlgebra: gram_eigh_full

julia> i, j, k, l, aux = namedoneto.((2, 2, 2, 2, 8), ("i", "j", "k", "l", "aux"));

julia> b = randn(aux, i, k);

julia> a = conj(b) * replacedimnames(b, "i" => "j", "k" => "l");

julia> x = gram_eigh_full(a, (i, k), (j, l));

julia> replacedimnames(x, "j" => "i", "l" => "k") * conj(x) ≈ a
true
source
TensorAlgebra.gram_eigh_fullMethod
TensorAlgebra.gram_eigh_full(a::AbstractNamedDimsOperator; kwargs...) -> x

Gram factorization of a Hermitian positive semi-definite named operator a, returning x such that x * x_cod ≈ state(a), where x_cod is conj(x) with its domain dimension names replaced by the corresponding codomain names of a. x carries a's domain dimension names and a fresh trailing rank name. The codomain and domain partition is taken from codomainnames(a) and domainnames(a).

kwargs are forwarded to TensorAlgebra.gram_eigh_full on the underlying named array (e.g. atol, rtol).

Examples

julia> using NamedDimsArrays: namedoneto, operator, replacedimnames, state

julia> using TensorAlgebra: gram_eigh_full

julia> i, j, k, l, aux = namedoneto.((2, 2, 2, 2, 8), ("i", "j", "k", "l", "aux"));

julia> b = randn(aux, i, k);

julia> a = operator(conj(b) * replacedimnames(b, "i" => "j", "k" => "l"), ("i", "k"), ("j", "l"));

julia> x = gram_eigh_full(a);

julia> replacedimnames(x, "j" => "i", "l" => "k") * conj(x) ≈ state(a)
true
source
TensorAlgebra.gram_eigh_full_with_pinvMethod
TensorAlgebra.gram_eigh_full_with_pinv(a::AbstractNamedDimsArray, dimnames_codomain, dimnames_domain; kwargs...) -> x, y

Like TensorAlgebra.gram_eigh_full, but additionally returns a named array y that is a left inverse of x: y * x ≈ I on the rank subspace (equal to the identity when a is full rank). x has the rank-name last, y has it first, both sharing the domain dimension names of a.

Examples

julia> using LinearAlgebra: I

julia> using NamedDimsArrays: dename, dimnames, namedoneto, replacedimnames

julia> using TensorAlgebra: gram_eigh_full_with_pinv

julia> i, j, k, l, aux = namedoneto.((2, 2, 2, 2, 8), ("i", "j", "k", "l", "aux"));

julia> b = randn(aux, i, k);

julia> a = conj(b) * replacedimnames(b, "i" => "j", "k" => "l");

julia> x, y = gram_eigh_full_with_pinv(a, (i, k), (j, l));

julia> replacedimnames(x, "j" => "i", "l" => "k") * conj(x) ≈ a
true

julia> rname = only(setdiff(dimnames(x), ("j", "l")));

julia> reshape(dename(y, (rname, "j", "l")), :, 4) *
       reshape(dename(x, ("j", "l", rname)), 4, :) ≈ I
true
source
TensorAlgebra.gram_eigh_full_with_pinvMethod
TensorAlgebra.gram_eigh_full_with_pinv(a::AbstractNamedDimsOperator; kwargs...) -> x, y

Like TensorAlgebra.gram_eigh_full, but additionally returns a named array y that is a left inverse of x: y * x ≈ I on the rank subspace (equal to the identity when a is full rank). The codomain and domain partition is taken from codomainnames(a) and domainnames(a).

Examples

julia> using LinearAlgebra: I

julia> using NamedDimsArrays: dename, dimnames, namedoneto, operator, replacedimnames

julia> using TensorAlgebra: gram_eigh_full_with_pinv

julia> i, j, k, l, aux = namedoneto.((2, 2, 2, 2, 8), ("i", "j", "k", "l", "aux"));

julia> b = randn(aux, i, k);

julia> a = operator(conj(b) * replacedimnames(b, "i" => "j", "k" => "l"), ("i", "k"), ("j", "l"));

julia> x, y = gram_eigh_full_with_pinv(a);

julia> rname = only(setdiff(dimnames(x), ("j", "l")));

julia> reshape(dename(y, (rname, "j", "l")), :, 4) *
       reshape(dename(x, ("j", "l", rname)), 4, :) ≈ I
true
source
NamedDimsArrays.@namesMacro
@names x y ...
@names x[1:3] y[1:3, 2:4] ...

Short-hand notation for constructing "named symbols", i.e. objects that can be used as names. In other words, the following expressions are equivalent:

x, y, z = @names x y z
x, y, z = Name.((:x, :y, :z))
source