@@ -20,6 +20,23 @@ using SparseArrays: AbstractSparseVector, AbstractSparseMatrixCSC, FixedSparseCS
20
20
@test (r[1 ] = r[1 ]; true )
21
21
end
22
22
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
+
23
40
struct_eq (A, B, C... ) = struct_eq (A, B) && struct_eq (B, C... )
24
41
struct_eq (A:: AbstractSparseMatrixCSC , B:: AbstractSparseMatrixCSC ) =
25
42
getcolptr (A) == getcolptr (B) && rowvals (A) == rowvals (B)
@@ -30,6 +47,10 @@ struct_eq(A::AbstractSparseVector, B::AbstractSparseVector) =
30
47
A = sprandn (10 , 10 , 0.3 )
31
48
32
49
F = FixedSparseCSC (copy (A))
50
+ Ft = FixedSparseCSC {eltype(A),eltype(rowvals(A))} (A)
51
+ @test typeof (Ft) == typeof (F)
52
+ @test Ft == F
53
+
33
54
@test struct_eq (F, A)
34
55
nonzeros (F) .= 0
35
56
@test struct_eq (F, A)
@@ -69,7 +90,16 @@ struct_eq(A::AbstractSparseVector, B::AbstractSparseVector) =
69
90
@test typeof (B) == typeof (F)
70
91
@test struct_eq (B, F)
71
92
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
72
98
99
+ # fixed(x...)
100
+ @test sparse (2 I, 3 , 3 ) == sparse (fixed (2 I, 3 , 3 ))
101
+ @test SparseArrays. _unsafe_unfix (A) == A
102
+ end
73
103
@testset " FixedSparseVector" begin
74
104
y = sprandn (10 , 0.3 )
75
105
x = FixedSparseVector (copy (y))
88
118
@test f (x, y, z) == 0
89
119
t = similar (x)
90
120
@test typeof (t) == typeof (x)
91
- @test struct_eq (t, x)
121
+ @test struct_eq (t, x)
92
122
end
93
123
94
124
@testset " Issue #190" begin
@@ -139,4 +169,4 @@ always_false(x...) = false
139
169
@test all (iszero, nonzeros (b))
140
170
141
171
end
142
- end
172
+ end
0 commit comments