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
3 changes: 2 additions & 1 deletion src/ExtendableSparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ using Requires

using DocStringExtensions


import SparseArrays: rowvals, getcolptr, nonzeros
import Base: copy

include("sparsematrixcsc.jl")
include("sparsematrixlnk.jl")
Expand Down
7 changes: 7 additions & 0 deletions src/extendable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,10 @@ function SparseArrays.dropzeros!(ext::ExtendableSparseMatrix)
end


function copy(S::ExtendableSparseMatrix)
if isnothing(S.lnkmatrix)
ExtendableSparseMatrix(copy(S.cscmatrix), nothing, S.phash)
else
ExtendableSparseMatrix(copy(S.cscmatrix), copy(S.lnkmatrix), S.phash)
end
end
7 changes: 7 additions & 0 deletions src/sparsematrixlnk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,10 @@ function SparseArrays.SparseMatrixCSC(lnk::SparseMatrixLNK)::SparseMatrixCSC
csc=spzeros(lnk.m,lnk.n)
lnk+csc
end


rowvals(S::SparseMatrixLNK) = getfield(S, :rowval)
getcolptr(S::SparseMatrixLNK) = getfield(S, :colptr)
nonzeros(S::SparseMatrixLNK) = getfield(S, :nzval)

copy(S::SparseMatrixLNK) = SparseMatrixLNK(size(S, 1), size(S, 2), S.nnz, S.nentries, copy(getcolptr(S)), copy(rowvals(S)), copy(nonzeros(S)))
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ using IterativeSolvers
@test test_constructors()
end

##############################################################
@testset "Copy-Methods" begin
function test_copymethods()
Xcsc = sprand(10_000,10_000,0.01)
Xlnk = SparseMatrixLNK(Xcsc)
Xext = ExtendableSparseMatrix(Xcsc)
t0 = @elapsed copy(Xcsc)
t1 = @elapsed copy(Xlnk)
t2 = @elapsed copy(Xext)
t1 / t0 < 10 && t0 / t2 < 10
end
@test test_copymethods()
end

#################################################################

@testset "Updates" begin
Expand Down