Skip to content

Commit 9d24016

Browse files
authored
Multiplication of size 0 sparse arrays (#58)
1 parent 2a2b51a commit 9d24016

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseArraysBase"
22
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.5.6"
4+
version = "0.5.7"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

src/abstractsparsearrayinterface.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ end
156156
@interface interface::AbstractSparseArrayInterface function Base.map!(
157157
f, a_dest::AbstractArray, as::AbstractArray...
158158
)
159+
isempty(a_dest) && return a_dest # special case to avoid trying to access empty array
159160
indices = if !preserves_unstored(f, a_dest, as...)
160161
eachindex(a_dest)
161162
elseif any(a -> a_dest !== a, as)

test/test_linalg.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,21 @@ const rng = StableRNG(123)
2424
check2 = mul!(Array(C), Array(A), Array(B), α, β)
2525
@test mul!(copy(C), A, B, α, β) check2
2626
end
27+
28+
# test empty matrix
29+
szA = (2, 0)
30+
szB = (0, 2)
31+
szC = (szA[1], szB[2])
32+
density = 0.1
33+
C = sparserand(rng, T, szC; density)
34+
A = sparserand(rng, T, szA; density)
35+
B = sparserand(rng, T, szB; density)
36+
37+
check1 = mul!(Array(C), Array(A), Array(B))
38+
@test mul!(copy(C), A, B) check1
39+
40+
α = rand(rng, T)
41+
β = rand(rng, T)
42+
check2 = mul!(Array(C), Array(A), Array(B), α, β)
43+
@test mul!(copy(C), A, B, α, β) check2
2744
end

0 commit comments

Comments
 (0)