Skip to content

Commit eb3b342

Browse files
lkdvosclaude
andauthored
fix: Julia 1.13 compatibility (#76)
* fix: canonical ordering for `sectors(::SumSpace)` `_sectors` returned `values(::Set)`, i.e. hash iteration order, which changed in Julia 1.13 and broke the two `sectors(V)` assertions in the SumSpace tests (they had codified 1.12's order). The order also leaks into fusion tree enumeration via `map(sectors, P)`, making the layout within a block depend on the Julia version. Sort the result instead, consistent with `sectors(::GradedSpace)` (sorted by construction) and `blocksectors(::ProductSpace)` (ends with `sort!`), and assert the invariant with `issorted` rather than a hardcoded permutation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: normalize `One`/`Zero` scalars before `LinearAlgebra` `mul!` accumulates block contributions with `β = One()`, which reaches `LinearAlgebra` untouched. On Julia 1.13 the HERK path calls `isreal(β)`, which `VectorInterface.One` does not implement, so `w' * w` errors. Map `One`/`Zero` to `true`/`false` at that hand-off; the latter is exactly the strong zero `LinearAlgebra` documents, so the semantics are unchanged. The generic `_mul!!` fallbacks keep the `One`/`Zero` types for VectorInterface's promotion. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 95d776a commit eb3b342

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎src/linalg/linalg.jl‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ const _TM_CAN_MUL = Union{
129129
TensorMap, AdjointTensorMap{<:Any, <:Any, <:Any, <:Any, <:TensorMap}, BraidingTensor,
130130
}
131131
function _mul!!(C::_TM_CAN_MUL, A::_TM_CAN_MUL, B::_TM_CAN_MUL, α::Number, β::Number)
132-
return mul!(C, A, B, α, β)
132+
return mul!(C, A, B, _blasscalar(α), _blasscalar(β))
133133
end
134+
135+
# `LinearAlgebra` cannot handle `One`/`Zero`, which carry the same meaning as `true`/`false`
136+
# TODO: remove once `VectorInterface` implements the full `Number` interface for these
137+
_blasscalar(α::Number) = α
138+
_blasscalar(::One) = true
139+
_blasscalar(::Zero) = false
134140
# TODO: optimize other implementations
135141

136142
# ensure that mixes with AbstractBlockTensorMap and AbstractTensorMap behave as expected:

‎src/vectorspaces/sumspace.jl‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ end
128128
function TensorKit._sectors(S::SumSpace, ::Type{I}) where {I}
129129
s = Set{I}()
130130
for v in S.spaces
131-
s = s ∪ sectors(v)
131+
union!(s, sectors(v))
132132
end
133-
return values(s)
133+
# sorted for a canonical order, consistent with `GradedSpace` and `blocksectors`
134+
return sort!(collect(s))
134135
end
135136

136137
TensorKit.dim(S::SumSpace, sector::Sector) = sum(v -> dim(v, sector), S.spaces; init = 0)

‎test/vectorspaces/sumspace.jl‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ end
129129

130130
@test @constinferred(sectortype(V)) == sectortype(V1)
131131
@test ((@constinferred sectors(V))...,) == (U1Irrep(0), U1Irrep(1))
132+
@test issorted(sectors(V))
132133
@test length(sectors(V)) == 2
133134
@test @constinferred(hassector(V, U1Irrep(0)))
134135
@test !@constinferred(hassector(V, U1Irrep(2)))
@@ -188,7 +189,8 @@ end
188189
@test unitspace(V) == unitspace(V1)
189190

190191
@test @constinferred(sectortype(V)) == sectortype(V1)
191-
@test ((@constinferred sectors(V))...,) == (C1, C0, D1, D0, M) # ordering matters
192+
@test ((@constinferred sectors(V))...,) == (C0, C1, M, D0, D1) # sorted order
193+
@test issorted(sectors(V))
192194
@test length(sectors(V)) == 5
193195
@test @constinferred(hassector(V, M))
194196
@test !@constinferred(hassector(V, Mop))

0 commit comments

Comments
 (0)