|
1 | | -using BlockArrays: AbstractBlockedUnitRange |
| 1 | +using BlockArrays: AbstractBlockedUnitRange, blocklengths |
2 | 2 |
|
3 | 3 | # Represents the range `1:1` or `Base.OneTo(1)`. |
4 | 4 | struct OneToOne{T} <: AbstractUnitRange{T} end |
@@ -48,24 +48,23 @@ function fuse_labels(x, y) |
48 | 48 | end |
49 | 49 |
|
50 | 50 | function fuse_blocklengths(x::Integer, y::Integer) |
51 | | - return x * y |
| 51 | + # return blocked unit range to keep non-abelian interface |
| 52 | + return blockedrange([x * y]) |
52 | 53 | end |
53 | 54 |
|
54 | 55 | using ..LabelledNumbers: LabelledInteger, label, labelled, unlabel |
55 | 56 | function fuse_blocklengths(x::LabelledInteger, y::LabelledInteger) |
56 | | - return labelled(unlabel(x) * unlabel(y), fuse_labels(label(x), label(y))) |
| 57 | + # return blocked unit range to keep non-abelian interface |
| 58 | + return blockedrange([labelled(x * y, fuse_labels(label(x), label(y)))]) |
57 | 59 | end |
58 | 60 |
|
59 | | -flatten_maybe_nested(v::Vector{<:Integer}) = v |
60 | | -flatten_maybe_nested(v::Vector{<:AbstractGradedUnitRange}) = reduce(vcat, blocklengths.(v)) |
61 | | - |
62 | 61 | using BlockArrays: blockedrange, blocks |
63 | 62 | function tensor_product(a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRange) |
64 | | - maybe_nested = map(Iterators.flatten((Iterators.product(blocks(a1), blocks(a2)),))) do it |
| 63 | + nested = map(Iterators.flatten((Iterators.product(blocks(a1), blocks(a2)),))) do it |
65 | 64 | return mapreduce(length, fuse_blocklengths, it) |
66 | 65 | end |
67 | | - blocklengths = flatten_maybe_nested(maybe_nested) |
68 | | - return blockedrange(blocklengths) |
| 66 | + new_blocklengths = reduce(vcat, blocklengths.(nested)) |
| 67 | + return blockedrange(new_blocklengths) |
69 | 68 | end |
70 | 69 |
|
71 | 70 | # convention: sort UnitRangeDual according to nondual blocks |
|
0 commit comments