Skip to content

Commit f3f660c

Browse files
borisdevoslkdvosclaudeJutho
authored
Specialise GradedSpace functions based on storage type (#511)
* specialise dim to storage type * oplus and ominus * infimum and supremum * fuse * truncate_space * restore binary search for sectordicts * refactor sorted merge procedure * speed up fuse slightly with sortperm * import thing * splat with type annotation above Val * actually don't splat, but construct directly where previously a vector was made * make slightly more readable maybe perhaps * truncate_space always has non-dual entry spaces * overkill iszero check in dim * assert truncate_space spaces being non-dual * introduce `sectorstoragetype` * specialise truncation code to sectorstoragetype * put `_sortedmerge` in `Base.mergewith` and use where possible * introduce and use `blockdims` * introduce the ntuple cutoff * apply code suggestions * slight refactor of sortmerge implementation * introduce `FullVectorDict` and use it * remove some reminder comments * avoid `NTuple{N,Int}(::Vector)` conversion cliff at N == 32 `NTuple{N,Int}(v)` falls off Julia's unrolled fast path at exactly N = 32: 9.7 ns at N = 31 versus 825 ns at N = 32. That is precisely `_ntuple_storage_threshold`, so the largest sector sets that tuple storage is meant to cover were by far the slowest to build. `ntuple(i -> @inbounds(v[i]), Val(N))` stays on the unrolled path and is faster at every N (3.1 ns at N = 32), so the threshold can stay at 32. Measured end-to-end, before -> after: Vect[ZNIrrep{32}] constructor 1067 ns -> 137 ns fuse, Z32, full 1329 ns -> 342 ns, 864 B/4 allocs -> 0 fuse, Z32, sparse 1088 ns -> 134 ns, 864 B/4 allocs -> 0 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * build tuple storage in a `MutableNTuple` with a bitmask The scatter-write paths that build `NTuple{N,Int}` storage used two heap buffers: a `zeros(Int, N)` accumulator and a `falses(N)` flag vector, both only there because `Base.setindex` on a tuple in a loop is slow. `TupleTools.MutableNTuple` replaces the accumulator: the optimizer elides the mutable box in these call patterns, so nothing escapes to the heap. Tracking which sectors have already been set needs one bit per sector, and tuple storage is only used for `N <= _ntuple_storage_threshold`, so a `UInt64` mask does that with no allocation at all. `Base.setindex` was measured as the third option and ruled out: 2-3x behind at N = 16 and 11x behind on the `fuse` accumulation pattern at N = 31. Constructor, before -> after: N = 4 121 ns, 240 B, 6 allocs -> 80 ns, 48 B, 1 alloc N = 16 115 ns, 432 B, 6 allocs -> 86 ns, 144 B, 1 alloc N = 32 137 ns, 560 B, 6 allocs -> 102 ns, 272 B, 1 alloc `fuse` deliberately keeps its plain `Vector` accumulator: it does not escape either, and `MutableNTuple` is ~9% slower there at N = 16 because the pointer round-trip blocks register promotion of the accumulator. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * specialise `flip` to tuple storage The generic `flip` rebuilds the space through `GradedSpace{I,NTuple{N,Int}}(dims)`, paying a `findindex` per sector plus the whole constructor. For tuple storage the result is just a fixed permutation of the dims with `isdual` negated, and that permutation depends only on `I`, so `Base.@assume_effects :foldable` lets it fold away entirely. flip, Z32 1083 ns, 1280 B, 9 allocs -> 5.2 ns, 0 B, 0 allocs flip, Z4 x Z8 1950 ns, 1280 B, 9 allocs -> 4.9 ns, 0 B, 0 allocs Verified to agree with the generic method on both `isdual` branches for Z4, Z8, Z32, a product sector, and empty spaces. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * make `ominus` a single pass `⊖` validated with `V ≿ W` and only then subtracted the dimensions, so every call traversed the sectors twice. `isepimorphic` also `collect`s `blocksectors(W)` and does a `dim` lookup per sector, which is what made `⊖` allocate on tuple storage where the subtraction itself is allocation-free. Both methods now subtract and validate in one pass: `map` over the two tuples, or one walk over the two sorted key vectors reusing `_mergestore!` so zero results are dropped. This also closes a latent trap. `_keepunmatched(-)` fell through to the `true` default, so `mergewith(-, ...)` gave a sector present only in `W` a *positive* dimension in the result; only the `≿` pre-check kept that unreachable. `⊖` was the sole `mergewith(-, ...)` caller, and there are none left. Rep[Z4] (tuple, N=4) 18.8 ns, 64 B, 2 allocs -> 2.1 ns, 0 B, 0 allocs ZNIrrep{8} (tuple, N=8) 42.8 ns, 112 B, 3 allocs -> 2.4 ns, 0 B, 0 allocs Rep[U1] (dict, 5 sect.) 76.3 ns, 384 B, 6 allocs -> 31.1 ns, 224 B, 5 allocs Rep[SU2] (dict, 6 sect.) 59.3 ns, 432 B, 6 allocs -> 27.9 ns, 256 B, 5 allocs Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * replace `_builddensemap` by `sectormap` in dicts.jl `_builddensemap(f, D, I, pairsiter, V)` took five arguments, two of which (`sectorstoragetype(I)` and `I`) were derivable and were spelled out at all fourteen call sites. It is really a `map` over `c => v` pairs into whichever dense sector map matches the storage choice for `GradedSpace{I}`, so it belongs next to the dict types rather than in the truncation code. - `sectormaptype(I, V)` folds the two-step storage dispatch into one function, keeping `_densemaptype` as the internal dispatch on the storage type. - `sectormap(f, [V,] pairsiter)` derives `I` from `eltype(pairsiter)` and, when `V` is omitted, the value type from `f` via `promote_op` - which is what four call sites were computing by hand. Only the intersection/union sites still pass `V` explicitly, to pin it to `Any`. - The separate keys-only builder is gone; callers that need just one half of the pair take a dummy argument. `pairs` normalises the intersection/union inputs, whose components may be `SectorVector` masks rather than dicts. `pairs(::SectorVector)` materialises a `SectorDict` that `sectormap` immediately re-iterates, but making it lazy would return a `Base.Generator` with `eltype == Any` and break the sector-type deduction at every call site, so it is left alone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * document why `fuse` accumulates into a `Dict` Inserting straight into the sorted result was measured as the alternative. It wins below a few hundred output sectors but is O(k^2) in them, and product sectors reach that regime quickly: U1 x U1 with 196 input sectors fuses to 729 output sectors at 1.03 ms against 0.57 ms for the `Dict`, and the gap grows. The `Dict` has no such cliff, so it stays. Also drops a stray blank line left before `_dualpermutation`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * address review: drop `FullVectorDict` and the `sectormap` paradigm `FullVectorDict`/`sectormap` existed only to give the truncation code a dense "sector => index" map for tuple-backed spaces. Their call sites all go through `pairs(::SectorVector)`, which materialises a `SectorDict` anyway, so the dense map bought little for a lot of `Sector`-specific machinery in `auxiliary/`. Every truncation index map is a plain `SectorDict` again; instead `pairs(::SectorVector)` is built directly from the already-sorted structure rather than by repeated sorted insertion. The storage-specialised `truncate_space` methods are kept, since they never used the dense map. Also from the review: - `⊖` for dict storage reuses `_sortedmerge`, whose `_keepunmatched` trait is generalised into per-side `_unmatched1`/`_unmatched2` hooks - `_ntuple_storage_threshold` -> `_NTUPLE_STORAGE_THRESHOLD`, lowered to 8 - `ZNSpace{N}` deprecated in favour of `Vect[ZNIrrep{N}]`, which the alias can no longer track once `N` exceeds the threshold - drop the over-strong `I == Trivial` assert in `truncate_space`, and name the index variables `ind`/`inds` instead of shadowing the sector type `I` Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix `pairs(::SectorVector)` for non-`SubArray` views `valtype(::SectorVector)` claims a `SubArray`, but `view` of a GPU array is itself a `CuArray`/`ROCArray`, so pinning the element type to `valtype` broke every GPU factorization. Take the element type from the views instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * review: storage-variant aliases, shared merge handlers, lazy `pairs` - add `TupleGradedSpace{I,N}` / `DictGradedSpace{I}` aliases for the two variants `sectorstoragetype` selects between, and use them for dispatch - `SubtractDims` doubles as the unmatched handler for `⊖`, and is used for the tuple variant as well, so both paths share one callable - `_sortedmerge` takes the unmatched handlers as arguments; `mergewith` selects them inline - `pairs(::SectorVector)` is lazy, like `blocks(::AbstractTensorMap)`: every consumer only iterates, and lookups go through the vector itself - document `sectorstoragetype`, whose docstring interpolates the threshold Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Apply batched suggestions from code review [skip ci] Co-authored-by: Jutho <Jutho@users.noreply.github.com> * review: drop StaticLength, simplify truncate_space, avoid re-sorting inds Address Jutho's final review round on #511: - replace `StaticLength(N)` with plain `N` (constant propagation makes the old TupleTools artefact unnecessary now that N is already a type parameter), and drop the now-dead `TupleTools: StaticLength` imports. - rewrite `truncate_space(::TupleGradedSpace, inds)` as a pure `ntuple` closure instead of mutating a `MutableNTuple`, guarding zero-dimension sectors before indexing into `inds` (which only holds keys for sectors with nonzero dimension). - `truncate_space(::DictGradedSpace, inds)` no longer collects and sorts: `inds` (whether a `SectorDict` or a `SectorVector`, depending on the truncation strategy) already iterates in sorted order by sector. - drop the now-unused `MutableNTuple`/`findindex` imports in the factorizations submodule. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * test: fix pairs(::SectorVector) comparison against Dict `pairs(::SectorVector)` is intentionally lazy (a `Base.Generator`), so comparing it directly to a `Dict` with `==` silently evaluates to `false` rather than erroring, since no `==` is defined between those unrelated iterator types. Collect it before comparing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: lkdvos <ldevos98@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Jutho <Jutho@users.noreply.github.com>
1 parent c19f94c commit f3f660c

11 files changed

Lines changed: 348 additions & 145 deletions

File tree

‎docs/src/Changelog.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
2626
- For sector types with `GenericUnit` such that colorings are not unique, `GradedSpace`, `ProductSpace` and `HomSpace` now check for this compatibility. In particular, this prevents the construction of `TensorMap`s with incompatible colorings, which previously either errored or produced empty tensors inconsistently. ([#515](https://github.com/QuantumKitHub/TensorKit.jl/pull/515))
2727

2828
### Deprecated
29+
- The type alias `ZNSpace{N}` is deprecated in favour of `Vect[ZNIrrep{N}]` or `Rep[ℤ{N}]`: a type alias cannot compute the storage type from `N`, so the two only agree for small `N`. ([#511](https://github.com/QuantumKitHub/TensorKit.jl/pull/511))
2930

3031
### Removed
3132

3233
### Fixed
3334

3435
### Performance
36+
- `GradedSpace` operations (`dim`, `flip`, `⊕`, `⊖`, `fuse`, `infimum`, `supremum`, truncation) are now specialised on the storage type of the degeneracy dimensions, and tuple storage is used only for sector types with at most `TensorKit._NTUPLE_STORAGE_THRESHOLD` sectors so that sector types with many sectors no longer burden the compiler. ([#511](https://github.com/QuantumKitHub/TensorKit.jl/pull/511))
3537

3638
## [0.17.1](https://github.com/QuantumKitHub/TensorKit.jl/compare/v0.17.0...v0.17.1) - 2026-07-13
3739

‎docs/src/lib/spaces.md‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ Vect
3737
Rep
3838
```
3939

40+
The storage that `Vect[I]` selects for the degeneracy dimensions depends on how many sectors `I` has:
41+
42+
```@docs
43+
TensorKit.sectorstoragetype
44+
```
45+
4046
In this respect, there are also a number of type aliases for the `GradedSpace` types associated with the most common sectors, namely
4147

4248
```julia
43-
const ZNSpace{N} = Vect[ZNIrrep{N}]
44-
const Z2Space = ZNSpace{2}
45-
const Z3Space = ZNSpace{3}
46-
const Z4Space = ZNSpace{4}
49+
const Z2Space = Rep[ℤ{2}]
50+
const Z3Space = Rep[ℤ{3}]
51+
const Z4Space = Rep[ℤ{4}]
4752
const U1Space = Rep[U₁]
4853
const CU1Space = Rep[CU₁]
4954
const SU2Space = Rep[SU₂]

‎docs/src/man/gradedspaces.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ However, this is mostly to lower the barrier, as really the instances of `Graded
2525
## Implementation details
2626

2727
As mentioned, the way in which the degeneracy dimensions ``n_a`` are stored depends on the specific sector type `I`, more specifically on the `IteratorSize` of `values(I)`.
28-
If `IteratorSize(values(I)) isa Union{IsInfinite, SizeUnknown}`, the different sectors ``a`` and their corresponding degeneracy ``n_a`` are stored as key value pairs in an `Associative` array, i.e. a dictionary `dims::SectorDict`.
28+
If `IteratorSize(values(I)) isa Union{IsInfinite, SizeUnknown}`, or if `values(I)` has a known length that exceeds `TensorKit._NTUPLE_STORAGE_THRESHOLD`, the different sectors ``a`` and their corresponding degeneracy ``n_a`` are stored as key value pairs in an `Associative` array, i.e. a dictionary `dims::SectorDict`.
2929
As the total number of sectors in `values(I)` can be infinite, only sectors ``a`` for which ``n_a`` are stored.
3030
Here, `SectorDict` is a constant type alias for a specific dictionary implementation, which currently resorts to `SortedVectorDict` implemented in TensorKit.jl.
3131
Hence, the sectors and their corresponding dimensions are stored as two matching lists (`Vector` instances), which are ordered based on the property `isless(a::I, b::I)`.
3232
This ensures that the space ``V = ⨁_a ℂ^{n_a} ⊗ R_{a}`` has some unique canonical order in the direct sum decomposition, such that two different but equal instances created independently always match.
3333

34-
If `IteratorSize(values(I)) isa Union{HasLength, HasShape}`, the degeneracy dimensions `n_a` are stored for all sectors `a ∈ values(I)` (also if `n_a == 0`) in a tuple, more specifically a `NTuple{N, Int}` with `N = length(values(I))`.
34+
If `IteratorSize(values(I)) isa Union{HasLength, HasShape}` and `N = length(values(I))` is at most `TensorKit._NTUPLE_STORAGE_THRESHOLD`, the degeneracy dimensions `n_a` are stored for all sectors `a ∈ values(I)` (also if `n_a == 0`) in a tuple, more specifically a `NTuple{N, Int}`.
3535
The methods `getindex(values(I), i)` and `findindex(values(I), a)` are used to map between a sector `a ∈ values(I)` and a corresponding index `i ∈ 1:N`.
3636
As `N` is a compile time constant, these types can be created in a type stable manner.
37-
Note however that this implies that for large values of `N`, it can be beneficial to define `IteratorSize(values(a)) = SizeUnknown()` to not overly burden the compiler.
37+
For larger `N` this would overly burden the compiler, which is precisely why the dictionary storage takes over above the threshold.
38+
The exact threshold is documented with [`TensorKit.sectorstoragetype`](@ref), which reports the storage type of a given sector type; the canonical space type is always obtained as `Vect[I]`.
3839

3940
## Constructing instances
4041

‎src/TensorKit.jl‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export infimum, supremum, isisomorphic, ismonomorphic, isepimorphic
4444
export sectortype, sectors, hassector
4545
export unit, rightunit, leftunit, allunits, isunit, otimes, deligneproduct, timereversed
4646
export Nsymbol, Fsymbol, Rsymbol, Bsymbol, frobenius_schur_phase, frobenius_schur_indicator, twist, fusiontensor
47-
export sectorscalartype, fusionscalartype, braidingscalartype
47+
export sectorscalartype, fusionscalartype, braidingscalartype, dimscalartype
4848

4949
# Export methods for fusion trees
5050
export fusiontrees, braid, permute, transpose
@@ -107,7 +107,6 @@ export empty_globalcaches!
107107
# Imports
108108
#---------
109109
using TupleTools
110-
using TupleTools: StaticLength
111110

112111
using Strided
113112

‎src/auxiliary/dicts.jl‎

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,12 @@ end
8989
Base.empty(::SortedVectorDict, ::Type{K}, ::Type{V}) where {K, V} = SortedVectorDict{K, V}()
9090
Base.empty!(d::SortedVectorDict) = (empty!(d.keys); empty!(d.values); return d)
9191

92-
# _searchsortedfirst(v::Vector, k) = searchsortedfirst(v, k)
93-
function _searchsortedfirst(v::Vector, k)
94-
i = 1
95-
@inbounds while i <= length(v) && isless(v[i], k)
96-
i += 1
97-
end
98-
return i
99-
end
100-
10192
function Base.delete!(d::SortedVectorDict{K}, k) where {K}
10293
key = convert(K, k)
10394
if !isequal(k, key)
10495
return d
10596
end
106-
i = _searchsortedfirst(d.keys, key)
97+
i = searchsortedfirst(d.keys, key)
10798
if i <= length(d) && isequal(d.keys[i], key)
10899
deleteat!(d.keys, i)
109100
deleteat!(d.values, i)
@@ -118,15 +109,15 @@ function Base.haskey(d::SortedVectorDict{K}, k) where {K}
118109
if !isequal(k, key)
119110
return false
120111
end
121-
i = _searchsortedfirst(d.keys, key)
112+
i = searchsortedfirst(d.keys, key)
122113
return (i <= length(d) && isequal(d.keys[i], key))
123114
end
124115
function Base.getindex(d::SortedVectorDict{K}, k) where {K}
125116
key = convert(K, k)
126117
if !isequal(k, key)
127118
throw(KeyError(k))
128119
end
129-
i = _searchsortedfirst(d.keys, key)
120+
i = searchsortedfirst(d.keys, key)
130121
@inbounds if (i <= length(d) && isequal(d.keys[i], key))
131122
return d.values[i]
132123
else
@@ -138,7 +129,7 @@ function Base.setindex!(d::SortedVectorDict{K}, v, k) where {K}
138129
if !isequal(k, key)
139130
throw(ArgumentError("$k is not a valid key for type $K"))
140131
end
141-
i = _searchsortedfirst(d.keys, key)
132+
i = searchsortedfirst(d.keys, key)
142133
if i <= length(d) && isequal(d.keys[i], key)
143134
d.values[i] = v
144135
else
@@ -153,7 +144,7 @@ function Base.get(d::SortedVectorDict{K}, k, default) where {K}
153144
if !isequal(k, key)
154145
return default
155146
end
156-
i = _searchsortedfirst(d.keys, key)
147+
i = searchsortedfirst(d.keys, key)
157148
@inbounds begin
158149
return (i <= length(d) && isequal(d.keys[i], key)) ? d.values[i] : default
159150
end
@@ -163,7 +154,7 @@ function Base.get(f::Union{Function, Type}, d::SortedVectorDict{K}, k) where {K}
163154
if !isequal(k, key)
164155
return f()
165156
end
166-
i = _searchsortedfirst(d.keys, key)
157+
i = searchsortedfirst(d.keys, key)
167158
@inbounds begin
168159
return (i <= length(d) && isequal(d.keys[i], key)) ? d.values[i] : f()
169160
end
@@ -186,6 +177,72 @@ function Base.:(==)(d1::SortedVectorDict, d2::SortedVectorDict)
186177
return true
187178
end
188179

180+
# merge two SortedVectorDicts of `GradedSpace` dimensions: `combine(v1, v2)` is applied to keys
181+
# present in both, `unmatched1(v)`/`unmatched2(v)` to keys present in only the first/second dict,
182+
# which may keep the value, drop the entry by returning `nothing`, or throw. Zero results are
183+
# always dropped, since `GradedSpace` never stores an explicit zero dimension.
184+
function _sortedmerge(
185+
combine::F, unmatched1::F1, unmatched2::F2,
186+
d1::SortedVectorDict{K, V}, d2::SortedVectorDict{K, V}
187+
) where {F, F1, F2, K, V <: Integer}
188+
k1, v1 = d1.keys, d1.values
189+
k2, v2 = d2.keys, d2.values
190+
n1, n2 = length(k1), length(k2)
191+
len = _mergelength(unmatched1, unmatched2, n1, n2)
192+
ks = Vector{K}(undef, len)
193+
vs = Vector{V}(undef, len)
194+
i, j, n = 1, 1, 0
195+
@inbounds while i <= n1 && j <= n2
196+
a, b = k1[i], k2[j]
197+
if isless(a, b)
198+
n = _mergestore!(ks, vs, n, a, unmatched1(v1[i]))
199+
i += 1
200+
elseif isless(b, a)
201+
n = _mergestore!(ks, vs, n, b, unmatched2(v2[j]))
202+
j += 1
203+
else
204+
n = _mergestore!(ks, vs, n, a, combine(v1[i], v2[j]))
205+
i += 1
206+
j += 1
207+
end
208+
end
209+
@inbounds while i <= n1
210+
n = _mergestore!(ks, vs, n, k1[i], unmatched1(v1[i]))
211+
i += 1
212+
end
213+
@inbounds while j <= n2
214+
n = _mergestore!(ks, vs, n, k2[j], unmatched2(v2[j]))
215+
j += 1
216+
end
217+
resize!(ks, n)
218+
resize!(vs, n)
219+
return SortedVectorDict{K, V}(ks, vs)
220+
end
221+
# write into slot `n + 1` and only advance the length when the value is nonzero
222+
@inline function _mergestore!(ks, vs, n, k, d)
223+
@inbounds ks[n + 1] = k
224+
@inbounds vs[n + 1] = d
225+
return n + !iszero(d)
226+
end
227+
@inline _mergestore!(ks, vs, n, k, ::Nothing) = n
228+
229+
# upper bound on the number of entries the merge can produce: a dropping handler contributes none
230+
function _mergelength(unmatched1, unmatched2, n1, n2)
231+
drop = Returns(nothing)
232+
return if unmatched1 == drop
233+
unmatched2 == drop ? min(n1, n2) : n2
234+
else
235+
unmatched2 == drop ? n1 : n1 + n2
236+
end
237+
end
238+
239+
function Base.mergewith(combine, d1::SortedVectorDict{K, V}, d2::SortedVectorDict{K, V}) where {K, V <: Integer}
240+
# keys occurring in only one of the dicts are kept, except for `min`, where a missing sector
241+
# has dimension zero and thus drops out of the result
242+
unmatched = combine == min ? Returns(nothing) : identity
243+
return _sortedmerge(combine, unmatched, unmatched, d1, d2)
244+
end
245+
189246
"""
190247
Hashed(value, hashfunction = Base.hash, isequal = Base.isequal)
191248

‎src/factorizations/factorizations.jl‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ module Factorizations
66
export copy_oftype, factorisation_scalartype, one!, truncspace
77

88
using ..TensorKit
9-
using ..TensorKit: AdjointTensorMap, SectorDict, SectorVector,
9+
using ..TensorKit: AdjointTensorMap, DictGradedSpace, SectorDict, SectorVector,
10+
TupleGradedSpace,
1011
blocktype, foreachblock, one!,
1112
similar_diagonal, similarstoragetype
1213
using ..TensorKit: GLOBAL_TIMER

‎src/factorizations/pullbacks.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ for pullback! in (:svd_pullback!, :eig_pullback!, :eigh_pullback!)
3232
kwargs...
3333
)
3434
foreachblock(Δt, t) do c, (Δb, b)
35-
haskey(inds, c) || return nothing
36-
ind = inds[c]
35+
ind = get(inds, c, nothing)
36+
isnothing(ind) && return nothing
3737
Fc = block.(F, Ref(c))
3838
ΔFc = block.(ΔF, Ref(c))
3939
MAK.$pullback!(Δb, b, Fc, ΔFc, ind; kwargs...)

0 commit comments

Comments
 (0)