Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.9.2 Base.map!(|,a,a,b) yields wrong answer on BitVector #50780

Closed
StephenVavasis opened this issue Aug 3, 2023 · 7 comments · Fixed by #50781
Closed

1.9.2 Base.map!(|,a,a,b) yields wrong answer on BitVector #50780

StephenVavasis opened this issue Aug 3, 2023 · 7 comments · Fixed by #50781
Labels
kind:bug Indicates an unexpected problem or unintended behavior

Comments

@StephenVavasis
Copy link
Contributor

StephenVavasis commented Aug 3, 2023

The testset for the DataStructures.jl package are now failing in 1.9.2. In particular, IntSet is not working. I have traced the error to a bug with the Base.map! function applied to BitVector. See below for the incorrect output from map!:

EDIT: I did not report this bug correctly in my first post. The bug is actually with map!(|,a,a,b) not with map!(|,a,b). Please refer to my follow-up post below.

julia> a = BitVector([1,1,0,0,1,1,0,0]);

julia> b = BitVector([1,0,1,0,1,0,1,0]);

julia> map!(|, a, b);

julia> a
8-element BitVector:
 1
 0
 1
 0
 1
 0
 1
 0
@adienes
Copy link
Contributor

adienes commented Aug 3, 2023

that looks correct to me, what output were you expecting?

note that map! here is doing something equivalent to a .= .|(b), not a .= .|(a, b)

@StephenVavasis
Copy link
Contributor Author

You are right, sorry. I will close this issue. But I am now confused how union of two IntSets is supposed to work since it seems to rely on map!(|,a,b) replacing a with the bitwise OR of a and b in line 94 of int_set.jl in the DataStructures package. And apparently this statement worked fine in pre-1.9 versions of Julia.

@oscardssmith
Copy link
Member

well that doesn't work in 1.8.5 at least...

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.5 (2023-01-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> map!(|, [false, true], [true, false])
2-element Vector{Bool}:
 1
 0

julia> map!(|, BitVector([false, true]), BitVector([true, false]))
2-element BitVector:
 1
 0

@StephenVavasis StephenVavasis reopened this Aug 3, 2023
@StephenVavasis
Copy link
Contributor Author

Wait! There is a new bug in Base.map! I am reopening this issue. Here is the bug. It is with map!(a,a,b), not map!(a,b) as I said earlier. Sorry for the confusion. I have confirmed that this behavior has changed since 1.6.7.

julia> a = BitVector([1,1,0,0,1,1,0,0]);

julia> b = BitVector([1,0,1,0,1,0,1,0]);

julia> map!(|,a,a,b);

julia> a
8-element BitVector:
 1
 0
 1
 0
 1
 0
 1
 0

@oscardssmith
Copy link
Member

Specifically the problem is new in 1.9 and affects the last chunk of the array and is caused by #47013.

@oscardssmith
Copy link
Member

For another related bug:

julia> a = BitVector([1,0])
2-element BitVector:
 1
 0

julia> map!(!, a, a)
2-element BitVector:
 1
 1

@StephenVavasis StephenVavasis changed the title 1.9.2 Base.map! error with BitVector 1.9.2 Base.map!(|,a,a,b) yields wrong answer on BitVector Aug 3, 2023
@oscardssmith
Copy link
Member

luckily it's easy to fix. Thanks for the report!

@brenhinkeller brenhinkeller added the kind:bug Indicates an unexpected problem or unintended behavior label Aug 3, 2023
oscardssmith added a commit that referenced this issue Aug 5, 2023
KristofferC pushed a commit that referenced this issue Aug 10, 2023
fixes #50780 caused by #47013.

(cherry picked from commit 3e04129)
KristofferC pushed a commit that referenced this issue Aug 10, 2023
fixes #50780 caused by #47013.

(cherry picked from commit 3e04129)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants