Skip to content

Multiplication of size 0 sparse arrays #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseArraysBase"
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.5.6"
version = "0.5.7"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
1 change: 1 addition & 0 deletions src/abstractsparsearrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ end
@interface interface::AbstractSparseArrayInterface function Base.map!(
f, a_dest::AbstractArray, as::AbstractArray...
)
isempty(a_dest) && return a_dest # special case to avoid trying to access empty array
indices = if !preserves_unstored(f, a_dest, as...)
eachindex(a_dest)
elseif any(a -> a_dest !== a, as)
Expand Down
17 changes: 17 additions & 0 deletions test/test_linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@ const rng = StableRNG(123)
check2 = mul!(Array(C), Array(A), Array(B), α, β)
@test mul!(copy(C), A, B, α, β) ≈ check2
end

# test empty matrix
szA = (2, 0)
szB = (0, 2)
szC = (szA[1], szB[2])
density = 0.1
C = sparserand(rng, T, szC; density)
A = sparserand(rng, T, szA; density)
B = sparserand(rng, T, szB; density)

check1 = mul!(Array(C), Array(A), Array(B))
@test mul!(copy(C), A, B) ≈ check1

α = rand(rng, T)
β = rand(rng, T)
check2 = mul!(Array(C), Array(A), Array(B), α, β)
@test mul!(copy(C), A, B, α, β) ≈ check2
end
Loading