Skip to content

Commit 6728cba

Browse files
committed
Try fixing tests
1 parent 261c2ec commit 6728cba

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ julia> Pkg.add("SparseArraysBase")
3434
````julia
3535
using SparseArraysBase:
3636
SparseArrayDOK,
37+
SparseMatrixDOK,
38+
SparseVectorDOK,
3739
eachstoredindex,
3840
getstoredindex,
3941
getunstoredindex,
@@ -62,15 +64,16 @@ a[1, 2] = 12
6264
SparseArraysBase interface:
6365

6466
````julia
67+
using Dictionaries: IndexError
6568
@test issetequal(eachstoredindex(a), [CartesianIndex(1, 2)])
6669
@test getstoredindex(a, 1, 2) == 12
67-
@test_throws KeyError getstoredindex(a, 1, 1)
70+
@test_throws IndexError getstoredindex(a, 1, 1)
6871
@test getunstoredindex(a, 1, 1) == 0
6972
@test getunstoredindex(a, 1, 2) == 0
7073
@test !isstored(a, 1, 1)
7174
@test isstored(a, 1, 2)
7275
@test setstoredindex!(copy(a), 21, 1, 2) == [0 21; 0 0]
73-
@test_throws KeyError setstoredindex!(copy(a), 21, 2, 1)
76+
@test_throws IndexError setstoredindex!(copy(a), 21, 2, 1)
7477
@test setunstoredindex!(copy(a), 21, 1, 2) == [0 21; 0 0]
7578
@test storedlength(a) == 1
7679
@test issetequal(storedpairs(a), [CartesianIndex(1, 2) => 12])
@@ -81,11 +84,30 @@ AbstractArray functionality:
8184

8285
````julia
8386
b = a .+ 2 .* a'
87+
@test b isa SparseMatrixDOK{Float64}
8488
@test b == [0 12; 24 0]
8589
@test storedlength(b) == 2
86-
@test b isa SparseArrayDOK{Float64}
8790

88-
a * a'
91+
b = permutedims(a, (2, 1))
92+
@test b isa SparseMatrixDOK{Float64}
93+
@test b[1, 1] == a[1, 1]
94+
@test b[2, 1] == a[1, 2]
95+
@test b[1, 2] == a[2, 1]
96+
@test b[2, 2] == a[2, 2]
97+
98+
b = a * a'
99+
@test b isa SparseMatrixDOK{Float64}
100+
@test b == [144 0; 0 0]
101+
@test storedlength(b) == 1
102+
````
103+
104+
Second column.
105+
106+
````julia
107+
b = a[1:2, 2]
108+
@test b isa SparseVectorDOK{Float64}
109+
@test b == [12, 0]
110+
@test storedlength(b) == 1
89111
````
90112

91113
---

src/abstractsparsearrayinterface.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
# TODO: Define default definitions for these based
33
# on the dense case.
44
# TODO: Define as `MethodError`.
5-
storedvalues(a) = error()
6-
isstored(a, I::Int...) = error()
7-
eachstoredindex(a) = error()
8-
getstoredindex(a, I::Int...) = error()
9-
getunstoredindex(a, I::Int...) = error()
10-
setstoredindex!(a, value, I::Int...) = error()
11-
setunstoredindex!(a, value, I::Int...) = error()
5+
## isstored(a::AbstractArray, I::Int...) = true
6+
isstored(a::AbstractArray, I::Int...) = error("Not implemented.")
7+
## eachstoredindex(a::AbstractArray) = eachindex(a)
8+
eachstoredindex(a::AbstractArray) = error("Not implemented.")
9+
## getstoredindex(a::AbstractArray, I::Int...) = getindex(a, I...)
10+
getstoredindex(a::AbstractArray, I::Int...) = error("Not implemented.")
11+
## setstoredindex!(a::AbstractArray, value, I::Int...) = setindex!(a, value, I...)
12+
setstoredindex!(a::AbstractArray, value, I::Int...) = error("Not implemented.")
13+
## setunstoredindex!(a::AbstractArray, value, I::Int...) = setindex!(a, value, I...)
14+
setunstoredindex!(a::AbstractArray, value, I::Int...) = error("Not implemented.")
1215

1316
# TODO: Use `Base.to_indices`?
1417
isstored(a::AbstractArray, I::CartesianIndex) = isstored(a, Tuple(I)...)
@@ -24,7 +27,7 @@ end
2427
# Interface defaults.
2528
# TODO: Have a fallback that handles element types
2629
# that don't define `zero(::Type)`.
27-
getunstoredindex(a, I::Int...) = zero(eltype(a))
30+
getunstoredindex(a::AbstractArray, I::Int...) = zero(eltype(a))
2831

2932
# Derived interface.
3033
storedlength(a::AbstractArray) = length(storedvalues(a))

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3+
Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
34
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
45
SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208"
56
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"

0 commit comments

Comments
 (0)