Skip to content

Commit

Permalink
migrate imports to toplevel
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Dec 10, 2024
1 parent ec7e36c commit 8fcf6f8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 74 deletions.
47 changes: 47 additions & 0 deletions src/GradedUnitRanges.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
module GradedUnitRanges

using BlockArrays:
BlockArrays,
AbstractBlockVector,
AbstractBlockedUnitRange,
Block,
BlockIndex,
BlockRange,
BlockSlice,
BlockVector,
BlockedOneTo,
BlockedUnitRange,
BlockedVector,
blockedrange,
BlockIndexRange,
block,
blocks,
blockaxes,
blockfirsts,
blocklasts,
blockisequal,
blocklength,
blocklengths,
blockindex,
findblock,
findblockindex,
combine_blockaxes,
mortar,
sortedunion
using Compat: allequal
using FillArrays: Fill
using LabelledNumbers:
LabelledNumbers,
LabelledInteger,
LabelledUnitRange,
LabelledStyle,
IsLabelled,
NotLabelled,
label,
label_type,
labelled,
labelled_isequal,
unlabel,
islabelled
using SplitApplyCombine: groupcount

include("blockedunitrange.jl")
include("gradedunitrange.jl")
include("dual.jl")
include("labelledunitrangedual.jl")
include("gradedunitrangedual.jl")
include("onetoone.jl")
include("fusion.jl")

end
18 changes: 0 additions & 18 deletions src/blockedunitrange.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
using BlockArrays:
BlockArrays,
AbstractBlockVector,
AbstractBlockedUnitRange,
Block,
BlockIndex,
BlockIndexRange,
BlockRange,
BlockSlice,
BlockVector,
BlockedOneTo,
BlockedUnitRange,
BlockedVector,
block,
blockindex,
findblock,
findblockindex

# Custom `BlockedUnitRange` constructor that takes a unit range
# and a set of block lengths, similar to `BlockArray(::AbstractArray, blocklengths...)`.
function blockedunitrange(a::AbstractUnitRange, blocklengths)
Expand Down
2 changes: 0 additions & 2 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ dual_type(T::Type) = T
nondual_type(x) = nondual_type(typeof(x))
nondual_type(T::Type) = T

using LabelledNumbers: LabelledStyle, IsLabelled, NotLabelled, label, labelled, unlabel

dual(i::LabelledInteger) = labelled(unlabel(i), dual(label(i)))
label_dual(x) = label_dual(LabelledStyle(x), x)
label_dual(::NotLabelled, x) = x
Expand Down
6 changes: 0 additions & 6 deletions src/fusion.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using BlockArrays: AbstractBlockedUnitRange, blocklengths

# https://github.com/ITensor/ITensors.jl/blob/v0.3.57/NDTensors/src/lib/GradedAxes/src/tensor_product.jl
# https://en.wikipedia.org/wiki/Tensor_product
# https://github.com/KeitaNakamura/Tensorial.jl
Expand Down Expand Up @@ -45,13 +43,11 @@ function fuse_blocklengths(x::Integer, y::Integer)
return blockedrange([x * y])
end

using LabelledNumbers: LabelledInteger, label, labelled, unlabel
function fuse_blocklengths(x::LabelledInteger, y::LabelledInteger)
# return blocked unit range to keep non-abelian interface
return blockedrange([labelled(x * y, fuse_labels(label(x), label(y)))])
end

using BlockArrays: blockedrange, blocks
function tensor_product(a1::AbstractBlockedUnitRange, a2::AbstractBlockedUnitRange)
nested = map(Iterators.flatten((Iterators.product(blocks(a1), blocks(a2)),))) do it
return mapreduce(length, fuse_blocklengths, it)
Expand All @@ -65,8 +61,6 @@ function blocksortperm(a::AbstractUnitRange)
return Block.(sortperm(blocklabels(nondual(a))))
end

