Skip to content

Commit 9464cd0

Browse files
leburgelclaude
andcommitted
Time the subblock groups and test permutations across the group threshold
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5ea4742 commit 9464cd0

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎src/tensors/indexmanipulations.jl‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,9 @@ function add_transform_kernel!(
662662
dst::StridedSubblocks{<:CPUStorage}, src::StridedSubblocks{<:CPUStorage}, p, conjsrc::Bool,
663663
transformer::TreeTransformer, α, β, backend, allocator, ntasks::Int
664664
)
665-
_add_subblockgroups!(dst.data, src.data, conjsrc, transformer.groups, α, β, ntasks)
665+
@timeit_debug GLOBAL_TIMER "dense: subblock groups" _add_subblockgroups!(
666+
dst.data, src.data, conjsrc, transformer.groups, α, β, ntasks
667+
)
666668
large = view(transformer.data, transformer.large)
667669
return _add_transform_blocks!(dst, src, p, conjsrc, transformer, large, α, β, backend, allocator, ntasks)
668670
end

‎src/tensors/treetransformers.jl‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ function UniqueTreeTransformer(::Type{A}, transform, p, Vdst::HomSpace, Vsrc::Ho
117117

118118
structure_dst = degeneracystructure(Vdst).subblockstructure
119119
structure_src = degeneracystructure(Vsrc).subblockstructure
120-
groups, large = subblockgroups(T, data, structure_dst, structure_src, linearize(p))
120+
groups, large = @timeit_debug GLOBAL_TIMER "bookkeeping: subblock groups" subblockgroups(
121+
T, data, structure_dst, structure_src, linearize(p)
122+
)
121123
transformer = UniqueTreeTransformer(data, structure_dst, structure_src, groups, large)
122124

123125
Δt = Base.time() - t₀
@@ -170,7 +172,9 @@ function GenericTreeTransformer(::Type{A}, transform, p, Vdst::HomSpace, Vsrc::H
170172

171173
# sort by (approximate) weight to facilitate multi-threading strategies
172174
@timeit_debug GLOBAL_TIMER "bookkeeping: sort" Base.permute!(data, sortperm(weights; rev = true))
173-
groups, large = subblockgroups(T, data, structure_dst, structure_src, linearize(p))
175+
groups, large = @timeit_debug GLOBAL_TIMER "bookkeeping: subblock groups" subblockgroups(
176+
T, data, structure_dst, structure_src, linearize(p)
177+
)
174178
transformer = GenericTreeTransformer{T, numind(Vdst)}(data, structure_dst, structure_src, groups, large)
175179

176180
Δt = Base.time() - t₀

‎test/tensors/indexmanipulations.jl‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,14 @@ for V in spacelist
235235
end
236236
TensorKit.empty_globalcaches!()
237237
end
238+
239+
@timedtestset "Permutations with small and large subblocks" begin
240+
# subblocks up to `SUBBLOCKGROUP_MAXLENGTH` entries are transformed in groups, larger ones one by one
241+
V = Vect[SU2Irrep](0 => 6, 1 // 2 => 6, 1 => 1)
242+
t = rand(ComplexF64, V ⊗ V ⊗ V ← V)
243+
@test maximum(length ∘ last, subblocks(t)) > TensorKit.SUBBLOCKGROUP_MAXLENGTH
244+
a = convert(Array, t)
245+
for p in (((1, 4), (2, 3)), ((3, 1, 4), (2,)))
246+
@test convert(Array, permute(t, p)) ≈ permutedims(a, (p[1]..., p[2]...))
247+
end
248+
end

0 commit comments

Comments
 (0)