Skip to content

Commit e40d1da

Browse files
committed
more JET happiness
1 parent 5fa5947 commit e40d1da

7 files changed

Lines changed: 29 additions & 10 deletions

File tree

src/auxiliary/iterators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct OneOrNoneIterator{T}
44
end
55

66
function Base.iterate(it::OneOrNoneIterator, state = true)
7-
if state && it.cond
7+
if isone(state) && it.cond
88
return (it.first, false)
99
else
1010
return nothing

src/fusiontrees/fusiontrees.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ function fusiontensor((f₁, f₂)::FusionTreePair)
334334
d1 = TupleTools.front(sz1)
335335
d2 = TupleTools.front(sz2)
336336
return reshape(
337-
reshape(F₁, TupleTools.prod(d1), sz1[end]) *
338-
reshape(F₂, TupleTools.prod(d2), sz2[end])', (d1..., d2...)
337+
reshape(F₁, :, sz1[end]) * reshape(F₂, :, sz2[end])', (d1..., d2...)
339338
)
340339
end
341340
fusiontensor(src::FusionTreeBlock) = sum(fusiontensor, fusiontrees(src))

src/pullbacks/tensoroperations.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function blas_contract_pullback_ΔA!(
2-
ΔA, ΔC, A, pA, B, pB, pAB, α, backend, allocator
2+
ΔA, ΔC, A::AbstractTensorMap, pA, B::AbstractTensorMap, pB, pAB, α, backend, allocator
33
)
44
ipAB = invperm(linearize(pAB))
55
pΔC = TO.repartition(ipAB, TO.numout(pA))
@@ -23,7 +23,7 @@ function blas_contract_pullback_ΔA!(
2323
end
2424

2525
function blas_contract_pullback_ΔB!(
26-
ΔB, ΔC, A, pA, B, pB, pAB, α, backend, allocator
26+
ΔB, ΔC, A::AbstractTensorMap, pA, B::AbstractTensorMap, pB, pAB, α, backend, allocator
2727
)
2828
ipAB = invperm(linearize(pAB))
2929
pΔC = TO.repartition(ipAB, TO.numout(pA))
@@ -48,7 +48,7 @@ function blas_contract_pullback_ΔB!(
4848
end
4949

5050
function trace_permute_pullback_ΔA!(
51-
ΔA, ΔC, A, p, q, α, backend
51+
ΔA, ΔC, A::AbstractTensorMap, p, q, α, backend
5252
)
5353
ip = invperm((linearize(p)..., q[1]..., q[2]...))
5454
pdA = TO.repartition(ip, numout(A))

src/spaces/productspace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ that make up the `ProductSpace` instance.
146146
"""
147147
function blocksectors(P::ProductSpace{S, N}) where {S, N}
148148
I = sectortype(S)
149-
if I == Trivial
149+
if I === Trivial
150150
return OneOrNoneIterator(dim(P) != 0, Trivial())
151151
end
152152
bs = Vector{I}()

src/tensors/abstracttensor.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ See also [`numin`](@ref) and [`numind`](@ref).
237237
""" numout
238238

239239
numout(x) = numout(typeof(x))
240-
numout(T::Type) = throw(MethodError(numout, T)) # avoid infinite recursion
240+
numout(T::Type) = throw(MethodError(numout, (T,))) # avoid infinite recursion
241+
# `typeintersect(Type{<:AbstractTensorMap}, Type{<:Union{FusionTreePair, FusionTreeBlock}})` is
242+
# `Type{Union{}}`, which leaves the parametric methods mutually ambiguous. Resolve it explicitly so
243+
# the intended `MethodError` is thrown instead of an ambiguity error.
244+
numout(::Type{Union{}}) = throw(MethodError(numout, (Union{},)))
241245
numout(::Type{<:AbstractTensorMap{T, S, N₁}}) where {T, S, N₁} = N₁
242246

243247
@doc """
@@ -251,7 +255,8 @@ See also [`numout`](@ref) and [`numind`](@ref).
251255
""" numin
252256

253257
numin(x) = numin(typeof(x))
254-
numin(T::Type) = throw(MethodError(numin, T)) # avoid infinite recursion
258+
numin(T::Type) = throw(MethodError(numin, (T,))) # avoid infinite recursion
259+
numin(::Type{Union{}}) = throw(MethodError(numin, (Union{},))) # see `numout(::Type{Union{}})`
255260
numin(::Type{<:AbstractTensorMap{T, S, N₁, N₂}}) where {T, S, N₁, N₂} = N₂
256261

257262
"""

src/tensors/adjoint.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ end
1313
Base.parent(t::AdjointTensorMap) = t.parent
1414
parenttype(t::AdjointTensorMap) = parenttype(typeof(t))
1515
parenttype(::Type{AdjointTensorMap{T, S, N₁, N₂, TT}}) where {T, S, N₁, N₂, TT} = TT
16+
parenttype(::Type{Union{}}) = throw(MethodError(parenttype, (Union{},)))
1617

1718
# Constructor: construct from taking adjoint of a tensor
1819
Base.adjoint(t::AdjointTensorMap) = parent(t)

test/other/jet.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,23 @@ using TensorKit
22
using Test
33
using JET
44

5+
# Reports that are not TensorKit's to fix. Each entry needs an upstream issue.
6+
const IGNORED = (
7+
# `schur_full`/`schur_vals` route `Diagonal` inputs to `DiagonalAlgorithm`, which schur does
8+
# not implement, so `schur_full(::DiagonalTensorMap)` throws a `MethodError`. This reproduces
9+
# with a plain `LinearAlgebra.Diagonal` and no TensorKit involved:
10+
# https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/issues/276
11+
JET.LastFrameMethod(:schur_full!),
12+
JET.LastFrameMethod(:schur_vals!),
13+
# `local variable kwargs may be undefined` inside `GenericTreeTransformer`, coming entirely
14+
# from Base's `@debug` expansion (`local msg, kwargs` bound in a short-circuit guard) rather
15+
# than from any TensorKit code: https://github.com/aviatesk/JET.jl/issues/860
16+
JET.LastFrameMethod(:GenericTreeTransformer),
17+
)
18+
519
# also gated in runtests.jl; JET < 0.12 does not define `JET_AVAILABLE`
620
if isdefined(JET, :JET_AVAILABLE) && JET.JET_AVAILABLE
7-
JET.test_package(TensorKit; target_modules = (TensorKit,))
21+
JET.test_package(TensorKit; target_modules = (TensorKit,), ignored_modules = IGNORED)
822
else
923
@info "Full JET functionality is unavailable on Julia $VERSION; skipping JET analysis"
1024
end

0 commit comments

Comments
 (0)