Skip to content

Commit 60ec997

Browse files
authored
Fix tests (#31)
1 parent 10ea80c commit 60ec997

File tree

11 files changed

+34
-25
lines changed

11 files changed

+34
-25
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.2.9"
4+
version = "0.2.10"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -11,6 +11,7 @@ DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
1111
DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77"
1212
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
1313
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
14+
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
1415
GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5"
1516
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1617
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
@@ -24,7 +25,6 @@ LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993"
2425
TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
2526

2627
[extensions]
27-
BlockSparseArraysAdaptExt = "Adapt"
2828
BlockSparseArraysTensorAlgebraExt = ["LabelledNumbers", "TensorAlgebra"]
2929

3030
[compat]

src/BlockSparseArrays.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ include("abstractblocksparsearray/broadcast.jl")
3535
include("abstractblocksparsearray/map.jl")
3636
include("abstractblocksparsearray/linearalgebra.jl")
3737
include("abstractblocksparsearray/cat.jl")
38+
include("abstractblocksparsearray/adapt.jl")
3839

3940
# functions specifically for BlockSparseArray
4041
include("blocksparsearray/defaults.jl")

src/abstractblocksparsearray/abstractblocksparsearray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ function Base.setindex!(a::AbstractBlockSparseArray{<:Any,0}, value)
5757
return a
5858
end
5959

60+
# Catch zero-dimensional case to avoid scalar indexing.
61+
function Base.setindex!(a::AbstractBlockSparseArray{<:Any,0}, value, ::Block{0})
62+
blocks(a)[] = value
63+
return a
64+
end
65+
6066
function Base.setindex!(
6167
a::AbstractBlockSparseArray{<:Any,N}, value, I::Vararg{Block{1},N}
6268
) where {N}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
module BlockSparseArraysAdaptExt
21
using Adapt: Adapt, adapt
3-
using BlockSparseArrays: AbstractBlockSparseArray, map_stored_blocks
42
Adapt.adapt_structure(to, x::AbstractBlockSparseArray) = map_stored_blocks(adapt(to), x)
5-
end

src/abstractblocksparsearray/map.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ArrayLayouts: LayoutArray
22
using BlockArrays: blockisequal
33
using DerivableInterfaces: @interface, AbstractArrayInterface, interface
4+
using GPUArraysCore: @allowscalar
45
using LinearAlgebra: Adjoint, Transpose
56
using SparseArraysBase: SparseArraysBase, SparseArrayStyle
67

@@ -55,7 +56,7 @@ function map_zero_dim! end
5556
@interface ::AbstractArrayInterface function map_zero_dim!(
5657
f, a_dest::AbstractArray, a_srcs::AbstractArray...
5758
)
58-
a_dest[] = f.(map(a_src -> a_src[], a_srcs)...)
59+
@allowscalar a_dest[] = f.(map(a_src -> a_src[], a_srcs)...)
5960
return a_dest
6061
end
6162

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ end
6565
@interface ::AbstractBlockSparseArrayInterface function Base.getindex(
6666
a::AbstractArray{<:Any,0}
6767
)
68-
# TODO: Use `Block()[]` once https://github.com/JuliaArrays/BlockArrays.jl/issues/430
69-
# is fixed.
70-
return a[BlockIndex()]
68+
return a[Block()[]]
7169
end
7270

7371
# a[1:2, 1:2]

test/basics/test_basics.jl renamed to test/test_basics.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,15 @@ arrayts = (Array, JLArray)
187187
@test iszero(@allowscalar(a[CartesianIndex()]))
188188
@test a[Block()] == dev(fill(0))
189189
@test iszero(@allowscalar(a[Block()][]))
190-
@test @allowscalar(a[Block()[]]) == 0
190+
@test iszero(@allowscalar(a[Block()[]]))
191191
@test Array(a) isa Array{elt,0}
192192
@test Array(a) == fill(0)
193193
for b in (
194-
(b = copy(a); @allowscalar b[] = 2; b),
195-
(b = copy(a); @allowscalar b[CartesianIndex()] = 2; b),
196-
(b = copy(a); @allowscalar b[CartesianIndex()] = 2; b),
194+
(b = copy(a); @allowscalar(b[] = 2); b),
195+
(b = copy(a); @allowscalar(b[CartesianIndex()] = 2); b),
196+
(b = copy(a); @allowscalar(b[Block()[]] = 2); b),
197197
# Regression test for https://github.com/ITensor/BlockSparseArrays.jl/issues/27.
198-
(b = copy(a); @allowscalar b[Block()] = dev(fill(2)); b),
198+
(b = copy(a); b[Block()] = dev(fill(2)); b),
199199
)
200200
@test size(b) == ()
201201
@test isone(length(b))

test/basics/test_svd.jl renamed to test/test_svd.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
using Test
2-
using BlockSparseArrays
3-
using BlockSparseArrays: BlockSparseArray, svd, BlockDiagonal, eachblockstoredindex
4-
using BlockArrays
5-
using Random
1+
using BlockArrays: Block, BlockedMatrix, BlockedVector, blocks, mortar
2+
using BlockSparseArrays: BlockSparseArray, BlockDiagonal, eachblockstoredindex, svd
63
using DiagonalArrays: diagonal
74
using LinearAlgebra: LinearAlgebra
5+
using Random: Random
6+
using Test: @inferred, @testset, @test
87

9-
function test_svd(a, usv)
8+
function test_svd(a, usv; broken=false)
109
U, S, V = usv
11-
12-
@test U * diagonal(S) * V' a
10+
@test U * diagonal(S) * V' a broken = broken
1311
@test U' * U LinearAlgebra.I
1412
@test V' * V LinearAlgebra.I
1513
end
@@ -41,9 +39,17 @@ end
4139
@testset "($m, $n) BlockDiagonal{$T}" for ((m, n), T) in
4240
Iterators.product(blockszs, eltypes)
4341
a = BlockDiagonal([rand(T, i, j) for (i, j) in zip(m, n)])
44-
usv = svd(a)
45-
# TODO: `BlockDiagonal * Adjoint` errors
46-
test_svd(a, usv)
42+
if VERSION v"1.11"
43+
usv = svd(a)
44+
# TODO: `BlockDiagonal * Adjoint` errors
45+
# TODO: This is broken because of https://github.com/JuliaLang/julia/issues/57034,
46+
# fix and reenable.
47+
test_svd(a, usv; broken=true)
48+
else
49+
# `svd(a)` depends on `diagind(::AbstractMatrix, ::IndexStyle)`
50+
# being defined, but it was only introduced in Julia v1.11.
51+
@test svd(a) broken = true
52+
end
4753
end
4854

4955
# blocksparse

0 commit comments

Comments
 (0)