Skip to content

Commit 5857ac6

Browse files
committed
remove unused constructors
[pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci
1 parent bc0988a commit 5857ac6

3 files changed

Lines changed: 19 additions & 160 deletions

File tree

src/fusedgradedmatrix.jl

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -86,51 +86,6 @@ function FusedGradedMatrix(
8686
return FusedGradedMatrix(cod, dom, blks)
8787
end
8888

89-
function FusedGradedMatrix(pairs::AbstractVector{<:Pair{<:SectorRange}})
90-
return FusedGradedMatrix(first.(pairs), last.(pairs))
91-
end
92-
93-
# ======================== undef constructors ========================
94-
95-
# Symmetric `undef` constructor: same sector list on both axes.
96-
function FusedGradedMatrix{T, D, S}(
97-
::UndefInitializer,
98-
sectors::AbstractVector{S},
99-
axes::Tuple{BlockedOneTo, BlockedOneTo}
100-
) where {T, D <: AbstractMatrix{T}, S <: SectorRange}
101-
blocklength(axes[1]) == blocklength(axes[2]) == length(sectors) ||
102-
throw(ArgumentError("axes block counts must match sectors length"))
103-
issorted(sectors) || throw(ArgumentError("sectors must be sorted"))
104-
allunique(sectors) || throw(ArgumentError("sectors must be unique"))
105-
cod = Dictionary{S, Int}(sectors, map(length, eachblockaxis(axes[1])))
106-
dom = Dictionary{S, Int}(sectors, map(length, eachblockaxis(axes[2])))
107-
return FusedGradedMatrix{T, D, S}(undef, cod, dom)
108-
end
109-
110-
# Convenience: default D = Matrix{T}.
111-
function FusedGradedMatrix{T}(
112-
::UndefInitializer, sectors::AbstractVector{<:SectorRange},
113-
axes::Tuple{BlockedOneTo, BlockedOneTo}
114-
) where {T}
115-
S = eltype(sectors)
116-
return FusedGradedMatrix{T, Matrix{T}, S}(undef, sectors, axes)
117-
end
118-
119-
# Vector{Int} convenience: wraps into BlockedOneTo and delegates.
120-
function FusedGradedMatrix{T}(
121-
::UndefInitializer,
122-
sectors::AbstractVector{<:SectorRange},
123-
codomain_blocklengths::AbstractVector{Int},
124-
domain_blocklengths::AbstractVector{Int}
125-
) where {T}
126-
S = eltype(sectors)
127-
issorted(sectors) || throw(ArgumentError("sectors must be sorted"))
128-
allunique(sectors) || throw(ArgumentError("sectors must be unique"))
129-
cod = Dictionary{S, Int}(sectors, codomain_blocklengths)
130-
dom = Dictionary{S, Int}(sectors, domain_blocklengths)
131-
return FusedGradedMatrix{T}(undef, cod, dom)
132-
end
133-
13489
function FusedGradedMatrix{T}(
13590
::UndefInitializer, codomain::Dictionary{S, Int}, domain::Dictionary{S, Int}
13691
) where {T, S <: SectorRange}
@@ -363,9 +318,6 @@ end
363318

364319
# ======================== Conversion from AbelianGradedArray ========================
365320

366-
# Identity
367-
FusedGradedMatrix(m::FusedGradedMatrix) = m
368-
369321
"""
370322
FusedGradedMatrix(a::AbelianGradedMatrix{T})
371323

src/fusedgradedvector.jl

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -142,44 +142,6 @@ function FusedGradedVector(
142142
return FusedGradedVector(ax, blks)
143143
end
144144

145-
function FusedGradedVector(pairs::AbstractVector{<:Pair{<:SectorRange}})
146-
return FusedGradedVector(first.(pairs), last.(pairs))
147-
end
148-
149-
# ======================== undef constructors ========================
150-
151-
function FusedGradedVector{T, D, S}(
152-
::UndefInitializer,
153-
sectors::AbstractVector{S},
154-
ax::BlockedOneTo
155-
) where {T, D <: AbstractVector{T}, S <: SectorRange}
156-
blocklength(ax) == length(sectors) ||
157-
throw(ArgumentError("axis block count must match sectors length"))
158-
issorted(sectors) || throw(ArgumentError("sectors must be sorted"))
159-
allunique(sectors) || throw(ArgumentError("sectors must be unique"))
160-
axis = Dictionary{S, Int}(sectors, map(length, eachblockaxis(ax)))
161-
return FusedGradedVector{T, D, S}(undef, axis)
162-
end
163-
164-
function FusedGradedVector{T}(
165-
::UndefInitializer, sectors::AbstractVector{<:SectorRange}, ax::BlockedOneTo
166-
) where {T}
167-
S = eltype(sectors)
168-
return FusedGradedVector{T, Vector{T}, S}(undef, sectors, ax)
169-
end
170-
171-
function FusedGradedVector{T}(
172-
::UndefInitializer,
173-
sectors::AbstractVector{<:SectorRange},
174-
blocklengths::AbstractVector{Int}
175-
) where {T}
176-
S = eltype(sectors)
177-
issorted(sectors) || throw(ArgumentError("sectors must be sorted"))
178-
allunique(sectors) || throw(ArgumentError("sectors must be unique"))
179-
axis = Dictionary{S, Int}(sectors, blocklengths)
180-
return FusedGradedVector{T}(undef, axis)
181-
end
182-
183145
function FusedGradedVector{T}(
184146
::UndefInitializer, axis::Dictionary{S, Int}
185147
) where {T, S <: SectorRange}
@@ -331,31 +293,3 @@ function LinearAlgebra.norm(A::FusedGradedVector, p::Real = 2)
331293
throw(ArgumentError("Norm with non-positive p ($p) is not defined"))
332294
end
333295
end
334-
335-
# ======================== Conversion from AbelianGradedArray ========================
336-
337-
# Identity
338-
FusedGradedVector(v::FusedGradedVector) = v
339-
340-
"""
341-
FusedGradedVector(a::AbelianGradedVector{T})
342-
343-
Convert a 1D block-sparse `AbelianGradedArray` into a `FusedGradedVector`.
344-
The axis dict comes from the axis sectors and lengths; stored entries of `a`
345-
populate `blocks`.
346-
"""
347-
function FusedGradedVector(a::AbelianGradedVector{T}) where {T}
348-
S = sectortype(a)
349-
ax_sectors = sectors(axes(a, 1))
350-
issorted(ax_sectors) ||
351-
throw(ArgumentError("axis sectors of input must be sorted"))
352-
allunique(ax_sectors) ||
353-
throw(ArgumentError("axis sectors of input must be unique"))
354-
axis = Dictionary{S, Int}(ax_sectors, datalengths(axes(a, 1)))
355-
356-
v = FusedGradedVector{T, datatype(a), S}(undef, axis)
357-
for I in eachblockstoredindex(a)
358-
view(v, I) .= view(a, I)
359-
end
360-
return v
361-
end

test/test_abelianarray.jl

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using BlockArrays: BlockArrays, Block, blockedrange, blocklength
1+
using BlockArrays: BlockArrays, Block, blocklength
22
using BlockSparseArrays: eachblockstoredindex
33
using Dictionaries: Dictionary
44
using GradedArrays: GradedArrays, AbelianGradedArray, AbelianSectorArray,
@@ -216,8 +216,8 @@ using Test: @test, @test_throws, @testset
216216
end
217217
end
218218

219-
@testset "FusedGradedMatrix Pair constructor" begin
220-
m = FusedGradedMatrix([U1(0) => [1.0 2.0; 3.0 4.0], U1(1) => ones(3, 3)])
219+
@testset "FusedGradedMatrix sectors/blocks constructor" begin
220+
m = FusedGradedMatrix([U1(0), U1(1)], [[1.0 2.0; 3.0 4.0], ones(3, 3)])
221221
@test m isa FusedGradedMatrix{Float64}
222222
@test data(m[Block(1, 1)]) == [1.0 2.0; 3.0 4.0]
223223
@test data(m[Block(2, 2)]) == ones(3, 3)
@@ -226,11 +226,8 @@ end
226226
# dimension `2j + 1`, so `Block(k, k)` has size
227227
# `(sectorlength × datalength)^2`.
228228
m_su2 = FusedGradedMatrix(
229-
[
230-
SU2(0) => [1.0;;],
231-
SU2(1 // 2) => [1.0 2.0; 3.0 4.0],
232-
SU2(1) => Matrix{Float64}(LinearAlgebra.I, 3, 3),
233-
]
229+
[SU2(0), SU2(1 // 2), SU2(1)],
230+
[[1.0;;], [1.0 2.0; 3.0 4.0], Matrix{Float64}(LinearAlgebra.I, 3, 3)]
234231
)
235232
@test m_su2 isa FusedGradedMatrix{Float64, Matrix{Float64}, SU2}
236233
@test collect(keys(m_su2.blocks)) == [SU2(0), SU2(1 // 2), SU2(1)]
@@ -242,75 +239,51 @@ end
242239

243240
@testset "FusedGradedMatrix * FusedGradedMatrix" begin
244241
@testset "U1 (abelian)" begin
245-
a = FusedGradedMatrix([U1(0) => [2.0;;], U1(1) => [1.0 2.0; 3.0 4.0]])
246-
b = FusedGradedMatrix([U1(0) => [3.0;;], U1(1) => [0.0 1.0; 1.0 0.0]])
242+
a = FusedGradedMatrix([U1(0), U1(1)], [[2.0;;], [1.0 2.0; 3.0 4.0]])
243+
b = FusedGradedMatrix([U1(0), U1(1)], [[3.0;;], [0.0 1.0; 1.0 0.0]])
247244
c = a * b
248245
@test collect(keys(c.blocks)) == [U1(0), U1(1)]
249246
@test data(c[Block(1, 1)]) == [6.0;;]
250247
@test data(c[Block(2, 2)]) == [1.0 2.0; 3.0 4.0] * [0.0 1.0; 1.0 0.0]
251248
end
252249
@testset "SU2 (non-abelian)" begin
253-
a = FusedGradedMatrix([SU2(0) => [2.0;;], SU2(1 // 2) => [1.0 2.0; 3.0 4.0]])
254-
b = FusedGradedMatrix([SU2(0) => [3.0;;], SU2(1 // 2) => [0.0 1.0; 1.0 0.0]])
250+
a = FusedGradedMatrix([SU2(0), SU2(1 // 2)], [[2.0;;], [1.0 2.0; 3.0 4.0]])
251+
b = FusedGradedMatrix([SU2(0), SU2(1 // 2)], [[3.0;;], [0.0 1.0; 1.0 0.0]])
255252
c = a * b
256253
@test collect(keys(c.blocks)) == [SU2(0), SU2(1 // 2)]
257254
@test data(c[Block(1, 1)]) == [6.0;;]
258255
@test data(c[Block(2, 2)]) == [1.0 2.0; 3.0 4.0] * [0.0 1.0; 1.0 0.0]
259256
end
260257
@testset "mismatched sectors throws" begin
261-
a = FusedGradedMatrix([U1(0) => [2.0;;], U1(1) => [1.0 2.0; 3.0 4.0]])
262-
b = FusedGradedMatrix([U1(0) => [3.0;;]])
258+
a = FusedGradedMatrix([U1(0), U1(1)], [[2.0;;], [1.0 2.0; 3.0 4.0]])
259+
b = FusedGradedMatrix([U1(0)], [[3.0;;]])
263260
@test_throws DimensionMismatch a * b
264261
end
265262
end
266263

267264
@testset "FusedGradedMatrix undef constructor" begin
268265
sectors = [U1(0), U1(1)]
269-
cod_bls = [2, 3]
270-
dom_bls = [1, 2]
266+
cod = Dictionary{U1, Int}(sectors, [2, 3])
267+
dom = Dictionary{U1, Int}(sectors, [1, 2])
271268

272-
@testset "Convenience constructor (defaults D = Matrix{T})" begin
273-
m = FusedGradedMatrix{Float64}(undef, sectors, cod_bls, dom_bls)
269+
@testset "Default D = Matrix{T}" begin
270+
m = FusedGradedMatrix{Float64}(undef, cod, dom)
274271
@test m isa FusedGradedMatrix{Float64, Matrix{Float64}, U1}
275272
@test length(m.blocks) == 2
276273
@test collect(keys(m.blocks)) == sectors
277274
@test size(m.blocks[U1(0)]) == (2, 1)
278275
@test size(m.blocks[U1(1)]) == (3, 2)
279276
end
280277

281-
@testset "Fully parameterized constructor" begin
282-
m = FusedGradedMatrix{Float64, Matrix{Float64}, U1}(
283-
undef, sectors, (blockedrange(cod_bls), blockedrange(dom_bls))
284-
)
278+
@testset "Fully parameterized" begin
279+
m = FusedGradedMatrix{Float64, Matrix{Float64}, U1}(undef, cod, dom)
285280
@test m isa FusedGradedMatrix{Float64, Matrix{Float64}, U1}
286281
@test size(m.blocks[U1(0)]) == (2, 1)
287282
end
288283

289-
@testset "Tuple BlockedOneTo form" begin
290-
m = FusedGradedMatrix{Float64}(
291-
undef, sectors, (blockedrange([2, 3]), blockedrange([1, 2]))
292-
)
293-
@test m isa FusedGradedMatrix{Float64, Matrix{Float64}, U1}
294-
@test size(m.blocks[U1(0)]) == (2, 1)
295-
@test size(m.blocks[U1(1)]) == (3, 2)
296-
end
297-
298-
@testset "Rejects mismatched lengths" begin
299-
@test_throws Exception FusedGradedMatrix{Float64}(
300-
undef, sectors, cod_bls, [1]
301-
)
302-
end
303-
304284
@testset "Rejects unsorted sectors" begin
305-
@test_throws ArgumentError FusedGradedMatrix{Float64}(
306-
undef, [U1(1), U1(0)], cod_bls, dom_bls
307-
)
308-
end
309-
310-
@testset "Rejects non-unique sectors" begin
311-
@test_throws ArgumentError FusedGradedMatrix{Float64}(
312-
undef, [U1(0), U1(0)], [2, 3], [1, 2]
313-
)
285+
cod_bad = Dictionary{U1, Int}([U1(1), U1(0)], [2, 3])
286+
@test_throws ArgumentError FusedGradedMatrix{Float64}(undef, cod_bad, dom)
314287
end
315288
end
316289

0 commit comments

Comments
 (0)