Skip to content

Commit 827bbca

Browse files
committed
Add tests, simplify matmul
1 parent 04e2fd2 commit 827bbca

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/abstractsparsearrayinterface.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,7 @@ function sparse_mul!(
359359
β::Number=false;
360360
(mul!!)=(default_mul!!),
361361
)
362-
# TODO: Change to: `a_dest .*= β`
363-
# once https://github.com/ITensor/SparseArraysBase.jl/issues/19 is fixed.
364-
storedvalues(a_dest) .*= β
362+
a_dest .*= β
365363
β′ = one(Bool)
366364
for I1 in eachstoredindex(a1)
367365
for I2 in eachstoredindex(a2)

test/basics/test_sparsearraydok.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,42 @@ arrayts = (Array,)
177177
a[1, 2] = 12
178178
@test sprint(show, "text/plain", a) == "$(summary(a)):\n$(eltype(a)(12))\n ⋅ ⋅"
179179
end
180+
181+
# Regression test for:
182+
# https://github.com/ITensor/SparseArraysBase.jl/issues/19
183+
a = SparseArrayDOK{elt}(2, 2)
184+
a[1, 1] = 1
185+
a .*= 2
186+
@test a == [2 0; 0 0]
187+
@test storedlength(a) == 1
188+
189+
# Test aliasing behavior.
190+
a = SparseArrayDOK{elt}(2, 2)
191+
a[1, 1] = 11
192+
a[1, 2] = 12
193+
a[2, 2] = 22
194+
c1 = @view a[:, 1]
195+
r1 = @view a[1, :]
196+
r1 .= c1
197+
@test c1 == [11, 0]
198+
@test storedlength(c1) == 1
199+
@test r1 == [11, 0]
200+
@test storedlength(r1) == 2
201+
@test a == [11 0; 0 22]
202+
@test storedlength(a) == 3
203+
204+
# Test aliasing behavior.
205+
a = SparseArrayDOK{elt}(2, 2)
206+
a[1, 1] = 11
207+
a[1, 2] = 12
208+
a[2, 2] = 22
209+
c1 = @view a[:, 1]
210+
r1 = @view a[1, :]
211+
c1 .= r1
212+
@test c1 == [11, 12]
213+
@test storedlength(c1) == 2
214+
@test r1 == [11, 12]
215+
@test storedlength(r1) == 2
216+
@test a == [11 12; 12 22]
217+
@test storedlength(a) == 4
180218
end

0 commit comments

Comments
 (0)