Skip to content

Commit

Permalink
add tests for SparseMatrix from ReadOnly vectors and FixedSparse{Tv,T…
Browse files Browse the repository at this point in the history
…i}(...)
  • Loading branch information
SobhanMP committed Jul 18, 2023
1 parent 145b144 commit 94b96f7
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ using SparseArrays: AbstractSparseVector, AbstractSparseMatrixCSC, FixedSparseCS
@test (r[1] = r[1]; true)
end

@testset "SparseMatrixCSC from readonly" begin

# test that SparseMatrixCSC from readonly does copy
A = sprandn(12, 11, 0.3)
B = SparseMatrixCSC(size(A)..., ReadOnly(getcolptr(A)), ReadOnly(rowvals(A)), nonzeros(A))

@test typeof(B) == typeof(A)
@test A == B

@test getcolptr(A) == getcolptr(B)
@test getcolptr(A) !== getcolptr(B)
@test rowvals(A) == rowvals(B)
@test rowvals(A) !== rowvals(B)
@test nonzeros(A) == nonzeros(B)
@test nonzeros(A) === nonzeros(B)
end

struct_eq(A, B, C...) = struct_eq(A, B) && struct_eq(B, C...)
struct_eq(A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC) =
getcolptr(A) == getcolptr(B) && rowvals(A) == rowvals(B)
Expand All @@ -30,6 +47,10 @@ struct_eq(A::AbstractSparseVector, B::AbstractSparseVector) =
A = sprandn(10, 10, 0.3)

F = FixedSparseCSC(copy(A))
Ft = FixedSparseCSC{eltype(A),eltype(rowvals(A))}(A)
@test typeof(Ft) == typeof(F)
@test Ft == F

@test struct_eq(F, A)
nonzeros(F) .= 0
@test struct_eq(F, A)
Expand Down Expand Up @@ -97,7 +118,7 @@ end
@test f(x, y, z) == 0
t = similar(x)
@test typeof(t) == typeof(x)
@test struct_eq(t, x)
@test struct_eq(t, x)
end

@testset "Issue #190" begin
Expand Down Expand Up @@ -148,4 +169,4 @@ always_false(x...) = false
@test all(iszero, nonzeros(b))

end
end
end

0 comments on commit 94b96f7

Please sign in to comment.