Skip to content

Commit b27f40e

Browse files
committed
bugfix-copy
1 parent 07381fd commit b27f40e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/p_sparse_matrix.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ function Base.similar(::Type{<:OldPSparseMatrix{V}},inds::Tuple{<:PRange,<:PRang
311311
OldPSparseMatrix(matrix_partition,partition(rows),partition(cols))
312312
end
313313

314+
function Base.copy(a::OldPSparseMatrix)
315+
mats = map(copy,partition(a))
316+
cache = map(copy_cache,a.cache)
317+
OldPSparseMatrix(mats,partition(axes(a,1)),partition(axes(a,2)),cache)
318+
end
319+
314320
function Base.copy!(a::OldPSparseMatrix,b::OldPSparseMatrix)
315321
@assert size(a) == size(b)
316322
copyto!(a,b)
@@ -674,6 +680,15 @@ function Base.similar(a::AbstractSplitMatrix,::Type{T}) where T
674680
split_matrix(blocks,a.row_permutation,a.col_permutation)
675681
end
676682

683+
function Base.copy(a::AbstractSplitMatrix)
684+
own_own = copy(a.blocks.own_own)
685+
own_ghost = copy(a.blocks.own_ghost)
686+
ghost_own = copy(a.blocks.ghost_own)
687+
ghost_ghost = copy(a.blocks.ghost_ghost)
688+
blocks = split_matrix_blocks(own_own,own_ghost,ghost_own,ghost_ghost)
689+
split_matrix(blocks,a.row_permutation,a.col_permutation)
690+
end
691+
677692
function Base.copy!(a::AbstractSplitMatrix,b::AbstractSplitMatrix)
678693
copy!(a.blocks.own_own,b.blocks.own_own)
679694
copy!(a.blocks.own_ghost,b.blocks.own_ghost)
@@ -1995,6 +2010,12 @@ function Base.similar(a::PSparseMatrix,::Type{T}) where T
19952010
PSparseMatrix(matrix_partition,partition(rows),partition(cols),a.assembled)
19962011
end
19972012

2013+
function Base.copy(a::PSparseMatrix)
2014+
mats = map(copy,partition(a))
2015+
rows, cols = axes(a)
2016+
PSparseMatrix(mats,partition(rows),partition(cols),a.assembled)
2017+
end
2018+
19982019
function Base.copy!(a::PSparseMatrix,b::PSparseMatrix)
19992020
@assert size(a) == size(b)
20002021
@assert a.assembled == b.assembled

test/p_sparse_matrix_tests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ function p_sparse_matrix_tests(distribute)
122122
@test norm(r) < 1.0e-9
123123
display(A)
124124

125+
B = copy(A)
126+
@test reduce(&, map((a,b) -> nnz(a) == nnz(b),partition(A),partition(B)))
127+
@test reduce(&, map((a,b) -> rowvals(a) == rowvals(b),partition(A),partition(B)))
128+
125129
# New stuff
126130

127131
n = 10
@@ -193,6 +197,7 @@ function p_sparse_matrix_tests(distribute)
193197
_A = similar(A)
194198
_A = similar(A,eltype(A))
195199
copy!(_A,A)
200+
_A = copy(A)
196201

197202
LinearAlgebra.fillstored!(A,1.0)
198203
fill!(x,3.0)
@@ -347,3 +352,4 @@ function p_sparse_matrix_tests(distribute)
347352

348353
end
349354

355+
p_sparse_matrix_tests(DebugArray)

0 commit comments

Comments
 (0)