From a6789e4aa140a99aa4351af9c6cb8b7600cf0b38 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sat, 6 Feb 2021 14:49:34 -0700 Subject: [PATCH 01/10] Update CircularArrays.jl --- src/CircularArrays.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/CircularArrays.jl b/src/CircularArrays.jl index 4664fa2..0176817 100644 --- a/src/CircularArrays.jl +++ b/src/CircularArrays.jl @@ -65,4 +65,12 @@ function Base.showarg(io::IO, arr::CircularArray, toplevel) # toplevel && print(io, " with eltype ", eltype(arr)) end +function Base.deleteat!(a::CircularVector, inds) + (CircularVector ∘ deleteat!)(a.data, (unique ∘ sort ∘ map)(i -> mod(i, eachindex(a.data)), inds)) +end + +function Base.deleteat!(a::CircularVector, i::Integer) + (CircularVector ∘ deleteat!)(a.data, mod(i, eachindex(a.data))) +end + end From c2e4909bb3f54b12c306f1da94a9a3315636126b Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sat, 6 Feb 2021 14:54:26 -0700 Subject: [PATCH 02/10] test deleteat! --- test/runtests.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 4956284..51f036e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -172,3 +172,11 @@ end @test a[CartesianIndex.(i,i)] == CircularArray(OffsetArray([5,9,1,5,9],-2:2)) @test a[a .> 4] == 5:9 end + +@testset "deleteat!" begin + a = CircularArray([1,2,3]); + @test deleteat!(a, 5) == CircularVector([1, 3]) + + b = CircularArray([1,2,3,4]); + @test deleteat!(a, 1:5:10) == CircularVector([3, 4]) +end From 78aeb09c918c5b9c03cac1db2d609a779353a5f2 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sat, 6 Feb 2021 14:55:44 -0700 Subject: [PATCH 03/10] fix typo --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 51f036e..8ba4483 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -178,5 +178,5 @@ end @test deleteat!(a, 5) == CircularVector([1, 3]) b = CircularArray([1,2,3,4]); - @test deleteat!(a, 1:5:10) == CircularVector([3, 4]) + @test deleteat!(b, 1:5:10) == CircularVector([3, 4]) end From 388bac7a884ddfa89a514a524d52ca349addbdb7 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sat, 6 Feb 2021 15:06:06 -0700 Subject: [PATCH 04/10] Update CircularArrays.jl --- src/CircularArrays.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CircularArrays.jl b/src/CircularArrays.jl index 0176817..a8f24e3 100644 --- a/src/CircularArrays.jl +++ b/src/CircularArrays.jl @@ -66,11 +66,13 @@ function Base.showarg(io::IO, arr::CircularArray, toplevel) end function Base.deleteat!(a::CircularVector, inds) - (CircularVector ∘ deleteat!)(a.data, (unique ∘ sort ∘ map)(i -> mod(i, eachindex(a.data)), inds)) + deleteat!(a.data, (unique ∘ sort ∘ map)(i -> mod(i, eachindex(a.data)), inds)) + a end function Base.deleteat!(a::CircularVector, i::Integer) - (CircularVector ∘ deleteat!)(a.data, mod(i, eachindex(a.data))) + deleteat!(a.data, mod(i, eachindex(a.data))) + a end end From ce9c22c0cc0d16e55c40fcf6f8631044ad23f033 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sat, 6 Feb 2021 19:42:49 -0700 Subject: [PATCH 05/10] bug and performance fixes --- src/CircularArrays.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/CircularArrays.jl b/src/CircularArrays.jl index a8f24e3..e64d2f8 100644 --- a/src/CircularArrays.jl +++ b/src/CircularArrays.jl @@ -65,13 +65,15 @@ function Base.showarg(io::IO, arr::CircularArray, toplevel) # toplevel && print(io, " with eltype ", eltype(arr)) end -function Base.deleteat!(a::CircularVector, inds) - deleteat!(a.data, (unique ∘ sort ∘ map)(i -> mod(i, eachindex(a.data)), inds)) +function Base.deleteat!(a::CircularVector, i::Integer) + j = firstindex(a) === 1 ? mod1(i, length(a.data)) : mod(i, eachindex(a.data)) + deleteat!(a.data, j) a end -function Base.deleteat!(a::CircularVector, i::Integer) - deleteat!(a.data, mod(i, eachindex(a.data))) +function Base.deleteat!(a::CircularVector, inds) + jnds = firstindex(a) === 1 ? mod1.(inds, length(a)) : map(i -> mod(i, eachindex(a.data))) + deleteat!(a.data, sort(unique(jnds))) a end From 4335ca88d48f4cd2e81b2a2eb41a9fb72da22f8e Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sat, 6 Feb 2021 19:43:55 -0700 Subject: [PATCH 06/10] test on tuple --- test/runtests.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 8ba4483..e31740d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -179,4 +179,7 @@ end b = CircularArray([1,2,3,4]); @test deleteat!(b, 1:5:10) == CircularVector([3, 4]) + + c = CircularArray([1,2,3,4]); + @test deleteat!(b, (6, 10)) == CircularVector([3, 4]) end From 79a5f7e6f023fb0e3f9df8b91a76e7189af29582 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sat, 6 Feb 2021 19:46:52 -0700 Subject: [PATCH 07/10] typo --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index e31740d..23f3734 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -181,5 +181,5 @@ end @test deleteat!(b, 1:5:10) == CircularVector([3, 4]) c = CircularArray([1,2,3,4]); - @test deleteat!(b, (6, 10)) == CircularVector([3, 4]) + @test deleteat!(c, (6, 10)) == CircularVector([3, 4]) end From 170d667fd3207cff373dc47d5de887f38562b4f2 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sat, 6 Feb 2021 19:50:00 -0700 Subject: [PATCH 08/10] fix yet another silly typo --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 23f3734..5a96e13 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -181,5 +181,5 @@ end @test deleteat!(b, 1:5:10) == CircularVector([3, 4]) c = CircularArray([1,2,3,4]); - @test deleteat!(c, (6, 10)) == CircularVector([3, 4]) + @test deleteat!(c, (1, 6)) == CircularVector([3, 4]) end From 964672fa1cbc4767f908894ad4ba301854a5cdd5 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sun, 7 Feb 2021 10:25:57 -0700 Subject: [PATCH 09/10] Update CircularArrays.jl --- src/CircularArrays.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CircularArrays.jl b/src/CircularArrays.jl index e64d2f8..1b20501 100644 --- a/src/CircularArrays.jl +++ b/src/CircularArrays.jl @@ -66,14 +66,12 @@ function Base.showarg(io::IO, arr::CircularArray, toplevel) end function Base.deleteat!(a::CircularVector, i::Integer) - j = firstindex(a) === 1 ? mod1(i, length(a.data)) : mod(i, eachindex(a.data)) - deleteat!(a.data, j) + deleteat!(a.data, mod(i, eachindex(a.data))) a end function Base.deleteat!(a::CircularVector, inds) - jnds = firstindex(a) === 1 ? mod1.(inds, length(a)) : map(i -> mod(i, eachindex(a.data))) - deleteat!(a.data, sort(unique(jnds))) + deleteat!(a.data, sort!(unique(map(i -> mod(i, eachindex(a.data)))))) a end From 04a078114a6674dd76562d07d6f44ca7f91ed1f5 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Sun, 7 Feb 2021 10:52:32 -0700 Subject: [PATCH 10/10] fix typo --- src/CircularArrays.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CircularArrays.jl b/src/CircularArrays.jl index 1b20501..d07a6a0 100644 --- a/src/CircularArrays.jl +++ b/src/CircularArrays.jl @@ -71,7 +71,7 @@ function Base.deleteat!(a::CircularVector, i::Integer) end function Base.deleteat!(a::CircularVector, inds) - deleteat!(a.data, sort!(unique(map(i -> mod(i, eachindex(a.data)))))) + deleteat!(a.data, (sort! ∘ unique ∘ map)(i -> mod(i, eachindex(a.data)), inds)) a end