From ec8e83999c533cae62cd0ccba29279a73724079b Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 9 Feb 2024 19:40:16 +0100 Subject: [PATCH] Testing skipping non positive values --- src/p_vector.jl | 21 ++++++++++++++------- test/p_sparse_matrix_tests.jl | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/p_vector.jl b/src/p_vector.jl index 172a61b6..6b6f574c 100644 --- a/src/p_vector.jl +++ b/src/p_vector.jl @@ -555,11 +555,24 @@ function dense_vector(I,V,n) T = eltype(V) a = zeros(T,n) for (i,v) in zip(I,V) + if i < 1 + continue + end a[i] += v end a end +function dense_vector!(A,K,V) + fill!(A,0) + for (k,v) in zip(K,V) + if k < 1 + continue + end + A[k] += v + end +end + function pvector(I,V,rows;kwargs...) pvector(dense_vector,I,V,rows;kwargs...) end @@ -665,16 +678,10 @@ end pvector!(B::PVector,V,cache) """ function pvector!(B,V,cache) - function update!(A,K,V) - fill!(A,0) - for (k,v) in zip(K,V) - A[k] += v - end - end (A,cacheB,assemble,assembled,K) = cache rows_sa = partition(axes(A,1)) values_sa = partition(A) - map(update!,values_sa,K,V) + map(dense_vector!,values_sa,K,V) if !assembled && assemble t = PartitionedArrays.assemble!(B,A,cacheB) else diff --git a/test/p_sparse_matrix_tests.jl b/test/p_sparse_matrix_tests.jl index 22f9f539..f8187353 100644 --- a/test/p_sparse_matrix_tests.jl +++ b/test/p_sparse_matrix_tests.jl @@ -206,11 +206,11 @@ function p_sparse_matrix_tests(distribute) if part == 1 [1,2,1,2,2], [2,6,1,2,1], [1.0,2.0,30.0,10.0,1.0] elseif part == 2 - [3,3,4,6], [3,9,4,2], [10.0,2.0,30.0,2.0] + [3,3,4,6,0], [3,9,4,2,0], [10.0,2.0,30.0,2.0,2.0] elseif part == 3 [5,5,6,7], [5,6,6,7], [10.0,2.0,30.0,1.0] else - [9,9,8,10,6], [9,3,8,10,5], [10.0,2.0,30.0,50.0,2.0] + [9,9,8,10,6,-1], [9,3,8,10,5,1], [10.0,2.0,30.0,50.0,2.0,1.0] end end |> tuple_of_arrays