From 673bf96b8fcec5643ac8f7ba85fec492d6165099 Mon Sep 17 00:00:00 2001 From: Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com> Date: Tue, 18 May 2021 13:49:03 -0400 Subject: [PATCH 1/2] Faster `map` over `ArrayPartitions`. --- src/array_partition.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/array_partition.jl b/src/array_partition.jl index 83c8a891..0903d25b 100644 --- a/src/array_partition.jl +++ b/src/array_partition.jl @@ -112,6 +112,7 @@ Base.:(==)(A::ArrayPartition,B::ArrayPartition) = A.x == B.x ## Iterable Collection Constructs +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.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)) From bf9443f440d1f33a1f964e41793a276801c7d244 Mon Sep 17 00:00:00 2001 From: Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com> Date: Tue, 18 May 2021 14:22:38 -0400 Subject: [PATCH 2/2] Added test for `map` over `ArrayPartition`. --- test/partitions_test.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/partitions_test.jl b/test/partitions_test.jl index 6b4db521..cce344b3 100644 --- a/test/partitions_test.jl +++ b/test/partitions_test.jl @@ -103,6 +103,9 @@ _broadcast_wrapper(y) = _scalar_op.(y) # Issue #8 # @inferred _broadcast_wrapper(x) +# Testing map +@test map(x->x^2, x) == ArrayPartition(x.x[1].^2, x.x[2].^2) + #### testing copyto! S = [ ((1,),(2,)) => ((1,),(2,)),