using BlockArrays: Block, BlockVector
using SplitApplyCombine: groupcount
# Get the permutation for sorting, then group by common elements.
# groupsortperm([2, 1, 2, 3]) == [[2], [1, 3], [4]]
function groupsortperm(v; kwargs...)
Expand Down
35 changes: 1 addition & 34 deletions src/gradedunitrange.jl
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
using BlockArrays:
BlockArrays,
AbstractBlockVector,
AbstractBlockedUnitRange,
Block,
BlockIndex,
BlockRange,
BlockSlice,
BlockVector,
BlockedOneTo,
BlockedUnitRange,
blockedrange,
BlockIndexRange,
blockfirsts,
blockisequal,
blocklength,
blocklengths,
findblock,
findblockindex,
mortar,
sortedunion
using Compat: allequal
using FillArrays: Fill
using LabelledNumbers:
LabelledNumbers,
LabelledInteger,
LabelledUnitRange,
label,
label_type,
labelled,
labelled_isequal,
unlabel

abstract type AbstractGradedUnitRange{T,BlockLasts} <:
AbstractBlockedUnitRange{T,BlockLasts} end

Expand Down Expand Up @@ -71,7 +38,7 @@ blocklabels(r::AbstractUnitRange) = Fill(NoLabel(), blocklength(r))
blocklabels(la::LabelledUnitRange) = [label(la)]

function LabelledNumbers.labelled_isequal(a1::AbstractUnitRange, a2::AbstractUnitRange)
# TODO: fix type piracy
# TODO: fix type piracy
return blockisequal(a1, a2) && (blocklabels(a1) == blocklabels(a2))
end

Expand Down
9 changes: 0 additions & 9 deletions src/gradedunitrangedual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ function blockedunitrange_getindices(
return dual(getindex(nondual(a), indices))
end

using BlockArrays: Block, BlockIndexRange, BlockRange

function blockedunitrange_getindices(a::GradedUnitRangeDual, indices::Integer)
return label_dual(getindex(nondual(a), indices))
end
Expand Down Expand Up @@ -111,26 +109,19 @@ end

Base.axes(a::GradedUnitRangeDual) = axes(nondual(a))

using BlockArrays: BlockArrays, Block, BlockSlice
using LabelledNumbers: LabelledUnitRange
function BlockArrays.BlockSlice(b::Block, a::LabelledUnitRange)
return BlockSlice(b, unlabel(a))
end

using BlockArrays: BlockArrays, BlockSlice
using GradedUnitRanges: GradedUnitRangeDual, dual
function BlockArrays.BlockSlice(b::Block, r::GradedUnitRangeDual)
return BlockSlice(b, dual(r))
end

using LabelledNumbers: LabelledNumbers, LabelledUnitRange, label
function Base.iterate(a::GradedUnitRangeDual, i)
i == last(a) && return nothing
return dual.(iterate(nondual(a), i))
end

using LabelledNumbers: LabelledInteger, label, labelled, unlabel
using BlockArrays: BlockArrays, blockaxes, blocklasts, combine_blockaxes, findblock
BlockArrays.blockaxes(a::GradedUnitRangeDual) = blockaxes(nondual(a))
BlockArrays.blockfirsts(a::GradedUnitRangeDual) = label_dual.(blockfirsts(nondual(a)))
BlockArrays.blocklasts(a::GradedUnitRangeDual) = label_dual.(blocklasts(nondual(a)))
Expand Down
2 changes: 0 additions & 2 deletions src/labelledunitrangedual.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# LabelledUnitRangeDual is obtained by slicing a GradedUnitRangeDual with a block

using LabelledNumbers: LabelledNumbers, label, labelled, unlabel

struct LabelledUnitRangeDual{T,NondualUnitRange<:AbstractUnitRange{T}} <:
AbstractUnitRange{T}
nondual_unitrange::NondualUnitRange
Expand Down
3 changes: 0 additions & 3 deletions src/onetoone.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using BlockArrays: AbstractBlockedUnitRange
using LabelledNumbers: islabelled

# Represents the range `1:1` or `Base.OneTo(1)`.
struct OneToOne{T} <: AbstractUnitRange{T} end
OneToOne() = OneToOne{Bool}()
Expand Down

0 comments on commit 8fcf6f8

Please sign in to comment.