@@ -20,6 +20,23 @@ using SparseArrays: AbstractSparseVector, AbstractSparseMatrixCSC, FixedSparseCS
2020 @test (r[1 ] = r[1 ]; true )
2121end
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+
2340struct_eq (A, B, C... ) = struct_eq (A, B) && struct_eq (B, C... )
2441struct_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)
7192end
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 (2 I, 3 , 3 ) == sparse (fixed (2 I, 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))
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)
92122end
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