Skip to content

Commit

Permalink
Rename *(HomSpace...) to compose
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed May 6, 2024
1 parent 260626d commit db85d6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/spaces/homspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ function permute(W::HomSpace{S}, (p₁, p₂)::Index2Tuple{N₁,N₂}) where {S,
return cod dom
end

function Base.:*(W::HomSpace{S}, V::HomSpace{S}) where {S}
"""
compose(W::HomSpace, V::HomSpace)
Obtain the HomSpace that is obtained from composing the morphisms in `W` and `V`. For this
to be possible, the domain of `W` must match the codomain of `V`.
"""
function compose(W::HomSpace{S}, V::HomSpace{S}) where {S}
domain(W) == codomain(V) || throw(SpaceMismatch("$(domain(W))$(codomain(V))"))
return HomSpace(codomain(W), domain(V))
end
4 changes: 2 additions & 2 deletions src/tensors/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LinearAlgebra.normalize(t::AbstractTensorMap, p::Real=2) = scale(t, inv(norm(t,

function Base.:*(t1::AbstractTensorMap, t2::AbstractTensorMap)
return mul!(similar(t1, promote_type(scalartype(t1), scalartype(t2)),
space(t1) * space(t2)), t1, t2)
compose(space(t1), space(t2))), t1, t2)
end
Base.exp(t::AbstractTensorMap) = exp!(copy(t))
function Base.:^(t::AbstractTensorMap, p::Integer)
Expand Down Expand Up @@ -242,7 +242,7 @@ end
function LinearAlgebra.mul!(tC::AbstractTensorMap,
tA::AbstractTensorMap,
tB::AbstractTensorMap, α=true, β=false)
space(tA) * space(tB) == space(tC) ||
compose(space(tA), space(tB)) == space(tC) ||
throw(SpaceMismatch("$(space(tC))$(space(tA)) * $(space(tB))"))

for c in blocksectors(tC)
Expand Down
2 changes: 1 addition & 1 deletion src/tensors/tensoroperations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function TO.tensorcontract_structure(pC::Index2Tuple{N₁,N₂},
conjB) where {S,N₁,N₂}
sA = TO.tensoradd_structure(pA, A, conjA)
sB = TO.tensoradd_structure(pB, B, conjB)
return permute(sA * sB, pC)
return permute(compose(sA, sB), pC)
end

function TO.checkcontractible(tA::AbstractTensorMap{S}, iA::Int, conjA::Symbol,
Expand Down
2 changes: 1 addition & 1 deletion test/spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,6 @@ println("------------------------------------")
@test W == deepcopy(W)
@test W == @constinferred permute(W, ((1, 2), (3, 4, 5)))
@test permute(W, ((2, 4, 5), (3, 1))) == (V2 V4' V5' V3 V1')
@test (V1 V2 V1 V2) == @constinferred W * W'
@test (V1 V2 V1 V2) == @constinferred compose(W, W')
end
end

0 comments on commit db85d6d

Please sign in to comment.