Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finish merging
Browse files Browse the repository at this point in the history
ogauthe committed Oct 28, 2024
1 parent 3f6bd2e commit 8a353bd
Showing 2 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using BlockArrays:
AbstractBlockedUnitRange,
BlockArrays,
Block,
BlockIndexRange,
BlockedVector,
blocklength,
blocksize,
viewblock
BlockArrays, Block, BlockIndexRange, BlockedVector, blocklength, blocksize, viewblock

# This splits `BlockIndexRange{N}` into
# `NTuple{N,BlockIndexRange{1}}`.
21 changes: 6 additions & 15 deletions NDTensors/src/lib/GradedAxes/src/fusion.jl
Original file line number Diff line number Diff line change
@@ -51,9 +51,6 @@ function fuse_blocklengths(x::LabelledInteger, y::LabelledInteger)
return blockedrange([labelled(x * y, fuse_labels(label(x), label(y)))])
end

flatten_maybe_nested(v::Vector{<:Integer}) = v
flatten_maybe_nested(v::Vector{<:AbstractGradedUnitRange}) = reduce(vcat, blocklengths.(v))

using BlockArrays: blockedrange, blocks
function tensor_product(a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRange)
nested = map(Iterators.flatten((Iterators.product(blocks(a1), blocks(a2)),))) do it
@@ -63,13 +60,8 @@ function tensor_product(a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRan
return blockedrange(new_blocklengths)
end

# convention: sort UnitRangeDual according to nondual blocks
function blocksortperm(a::AbstractUnitRange)
return Block.(sortperm(blocklabels(nondual(a))))
end

# convention: sort GradedUnitRangeDual according to nondual blocks
function blocksortperm(a::GradedUnitRangeDual)
function blocksortperm(a::AbstractUnitRange)
return Block.(sortperm(blocklabels(nondual(a))))
end

@@ -102,14 +94,13 @@ end
function blockmergesort(g::AbstractGradedUnitRange)
glabels = blocklabels(g)
gblocklengths = blocklengths(g)
new_blocklengths = map(
la -> labelled(sum(gblocklengths[findall(==(la), glabels)]; init=0), la),
sort(unique(glabels)),
)
return GradedAxes.gradedrange(new_blocklengths)
new_blocklengths = map(sort(unique(glabels))) do la
return labelled(sum(gblocklengths[findall(==(la), glabels)]; init=0), la)
end
return gradedrange(new_blocklengths)
end

blockmergesort(g::GradedUnitRangeDual) = dual(blockmergesort(flip(g)))
blockmergesort(g::GradedUnitRangeDual) = flip(blockmergesort(flip(g)))

# fusion_product produces a sorted, non-dual GradedUnitRange
function fusion_product(g1, g2)

0 comments on commit 8a353bd

Please sign in to comment.