Skip to content

Commit bb8bf9d

Browse files
authored
docs: add costrings for catdomain and catcodomain (#485)
1 parent 336d13f commit bb8bf9d

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

src/tensors/linalg.jl

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,32 @@ for f in (:sqrt, :log, :asin, :acos, :acosh, :atanh, :acoth)
467467
end
468468
end
469469

470-
# concatenate tensors
470+
"""
471+
catdomain(t1::AbstractTensorMap{<:Any, S, N₁, 1}, t2::AbstractTensorMap{<:Any, S, N₁, 1}) where {S, N₁}
472+
473+
Given two tensors that share the same codomain, and whose domain is a single
474+
`ElementarySpace` (rank 1) with matching duality, return a new tensor `t` with that
475+
same codomain and domain `V = domain(t1) ⊕ domain(t2)` — the tensor-map analogue of
476+
`hcat`.
477+
478+
Throws a `SpaceMismatch` if the codomains don't match, or if `domain(t1)` and
479+
`domain(t2)` have different duality (i.e. one is dual and the other isn't) — a direct
480+
sum is only meaningful between spaces of matching duality.
481+
482+
See also [`catcodomain`](@ref).
483+
484+
# Examples
485+
```jldoctest
486+
julia> t1 = randn(ComplexF64, ℂ^2 ← ℂ^3);
487+
488+
julia> t2 = randn(ComplexF64, ℂ^2 ← ℂ^4);
489+
490+
julia> t3 = catdomain(t1, t2);
491+
492+
julia> only(domain(t3)) == only(domain(t1)) ⊕ only(domain(t2))
493+
true
494+
```
495+
"""
471496
function catdomain(t1::AbstractTensorMap{<:Any, S, N₁, 1}, t2::AbstractTensorMap{<:Any, S, N₁, 1}) where {S, N₁}
472497
codomain(t1) == codomain(t2) ||
473498
throw(
@@ -487,6 +512,33 @@ function catdomain(t1::AbstractTensorMap{<:Any, S, N₁, 1}, t2::AbstractTensorM
487512
end
488513
return t
489514
end
515+
516+
"""
517+
catcodomain(t1::AbstractTensorMap{<:Any, S, 1, N₂}, t2::AbstractTensorMap{<:Any, S, 1, N₂}) where {S, N₂}
518+
519+
Given two tensors that share the same domain, and whose codomain is a single
520+
`ElementarySpace` (rank 1) with matching duality, return a new tensor `t` with that
521+
same domain and codomain `V = codomain(t1) ⊕ codomain(t2)` — the tensor-map analogue
522+
of `vcat`.
523+
524+
Throws a `SpaceMismatch` if the domains don't match, or if `codomain(t1)` and
525+
`codomain(t2)` have different duality (i.e. one is dual and the other isn't) — a
526+
direct sum is only meaningful between spaces of matching duality.
527+
528+
See also [`catdomain`](@ref).
529+
530+
# Examples
531+
```jldoctest
532+
julia> t1 = randn(ComplexF64, ℂ^2 ← ℂ^3);
533+
534+
julia> t2 = randn(ComplexF64, ℂ^4 ← ℂ^3);
535+
536+
julia> t3 = catcodomain(t1, t2);
537+
538+
julia> only(codomain(t3)) == only(codomain(t1)) ⊕ only(codomain(t2))
539+
true
540+
```
541+
"""
490542
function catcodomain(t1::AbstractTensorMap{<:Any, S, 1, N₂}, t2::AbstractTensorMap{<:Any, S, 1, N₂}) where {S, N₂}
491543
domain(t1) == domain(t2) ||
492544
throw(SpaceMismatch("domains of tensors to concatenate must match:\n$(domain(t1))$(domain(t2))"))

0 commit comments

Comments
 (0)