From 62915b8ff3d615dd9695a1c9acd1532d62f4d5bc Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Fri, 17 Dec 2021 13:01:42 +0300 Subject: [PATCH] add filter method for ArrayPartition --- src/array_partition.jl | 1 + test/partitions_test.jl | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/array_partition.jl b/src/array_partition.jl index 1d66a856..06da62f5 100644 --- a/src/array_partition.jl +++ b/src/array_partition.jl @@ -114,6 +114,7 @@ Base.:(==)(A::ArrayPartition,B::ArrayPartition) = A.x == B.x Base.map(f,A::ArrayPartition) = ArrayPartition(map(x->map(f,x), A.x)) Base.mapreduce(f,op,A::ArrayPartition) = mapreduce(f,op,(mapreduce(f,op,x) for x in A.x)) +Base.filter(f,A::ArrayPartition) = ArrayPartition(map(x->filter(f,x), A.x)) Base.any(f,A::ArrayPartition) = any(f,(any(f,x) for x in A.x)) Base.any(f::Function,A::ArrayPartition) = any(f,(any(f,x) for x in A.x)) Base.any(A::ArrayPartition) = any(identity, A) diff --git a/test/partitions_test.jl b/test/partitions_test.jl index 0866d647..65f77195 100644 --- a/test/partitions_test.jl +++ b/test/partitions_test.jl @@ -106,6 +106,9 @@ _broadcast_wrapper(y) = _scalar_op.(y) # Testing map @test map(x->x^2, x) == ArrayPartition(x.x[1].^2, x.x[2].^2) +# Testing filter +@test filter(x->iseven(round(Int, x)), x) == ArrayPartition([2], [4.0]) + #### testing copyto! S = [ ((1,),(2,)) => ((1,),(2,)),