From e36e09db804dd9de43522305a0ac884b814007c7 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Sun, 2 Oct 2022 16:35:08 -0400 Subject: [PATCH 01/22] fix bit_map! --- base/bitarray.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 841509a90ba44..4b6474e9be21a 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1779,11 +1779,11 @@ end # map across the chunks. Otherwise, fall-back to the AbstractArray method that # iterates bit-by-bit. function bit_map!(f::F, dest::BitArray, A::BitArray) where F - size(A) == size(dest) || throw(DimensionMismatch("sizes of dest and A must match")) + size(A) > size(dest) || throw(DimensionMismatch("size of dest must be >= that of the source")) isempty(A) && return dest destc = dest.chunks Ac = A.chunks - for i = 1:(length(Ac)-1) + for i = 1:(length(destc)-1) destc[i] = f(Ac[i]) end destc[end] = f(Ac[end]) & _msk_end(A) From 3e19ce3058126ecb85431e5874f5c551794e9947 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Sun, 2 Oct 2022 18:04:46 -0400 Subject: [PATCH 02/22] add bit array test for unequal length --- base/bitarray.jl | 7 ++++--- test/bitarray.jl | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 4b6474e9be21a..8c7edf3971b94 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1779,7 +1779,7 @@ end # map across the chunks. Otherwise, fall-back to the AbstractArray method that # iterates bit-by-bit. function bit_map!(f::F, dest::BitArray, A::BitArray) where F - size(A) > size(dest) || throw(DimensionMismatch("size of dest must be >= that of the source")) + size(A) <= size(dest) || throw(DimensionMismatch("size of dest must be >= than size of A")) isempty(A) && return dest destc = dest.chunks Ac = A.chunks @@ -1790,12 +1790,13 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F - size(A) == size(B) == size(dest) || throw(DimensionMismatch("sizes of dest, A, and B must all match")) + size(A) == size(B) || throw(DimensionMismatch("size of A and B must be equal")) + size(dest) < size(A) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) isempty(A) && return dest destc = dest.chunks Ac = A.chunks Bc = B.chunks - for i = 1:(length(Ac)-1) + for i = 1:(length(destc)-1) destc[i] = f(Ac[i], Bc[i]) end destc[end] = f(Ac[end], Bc[end]) & _msk_end(A) diff --git a/test/bitarray.jl b/test/bitarray.jl index c1c596dc5d7d6..0622bd7e956c6 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1494,6 +1494,17 @@ timesofar("reductions") C17970 = map(x -> x ? false : true, A17970) @test C17970::BitArray{1} == map(~, A17970) end + + @testset "Issue #47011, map! over unequal length bitarray" begin + for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] + b1 = bitrand(l+10) + b2 = bitrand(l) + for op in (!, ~) + map!(op, b1, b2) + @test first(b1,l) == map(op, b2) + end + end + end end ## Filter ## From 286a10d1bddda0468177ebf4a886196e05a59035 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Sun, 2 Oct 2022 18:40:48 -0400 Subject: [PATCH 03/22] fix logic and add more tests --- base/bitarray.jl | 19 ++++++++++++++++--- test/bitarray.jl | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 8c7edf3971b94..712338e9be6dd 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1783,10 +1783,17 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F isempty(A) && return dest destc = dest.chunks Ac = A.chunks - for i = 1:(length(destc)-1) + len_destc = length(destc) + for i = 1:(len_destc-1) destc[i] = f(Ac[i]) end - destc[end] = f(Ac[end]) & _msk_end(A) + + dest_last = destc[len_destc] + _msk = _msk_end(A) + # first zero out the bits mask is going to change + destc[len_destc] = (dest_last & ~(_msk)) + # then update bits by `or`ing with a masked RHS + destc[len_destc] |= f(Ac[len_destc]) & _msk dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F @@ -1799,7 +1806,13 @@ function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F for i = 1:(length(destc)-1) destc[i] = f(Ac[i], Bc[i]) end - destc[end] = f(Ac[end], Bc[end]) & _msk_end(A) + + dest_last = destc[len_destc] + _msk = _msk_end(A) + # first zero out the bits mask is going to change + destc[len_destc] = (dest_last & ~(_msk)) + # then update bits by `or`ing with a masked RHS + destc[len_destc] |= f(Ac[len_destc]) & _msk dest end diff --git a/test/bitarray.jl b/test/bitarray.jl index 0622bd7e956c6..fcf067e8646af 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1500,8 +1500,11 @@ timesofar("reductions") b1 = bitrand(l+10) b2 = bitrand(l) for op in (!, ~) + original_tail = last(b1, 10) map!(op, b1, b2) @test first(b1,l) == map(op, b2) + # check we didn't change bits we're not suppose to + @test last(b1,10) == original_tail end end end From 81256107f105ecd751fd938ebc6ea4c912f30aeb Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Sun, 2 Oct 2022 18:42:34 -0400 Subject: [PATCH 04/22] fix logic and add more tests --- base/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 712338e9be6dd..23db56c9d1a86 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1812,7 +1812,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F # first zero out the bits mask is going to change destc[len_destc] = (dest_last & ~(_msk)) # then update bits by `or`ing with a masked RHS - destc[len_destc] |= f(Ac[len_destc]) & _msk + destc[len_destc] |= f(Ac[len_destc], Bc[len_destc]) & _msk dest end From e488de7519779e81a1d2b05d90421dfda0cb2eba Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Sun, 2 Oct 2022 19:14:06 -0400 Subject: [PATCH 05/22] remove white space --- base/bitarray.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 23db56c9d1a86..26d4e8dae9fd4 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1787,7 +1787,6 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F for i = 1:(len_destc-1) destc[i] = f(Ac[i]) end - dest_last = destc[len_destc] _msk = _msk_end(A) # first zero out the bits mask is going to change @@ -1806,7 +1805,6 @@ function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F for i = 1:(length(destc)-1) destc[i] = f(Ac[i], Bc[i]) end - dest_last = destc[len_destc] _msk = _msk_end(A) # first zero out the bits mask is going to change From b32fd476df3159463848ed2460d63300e6f37e27 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 3 Oct 2022 00:53:19 -0400 Subject: [PATCH 06/22] Update base/bitarray.jl Co-authored-by: N5N3 <2642243996@qq.com> --- base/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 26d4e8dae9fd4..35a17c2b8ee5b 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1779,7 +1779,7 @@ end # map across the chunks. Otherwise, fall-back to the AbstractArray method that # iterates bit-by-bit. function bit_map!(f::F, dest::BitArray, A::BitArray) where F - size(A) <= size(dest) || throw(DimensionMismatch("size of dest must be >= than size of A")) + length(A) <= length(dest) || throw(DimensionMismatch("length of dest must be >= than length of A")) isempty(A) && return dest destc = dest.chunks Ac = A.chunks From 2eab0229978dcea892f30c14c8bf82700d324ee9 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 3 Oct 2022 09:13:02 -0400 Subject: [PATCH 07/22] correction and more tests --- base/bitarray.jl | 18 ++++++++++-------- test/bitarray.jl | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 35a17c2b8ee5b..d8b5b3c0c7c3d 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1783,16 +1783,17 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F isempty(A) && return dest destc = dest.chunks Ac = A.chunks - len_destc = length(destc) - for i = 1:(len_destc-1) + len_Ac = length(Ac) + for i = 1:(len_Ac-1) destc[i] = f(Ac[i]) end - dest_last = destc[len_destc] + # the last effected UInt64's original content + dest_last = destc[len_Ac] _msk = _msk_end(A) # first zero out the bits mask is going to change - destc[len_destc] = (dest_last & ~(_msk)) + destc[len_Ac] = (dest_last & ~(_msk)) # then update bits by `or`ing with a masked RHS - destc[len_destc] |= f(Ac[len_destc]) & _msk + destc[len_Ac] |= f(Ac[end]) & _msk dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F @@ -1805,12 +1806,13 @@ function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F for i = 1:(length(destc)-1) destc[i] = f(Ac[i], Bc[i]) end - dest_last = destc[len_destc] + # the last effected UInt64's original content + dest_last = destc[len_Ac] _msk = _msk_end(A) # first zero out the bits mask is going to change - destc[len_destc] = (dest_last & ~(_msk)) + destc[len_Ac] = (dest_last & ~(_msk)) # then update bits by `or`ing with a masked RHS - destc[len_destc] |= f(Ac[len_destc], Bc[len_destc]) & _msk + destc[len_Ac] |= f(Ac[end], Bc[end]) & _msk dest end diff --git a/test/bitarray.jl b/test/bitarray.jl index fcf067e8646af..d84f47b7ecb13 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1497,14 +1497,16 @@ timesofar("reductions") @testset "Issue #47011, map! over unequal length bitarray" begin for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] - b1 = bitrand(l+10) - b2 = bitrand(l) - for op in (!, ~) - original_tail = last(b1, 10) - map!(op, b1, b2) - @test first(b1,l) == map(op, b2) - # check we didn't change bits we're not suppose to - @test last(b1,10) == original_tail + for extra_l = [10, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] + b1 = bitrand(l+extra_l) + b2 = bitrand(l) + for op in (!, ~) + original_tail = last(b1, extra_l) + map!(op, b1, b2) + @test first(b1,l) == map(op, b2) + # check we didn't change bits we're not suppose to + @test last(b1,extra_l) == original_tail + end end end end From 2727a9811cf4dcfeaaf7a5db768b90d5756ae309 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 3 Oct 2022 09:29:07 -0400 Subject: [PATCH 08/22] better styling --- test/bitarray.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index d84f47b7ecb13..3ef78b454976c 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1503,9 +1503,9 @@ timesofar("reductions") for op in (!, ~) original_tail = last(b1, extra_l) map!(op, b1, b2) - @test first(b1,l) == map(op, b2) + @test first(b1, l) == map(op, b2) # check we didn't change bits we're not suppose to - @test last(b1,extra_l) == original_tail + @test last(b1, extra_l) == original_tail end end end From 9eeb5f1c1048b27deb218559d4f5fd40bd93a807 Mon Sep 17 00:00:00 2001 From: Moelf Date: Mon, 3 Oct 2022 11:11:44 -0400 Subject: [PATCH 09/22] fix length checking --- base/bitarray.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index d8b5b3c0c7c3d..88e96ae391469 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1797,8 +1797,8 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F - size(A) == size(B) || throw(DimensionMismatch("size of A and B must be equal")) - size(dest) < size(A) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) + length(A) == length(B) || throw(DimensionMismatch("size of A and B must be equal")) + length(A) <= length(A) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) isempty(A) && return dest destc = dest.chunks Ac = A.chunks From 160e63bd1899c602accf08568553a09372e1643b Mon Sep 17 00:00:00 2001 From: Moelf Date: Mon, 3 Oct 2022 11:18:32 -0400 Subject: [PATCH 10/22] add more tests --- test/bitarray.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index 3ef78b454976c..37ee2b0522dc4 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1498,15 +1498,24 @@ timesofar("reductions") @testset "Issue #47011, map! over unequal length bitarray" begin for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] for extra_l = [10, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] + b1 = bitrand(l+extra_l) b2 = bitrand(l) + original_tail = last(b1, extra_l) for op in (!, ~) - original_tail = last(b1, extra_l) map!(op, b1, b2) @test first(b1, l) == map(op, b2) # check we didn't change bits we're not suppose to @test last(b1, extra_l) == original_tail end + + b3 = bitrand(l) + for op in (|, ⊻) + map!(op, b1, b2) + @test first(b1, l) == map(op, b2, b3) + # check we didn't change bits we're not suppose to + @test last(b1, extra_l) == original_tail + end end end end From a8c8044ade4737b0a60b743277702980cd8d9d06 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 3 Oct 2022 23:07:22 -0400 Subject: [PATCH 11/22] Update base/bitarray.jl Co-authored-by: N5N3 <2642243996@qq.com> --- base/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 88e96ae391469..e01b1e53e345e 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1798,7 +1798,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F length(A) == length(B) || throw(DimensionMismatch("size of A and B must be equal")) - length(A) <= length(A) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) + length(A) <= length(dest) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) isempty(A) && return dest destc = dest.chunks Ac = A.chunks From 8439e508fda95949450ab05696a8662166ae61be Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 3 Oct 2022 23:07:35 -0400 Subject: [PATCH 12/22] Update base/bitarray.jl Co-authored-by: N5N3 <2642243996@qq.com> --- base/bitarray.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index e01b1e53e345e..d2b848397e051 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1803,7 +1803,8 @@ function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F destc = dest.chunks Ac = A.chunks Bc = B.chunks - for i = 1:(length(destc)-1) + len_Ac = length(Ac) + for i = 1:len_Ac-1 destc[i] = f(Ac[i], Bc[i]) end # the last effected UInt64's original content From 93d10ca31ff45bc28bc18ce919999a9e70265883 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 3 Oct 2022 23:47:34 -0400 Subject: [PATCH 13/22] relax three arg bit_map! --- base/bitarray.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index d2b848397e051..ccc467801c8e0 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1797,19 +1797,20 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F - length(A) == length(B) || throw(DimensionMismatch("size of A and B must be equal")) length(A) <= length(dest) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) + length(B) <= length(dest) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) isempty(A) && return dest + isempty(B) && return dest destc = dest.chunks Ac = A.chunks Bc = B.chunks - len_Ac = length(Ac) + len_Ac = min(length(Ac), length(Bc)) for i = 1:len_Ac-1 destc[i] = f(Ac[i], Bc[i]) end # the last effected UInt64's original content dest_last = destc[len_Ac] - _msk = _msk_end(A) + _msk = _msk_end(len_Ac) # first zero out the bits mask is going to change destc[len_Ac] = (dest_last & ~(_msk)) # then update bits by `or`ing with a masked RHS From f4de9da83a8d07bdb8ba000efb036537c69107ae Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 3 Oct 2022 23:52:39 -0400 Subject: [PATCH 14/22] more tests --- test/bitarray.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index 37ee2b0522dc4..866711dc55080 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1510,11 +1510,17 @@ timesofar("reductions") end b3 = bitrand(l) + b4 = bitrand(l+extra_len) for op in (|, ⊻) - map!(op, b1, b2) + map!(op, b1, b2, b3) @test first(b1, l) == map(op, b2, b3) # check we didn't change bits we're not suppose to @test last(b1, extra_l) == original_tail + + map!(op, b1, b2, b4) + @test first(b1, l) == map(op, b2, b4) + # check we didn't change bits we're not suppose to + @test last(b1, extra_l) == original_tail end end end From 9bb987d5c185c61214b4dd828e6534522da30e9d Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Tue, 4 Oct 2022 11:24:13 -0400 Subject: [PATCH 15/22] Update test/bitarray.jl Co-authored-by: Cameron Bieganek <8310743+CameronBieganek@users.noreply.github.com> --- test/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index 866711dc55080..9655ac3e5dad0 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1510,7 +1510,7 @@ timesofar("reductions") end b3 = bitrand(l) - b4 = bitrand(l+extra_len) + b4 = bitrand(l+extra_l) for op in (|, ⊻) map!(op, b1, b2, b3) @test first(b1, l) == map(op, b2, b3) From 03d5510abd61d36bace27bc823ad63a3bc7c4524 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Tue, 4 Oct 2022 11:40:52 -0400 Subject: [PATCH 16/22] more tests and diagram --- base/bitarray.jl | 3 +-- test/bitarray.jl | 36 +++++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index ccc467801c8e0..f1d744818b2cb 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1797,8 +1797,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F - length(A) <= length(dest) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) - length(B) <= length(dest) || throw(DimensionMismatch("size of dest must be >= than size of A and B")) + min(length(A), length(B)) <= length(dest) || throw(DimensionMismatch("size of dest must be >= than size of A or B")) isempty(A) && return dest isempty(B) && return dest destc = dest.chunks diff --git a/test/bitarray.jl b/test/bitarray.jl index 9655ac3e5dad0..cda4dd3b7ac62 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1495,32 +1495,46 @@ timesofar("reductions") @test C17970::BitArray{1} == map(~, A17970) end + #= + |<----------------dest----------(original_tail)->| + |<------------------b2(l)------>| extra_l | + |<------------------b3(l)------>| + |<------------------b4(l+extra_l)--------------->| + |<--------------desk_inbetween-------->| extra÷2 | + =# @testset "Issue #47011, map! over unequal length bitarray" begin for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] for extra_l = [10, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] - b1 = bitrand(l+extra_l) + dest = bitrand(l+extra_l) b2 = bitrand(l) - original_tail = last(b1, extra_l) + original_tail = last(dest, extra_l) for op in (!, ~) - map!(op, b1, b2) - @test first(b1, l) == map(op, b2) + map!(op, dest, b2) + @test first(dest, l) == map(op, b2) # check we didn't change bits we're not suppose to - @test last(b1, extra_l) == original_tail + @test last(dest, extra_l) == original_tail end b3 = bitrand(l) b4 = bitrand(l+extra_l) + # when dest is longer than one source but shorter than the other + dest_inbewteen = bitrand(l + extra_l÷2) + original_tail_inbetween = last(dest_inbewteen, extra_l÷2) for op in (|, ⊻) - map!(op, b1, b2, b3) - @test first(b1, l) == map(op, b2, b3) + map!(op, dest, b2, b3) + @test first(dest, l) == map(op, b2, b3) # check we didn't change bits we're not suppose to - @test last(b1, extra_l) == original_tail + @test last(dest, extra_l) == original_tail - map!(op, b1, b2, b4) - @test first(b1, l) == map(op, b2, b4) + map!(op, dest, b2, b4) + @test first(dest, l) == map(op, b2, b4) # check we didn't change bits we're not suppose to - @test last(b1, extra_l) == original_tail + @test last(dest, extra_l) == original_tail + + map!(op, dest_inbewteen, b2, b4) + @test first(dest_inbetween, l) == map(op, b2, b4) + @test last(dest_inbetween, extra_l÷2) == original_tail_inbetween end end end From 2fee4c43ca046efd447d4b676c8ab064198aba96 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Tue, 4 Oct 2022 13:37:00 -0400 Subject: [PATCH 17/22] Update base/bitarray.jl Co-authored-by: Cameron Bieganek <8310743+CameronBieganek@users.noreply.github.com> --- base/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index f1d744818b2cb..3be6a0d6854cc 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1779,7 +1779,7 @@ end # map across the chunks. Otherwise, fall-back to the AbstractArray method that # iterates bit-by-bit. function bit_map!(f::F, dest::BitArray, A::BitArray) where F - length(A) <= length(dest) || throw(DimensionMismatch("length of dest must be >= than length of A")) + length(A) <= length(dest) || throw(DimensionMismatch("length of destination must be >= length of collection")) isempty(A) && return dest destc = dest.chunks Ac = A.chunks From 96205c964ad6af86cae4e1b17b8140c8d4326a2c Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Tue, 4 Oct 2022 13:37:06 -0400 Subject: [PATCH 18/22] Update base/bitarray.jl Co-authored-by: Cameron Bieganek <8310743+CameronBieganek@users.noreply.github.com> --- base/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 3be6a0d6854cc..ece6dd360ff09 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1797,7 +1797,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F - min(length(A), length(B)) <= length(dest) || throw(DimensionMismatch("size of dest must be >= than size of A or B")) + min(length(A), length(B)) <= length(dest) || throw(DimensionMismatch("length of destination must be >= length of smallest input collection")) isempty(A) && return dest isempty(B) && return dest destc = dest.chunks From be34441a010ac38beb3bbe30f1514ce1df4c5d02 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Sat, 8 Oct 2022 00:17:51 -0400 Subject: [PATCH 19/22] fix typo --- test/bitarray.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index cda4dd3b7ac62..92e3c629c8b3d 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1519,8 +1519,8 @@ timesofar("reductions") b3 = bitrand(l) b4 = bitrand(l+extra_l) # when dest is longer than one source but shorter than the other - dest_inbewteen = bitrand(l + extra_l÷2) - original_tail_inbetween = last(dest_inbewteen, extra_l÷2) + dest_inbetween = bitrand(l + extra_l÷2) + original_tail_inbetween = last(dest_inbetween, extra_l÷2) for op in (|, ⊻) map!(op, dest, b2, b3) @test first(dest, l) == map(op, b2, b3) @@ -1532,7 +1532,7 @@ timesofar("reductions") # check we didn't change bits we're not suppose to @test last(dest, extra_l) == original_tail - map!(op, dest_inbewteen, b2, b4) + map!(op, dest_inbetween, b2, b4) @test first(dest_inbetween, l) == map(op, b2, b4) @test last(dest_inbetween, extra_l÷2) == original_tail_inbetween end From ec39ca3386107fc894c63e5fad843794c39ee056 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 10 Oct 2022 18:16:22 -0400 Subject: [PATCH 20/22] fix --- base/bitarray.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index ece6dd360ff09..4662c4950b077 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1791,13 +1791,14 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F dest_last = destc[len_Ac] _msk = _msk_end(A) # first zero out the bits mask is going to change - destc[len_Ac] = (dest_last & ~(_msk)) + destc[len_Ac] = (dest_last & (~_msk)) # then update bits by `or`ing with a masked RHS - destc[len_Ac] |= f(Ac[end]) & _msk + destc[len_Ac] |= f(Ac[len_Ac]) & _msk dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F - min(length(A), length(B)) <= length(dest) || throw(DimensionMismatch("length of destination must be >= length of smallest input collection")) + min_bitlen = min(length(A), length(B)) + min_bitlen <= length(dest) || throw(DimensionMismatch("length of destination must be >= length of smallest input collection")) isempty(A) && return dest isempty(B) && return dest destc = dest.chunks @@ -1809,7 +1810,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F end # the last effected UInt64's original content dest_last = destc[len_Ac] - _msk = _msk_end(len_Ac) + _msk = _msk_end(min_bitlen) # first zero out the bits mask is going to change destc[len_Ac] = (dest_last & ~(_msk)) # then update bits by `or`ing with a masked RHS From cde51954f73eacfac2916e9eaa02f69eafe71466 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 10 Oct 2022 18:19:53 -0400 Subject: [PATCH 21/22] whitespace --- test/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index 92e3c629c8b3d..bd7f8a2cf55cf 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1531,7 +1531,7 @@ timesofar("reductions") @test first(dest, l) == map(op, b2, b4) # check we didn't change bits we're not suppose to @test last(dest, extra_l) == original_tail - + map!(op, dest_inbetween, b2, b4) @test first(dest_inbetween, l) == map(op, b2, b4) @test last(dest_inbetween, extra_l÷2) == original_tail_inbetween From 5350ca1488e5ae1b070c318b2d1157826463c281 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Mon, 10 Oct 2022 19:07:49 -0400 Subject: [PATCH 22/22] white space --- test/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index bd7f8a2cf55cf..05abd610682a2 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -1531,7 +1531,7 @@ timesofar("reductions") @test first(dest, l) == map(op, b2, b4) # check we didn't change bits we're not suppose to @test last(dest, extra_l) == original_tail - + map!(op, dest_inbetween, b2, b4) @test first(dest_inbetween, l) == map(op, b2, b4) @test last(dest_inbetween, extra_l÷2) == original_tail_inbetween