diff --git a/docs/src/Changelog.md b/docs/src/Changelog.md index 50be1f602..eb041a913 100644 --- a/docs/src/Changelog.md +++ b/docs/src/Changelog.md @@ -40,6 +40,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec ### Performance - `twist!` and `twist` on a `TensorMap`, a `DiagonalTensorMap` or their adjoints use a cached tree transformer and the index manipulation kernel instead of a loop over all fusion trees, which removes the per-subblock bookkeeping and turns a twist of a GPU tensor, diagonal or not, into a single kernel launch ([#595](https://github.com/QuantumKitHub/TensorKit.jl/issues/595)) +- `foreachblock` with several tensors is type stable, which removes the dynamic dispatch on every call to it and to the factorizations that go through it ## [0.17.3](https://github.com/QuantumKitHub/TensorKit.jl/compare/v0.17.2...v0.17.3) - 2026-10-30 diff --git a/src/factorizations/matrixalgebrakit.jl b/src/factorizations/matrixalgebrakit.jl index 44bff6cd0..ef6e022c2 100644 --- a/src/factorizations/matrixalgebrakit.jl +++ b/src/factorizations/matrixalgebrakit.jl @@ -62,7 +62,7 @@ for (f!, bf!) in ((:svd_compact!, :batched_svd_compact!), (:svd_full!, :batched_ @timeit_debug GLOBAL_TIMER $(string(f!)) begin U, S, Vᴴ = F driver = get(alg.kwargs, :driver, MAK.DefaultDriver()) - cs = collect(union(blocksectors.((t, U, S, Vᴴ))...)) + cs = collect(union(map(blocksectors, (t, U, S, Vᴴ))...)) if !isempty(cs) && MAK.supports_ragged_batch(MAK.$f!, alg, driver, storagetype(t)) As = [block(t, c) for c in cs] Fs = ([block(U, c) for c in cs], [block(S, c) for c in cs], [block(Vᴴ, c) for c in cs]) diff --git a/src/fusiontrees/duality_manipulations.jl b/src/fusiontrees/duality_manipulations.jl index af3c02452..0065406d3 100644 --- a/src/fusiontrees/duality_manipulations.jl +++ b/src/fusiontrees/duality_manipulations.jl @@ -266,8 +266,8 @@ function foldright(src::FusionTreeBlock) multi_Fmove(f₁) end for (f₁′, coeff₁) in zip(f₁′s, coeffs₁) - b = f₁′.coupled - c = f₁.coupled + local b = f₁′.coupled + local c = f₁.coupled A = get!(cache₃, (b, c)) do Asymbol(a, b, c) end @@ -353,8 +353,8 @@ function foldleft(src::FusionTreeBlock) multi_Fmove(f₂) end for (f₂′, coeff₂) in zip(f₂′s, coeffs₂) - b = f₂′.coupled - c = f₂.coupled + local b = f₂′.coupled + local c = f₂.coupled A = get!(cache₃, (b, c)) do Asymbol(a, b, c) end diff --git a/src/tensors/blockiterators.jl b/src/tensors/blockiterators.jl index 893ad5ee7..88583e1bd 100644 --- a/src/tensors/blockiterators.jl +++ b/src/tensors/blockiterators.jl @@ -30,11 +30,11 @@ for c in union(blocksectors.(ts)...) end ``` """ -function foreachblock(f, t, ts...; scheduler = nothing) +function foreachblock(f, t, ts::Vararg{Any, N}; scheduler = nothing) where {N} tensors = (t, ts...) - allsectors = union(blocksectors.(tensors)...) + allsectors = union(map(blocksectors, tensors)...) foreach(allsectors) do c - return f(c, block.(tensors, Ref(c))) + return f(c, map(x -> block(x, c), tensors)) end return nothing end