Skip to content

Commit 62915b8

Browse files
committed
add filter method for ArrayPartition
1 parent 97f1e90 commit 62915b8

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/array_partition.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Base.:(==)(A::ArrayPartition,B::ArrayPartition) = A.x == B.x
114114

115115
Base.map(f,A::ArrayPartition) = ArrayPartition(map(x->map(f,x), A.x))
116116
Base.mapreduce(f,op,A::ArrayPartition) = mapreduce(f,op,(mapreduce(f,op,x) for x in A.x))
117+
Base.filter(f,A::ArrayPartition) = ArrayPartition(map(x->filter(f,x), A.x))
117118
Base.any(f,A::ArrayPartition) = any(f,(any(f,x) for x in A.x))
118119
Base.any(f::Function,A::ArrayPartition) = any(f,(any(f,x) for x in A.x))
119120
Base.any(A::ArrayPartition) = any(identity, A)

test/partitions_test.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ _broadcast_wrapper(y) = _scalar_op.(y)
106106
# Testing map
107107
@test map(x->x^2, x) == ArrayPartition(x.x[1].^2, x.x[2].^2)
108108

109+
# Testing filter
110+
@test filter(x->iseven(round(Int, x)), x) == ArrayPartition([2], [4.0])
111+
109112
#### testing copyto!
110113
S = [
111114
((1,),(2,)) => ((1,),(2,)),

0 commit comments

Comments
 (0)