From 8a353bdf7a902a6166412a55394cd03ac2c95b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Mon, 28 Oct 2024 17:01:48 -0400 Subject: [PATCH] finish merging --- .../src/abstractblocksparsearray/views.jl | 9 +------- NDTensors/src/lib/GradedAxes/src/fusion.jl | 21 ++++++------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/views.jl b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/views.jl index a07ba72913..e409ed5500 100644 --- a/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/views.jl +++ b/NDTensors/src/lib/BlockSparseArrays/src/abstractblocksparsearray/views.jl @@ -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}}`. diff --git a/NDTensors/src/lib/GradedAxes/src/fusion.jl b/NDTensors/src/lib/GradedAxes/src/fusion.jl index 320244ea75..1a6d98f318 100644 --- a/NDTensors/src/lib/GradedAxes/src/fusion.jl +++ b/NDTensors/src/lib/GradedAxes/src/fusion.jl @@ -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)