Skip to content

Commit 32d0f11

Browse files
committed
add tests
1 parent dc762be commit 32d0f11

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/test/runtests.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using NDTensors.GradedAxes:
88
using NDTensors.LabelledNumbers: label
99
using NDTensors.SparseArrayInterface: nstored
1010
using NDTensors.TensorAlgebra: fusedims, splitdims
11+
using LinearAlgebra: adjoint
1112
using Random: randn!
1213
function blockdiagonal!(f, a::AbstractArray)
1314
for i in 1:minimum(blocksize(a))
@@ -38,8 +39,6 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
3839
@test blocklengths.(axes(b)) == ([2, 2], [2, 2], [2, 2], [2, 2])
3940
@test nstored(b) == 32
4041
@test block_nstored(b) == 2
41-
# TODO: Have to investigate why this fails
42-
# on Julia v1.6, or drop support for v1.6.
4342
for i in 1:ndims(a)
4443
@test axes(b, i) isa GradedOneTo
4544
end
@@ -158,11 +157,11 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
158157
b = 2 * a
159158
@test block_nstored(b) == 2
160159
@test Array(b) == 2 * Array(a)
161-
@test a[:, :] isa BlockSparseArray
162-
for ax in axes(b)
163-
@test ax isa GradedUnitRangeDual
160+
@test a[:, :] isa BlockSparseArray # broken in 1.6
161+
for i in 1:2
162+
@test axes(b, i) isa GradedUnitRangeDual
163+
@test_broken axes(a[:, :], i) isa GradedUnitRangeDual
164164
end
165-
166165
I = [Block(1)[1:1]]
167166
@test_broken a[I, :]
168167
@test_broken a[:, I]
@@ -179,9 +178,10 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
179178
b = 2 * a
180179
@test block_nstored(b) == 2
181180
@test Array(b) == 2 * Array(a)
182-
@test a[:, :] isa BlockSparseArray
183-
for ax in axes(b)
184-
@test ax isa GradedUnitRangeDual
181+
@test a[:, :] isa BlockSparseArray # broken in 1.6
182+
for i in 1:2
183+
@test axes(b, i) isa GradedUnitRangeDual
184+
@test_broken axes(a[:, :], i) isa GradedUnitRangeDual
185185
end
186186

187187
I = [Block(1)[1:1]]
@@ -191,7 +191,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
191191
@test_broken GradedAxes.isdual(axes(a[I, I], 1))
192192
end
193193

194-
@testset "BlockedUnitRange" begin
194+
@testset "BlockedUnitRange" begin # self dual
195195
r = blockedrange([2, 2])
196196
a = BlockSparseArray{elt}(dual(r), dual(r))
197197
@views for i in [Block(1, 1), Block(2, 2)]
@@ -201,8 +201,9 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
201201
@test block_nstored(b) == 2
202202
@test Array(b) == 2 * Array(a)
203203
@test a[:, :] isa BlockSparseArray
204-
for ax in axes(b)
205-
@test ax isa BlockedOneTo
204+
for i in 1:2
205+
@test axes(b, i) isa BlockedOneTo
206+
@test axes(a[:, :], i) isa BlockedOneTo
206207
end
207208

208209
I = [Block(1)[1:1]]
@@ -226,7 +227,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
226227
@test ax isa typeof(dual(r))
227228
end
228229

229-
@test a[:, :] isa BlockSparseArray
230+
@test a[:, :] isa BlockSparseArray # broken in 1.6
231+
@test axes(a[:, :]) isa Tuple{BlockedOneTo,BlockedOneTo} # broken in 1.6
230232

231233
I = [Block(1)[1:1]]
232234
@test size(a[I, :]) == (1, 4)

NDTensors/src/lib/GradedAxes/test/test_dual.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@eval module $(gensym())
22
using BlockArrays:
33
Block,
4+
BlockedOneTo,
45
blockaxes,
56
blockedrange,
67
blockfirsts,
@@ -32,19 +33,22 @@ Base.isless(c1::U1, c2::U1) = c1.n < c2.n
3233

3334
@testset "AbstractUnitRange" begin
3435
a0 = OneToOne()
35-
@test gradedisequal(a0, dual(a0))
3636
@test !isdual(a0)
37+
@test dual(a0) isa OneToOne
38+
@test gradedisequal(a0, dual(a0))
3739

3840
a = 1:3
3941
ad = dual(a)
40-
@test !isdual(ad)
4142
@test !isdual(a)
43+
@test !isdual(ad)
44+
@test ad isa UnitRange
4245
@test gradedisequal(ad, a)
4346

4447
a = blockedrange([2, 3])
4548
ad = dual(a)
46-
@test !isdual(ad)
4749
@test !isdual(a)
50+
@test !isdual(ad)
51+
@test ad isa BlockedOneTo
4852
@test gradedisequal(ad, a)
4953
end
5054

0 commit comments

Comments
 (0)