Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ copy(S::AbstractSparseMatrixCSC) =
SparseMatrixCSC(size(S, 1), size(S, 2), copy(getcolptr(S)), copy(rowvals(S)), copy(nonzeros(S)))
copy(S::FixedSparseCSC) =
FixedSparseCSC(size(S, 1), size(S, 2), getcolptr(S), rowvals(S), copy(nonzeros(S)))
function copyto!(A::FixedSparseCSC, B::FixedSparseCSC)
size(A) == size(B) || throw(DimensionMismatch("cannot copy sparse matrix with different dimensions into FixedSparseCSC"))
nnz(A) == nnz(B) || throw(ArgumentError("cannot change fixed sparse structure via copyto!"))
copyto!(parent(getcolptr(A)), getcolptr(B))
copyto!(parent(rowvals(A)), rowvals(B))
copyto!(nonzeros(A), nonzeros(B))
return A
end
function copyto!(A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC)
# If the two matrices have the same length then all the
# elements in A will be overwritten.
Expand Down Expand Up @@ -712,6 +720,10 @@ uninitialized values for the nonzero locations.
similar(S::AbstractSparseMatrixCSC{<:Any,Ti}, ::Type{TvNew}) where {Ti,TvNew} =
@if_move_fixed S _sparsesimilar(S, TvNew, Ti)

similar(S::FixedSparseCSC{<:Any,Ti}, ::Type{TvNew}, dims::Dims{2}) where {Ti,TvNew} =
dims == size(S) ? move_fixed(_sparsesimilar(S, TvNew, Ti)) :
move_fixed(_sparsesimilar(S, TvNew, Ti, dims))

similar(S::AbstractSparseMatrixCSC{<:Any,Ti}, ::Type{TvNew}, dims::Union{Dims{1},Dims{2}}) where {Ti,TvNew} =
@if_move_fixed S _sparsesimilar(S, TvNew, Ti, dims)

Expand Down Expand Up @@ -1008,6 +1020,7 @@ julia> sparse(A)
sparse(A::AbstractMatrix{Tv}) where {Tv} = convert(SparseMatrixCSC{Tv}, A)

sparse(S::AbstractSparseMatrixCSC) = copy(S)
sparse(S::FixedSparseCSC) = SparseMatrixCSC(S)

sparse(Q::AbstractQ) = SparseMatrixCSC(Q)

Expand Down
8 changes: 4 additions & 4 deletions test/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
module CHOLMODTests

using Test
using SparseArrays.CHOLMOD
using SparseArrays.CHOLMOD: getcommon
using Random
using Serialization
using LinearAlgebra:
Expand All @@ -13,10 +11,12 @@ using LinearAlgebra:
PosDefException, ZeroPivotException
using SparseArrays
using SparseArrays: getcolptr
using SparseArrays.LibSuiteSparse
using SparseArrays.LibSuiteSparse: cholmod_l_allocate_sparse, cholmod_allocate_sparse

if Base.USE_GPL_LIBS
using SparseArrays.CHOLMOD
using SparseArrays.CHOLMOD: getcommon
using SparseArrays.LibSuiteSparse
using SparseArrays.LibSuiteSparse: cholmod_l_allocate_sparse, cholmod_allocate_sparse

# CHOLMOD tests
itypes = sizeof(Int) == 4 ? (Int32,) : (Int32, Int64)
Expand Down
37 changes: 32 additions & 5 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ struct_eq(A::AbstractSparseVector, B::AbstractSparseVector) =
B = similar(F)
@test typeof(B) == typeof(F)
@test struct_eq(B, F)

C = fixed(copy(A))
copyto!(C, F)
@test C == F
@test struct_eq(C, F)

G = fixed(sparse([1.0 0.0; 0.0 2.0]))
H = fixed(sparse([1.0 3.0; 0.0 2.0]))
@test_throws DimensionMismatch copyto!(fixed(sprandn(9, 10, 0.3)), F)
@test_throws ArgumentError copyto!(G, H)

Bsame = similar(F, Float32, size(F))
@test Bsame isa FixedSparseCSC{Float32, eltype(rowvals(F))}
@test _is_fixed(Bsame)
@test struct_eq(Bsame, F)

Bdiff = similar(F, Float32, (size(F, 1) + 1, size(F, 2)))
@test typeof(Bdiff) == typeof(Bsame)
@test _is_fixed(Bdiff)
@test size(Bdiff) == (size(F, 1) + 1, size(F, 2))
end
@testset "SparseMatrixCSC conversions" begin
A = sprandn(10, 10, 0.3)
Expand Down Expand Up @@ -152,11 +172,18 @@ end
@testset "Test factorization" begin
b = sprandn(10, 10, 0.99) + I
a = fixed(b)

@test (lu(a) \ randn(10); true)
@test b == a
@test (qr(a + a') \ randn(10); true)
@test b == a
@test sparse(a) isa SparseMatrixCSC

if Base.USE_GPL_LIBS
@test (lu(a) \ randn(10); true)
@test b == a
@test (qr(a + a') \ randn(10); true)
@test b == a
else
@test (lu(sparse(a)) \ randn(10); true)
@test (qr(sparse(a + a')) \ randn(10); true)
@test b == a
end
end

always_false(x...) = false
Expand Down
4 changes: 2 additions & 2 deletions test/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
module SPQRTests

using Test
using SparseArrays.SPQR
using SparseArrays.CHOLMOD
using LinearAlgebra: I, istriu, norm, qr, rank, rmul!, lmul!, Adjoint, Transpose, ColumnNorm, RowMaximum, NoPivot
using SparseArrays: SparseArrays, sparse, sprandn, spzeros, SparseMatrixCSC
using Random: seed!

# TODO REMOVE SECOND PREDICATE WITH SS7.1
if Base.USE_GPL_LIBS
using SparseArrays.SPQR
using SparseArrays.CHOLMOD
@testset "Sparse QR" begin
m, n = 100, 10
nn = 100
Expand Down
3 changes: 2 additions & 1 deletion test/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ using SparseArrays
using Serialization
using LinearAlgebra:
LinearAlgebra, I, det, issuccess, ldiv!, lu, lu!, Transpose, SingularException, Diagonal, logabsdet
using SparseArrays: nnz, sparse, sprand, sprandn, SparseMatrixCSC, UMFPACK, increment!
using SparseArrays: nnz, sparse, sprand, sprandn, SparseMatrixCSC, increment!
if Base.USE_GPL_LIBS
using SparseArrays: UMFPACK
function umfpack_report(l::UMFPACK.UmfpackLU)
UMFPACK.umfpack_report_numeric(l, 0)
UMFPACK.umfpack_report_symbolic(l, 0)
Expand Down
Loading