Skip to content

Commit f8f0f40

Browse files
SobhanMPdkarraschViralBShah
authored
bring coverage of fixed SparseMatrixCSC to 100% (#392)
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de> Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
1 parent 0eb9c04 commit f8f0f40

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/sparsematrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Get a writable copy of x. See `_unsafe_unfix(x)`
124124
"""
125125
SparseMatrixCSC(x::FixedSparseCSC) = SparseMatrixCSC(size(x, 1), size(x, 2),
126126
copy(parent(getcolptr(x))),
127-
copy(parent(rowval(x))),
127+
copy(parent(rowvals(x))),
128128
copy(nonzeros(x)))
129129

130130
function sparse_check_Ti(m::Integer, n::Integer, Ti::Type)

test/fixed.jl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ using SparseArrays: AbstractSparseVector, AbstractSparseMatrixCSC, FixedSparseCS
2020
@test (r[1] = r[1]; true)
2121
end
2222

23+
@testset "SparseMatrixCSC from readonly" begin
24+
25+
# test that SparseMatrixCSC from readonly does copy
26+
A = sprandn(12, 11, 0.3)
27+
B = SparseMatrixCSC(size(A)..., ReadOnly(getcolptr(A)), ReadOnly(rowvals(A)), nonzeros(A))
28+
29+
@test typeof(B) == typeof(A)
30+
@test A == B
31+
32+
@test getcolptr(A) == getcolptr(B)
33+
@test getcolptr(A) !== getcolptr(B)
34+
@test rowvals(A) == rowvals(B)
35+
@test rowvals(A) !== rowvals(B)
36+
@test nonzeros(A) == nonzeros(B)
37+
@test nonzeros(A) === nonzeros(B)
38+
end
39+
2340
struct_eq(A, B, C...) = struct_eq(A, B) && struct_eq(B, C...)
2441
struct_eq(A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC) =
2542
getcolptr(A) == getcolptr(B) && rowvals(A) == rowvals(B)
@@ -30,6 +47,10 @@ struct_eq(A::AbstractSparseVector, B::AbstractSparseVector) =
3047
A = sprandn(10, 10, 0.3)
3148

3249
F = FixedSparseCSC(copy(A))
50+
Ft = FixedSparseCSC{eltype(A),eltype(rowvals(A))}(A)
51+
@test typeof(Ft) == typeof(F)
52+
@test Ft == F
53+
3354
@test struct_eq(F, A)
3455
nonzeros(F) .= 0
3556
@test struct_eq(F, A)
@@ -69,7 +90,16 @@ struct_eq(A::AbstractSparseVector, B::AbstractSparseVector) =
6990
@test typeof(B) == typeof(F)
7091
@test struct_eq(B, F)
7192
end
93+
@testset "SparseMatrixCSC conversions" begin
94+
A = sprandn(10, 10, 0.3)
95+
F = fixed(copy(A))
96+
B = SparseMatrixCSC(F)
97+
@test A == B
7298

99+
# fixed(x...)
100+
@test sparse(2I, 3, 3) == sparse(fixed(2I, 3, 3))
101+
@test SparseArrays._unsafe_unfix(A) == A
102+
end
73103
@testset "FixedSparseVector" begin
74104
y = sprandn(10, 0.3)
75105
x = FixedSparseVector(copy(y))
@@ -88,7 +118,7 @@ end
88118
@test f(x, y, z) == 0
89119
t = similar(x)
90120
@test typeof(t) == typeof(x)
91-
@test struct_eq(t, x)
121+
@test struct_eq(t, x)
92122
end
93123

94124
@testset "Issue #190" begin
@@ -139,4 +169,4 @@ always_false(x...) = false
139169
@test all(iszero, nonzeros(b))
140170

141171
end
142-
end
172+
end

0 commit comments

Comments
 (0)