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

copyto! dispatches incorrectly for BitVector #25968

Closed
jamii opened this issue Feb 9, 2018 · 3 comments · Fixed by #46161
Closed

copyto! dispatches incorrectly for BitVector #25968

jamii opened this issue Feb 9, 2018 · 3 comments · Fixed by #46161
Labels
domain:arrays [a, r, r, a, y, s] kind:bug Indicates an unexpected problem or unintended behavior

Comments

@jamii
Copy link
Contributor

jamii commented Feb 9, 2018

julia> a = BitVector([true, false, true])
3-element BitArray{1}:
  true
 false
  true

julia> unsafe_copyto!(a, 2, a, 1, 2)
3-element BitArray{1}:
  true
  true
 false

julia> a = BitVector([true, false, true])
3-element BitArray{1}:
  true
 false
  true

julia> copyto!(a, 2, a, 1, 2)
3-element BitArray{1}:
 true
 true
 true

julia> @which unsafe_copyto!(a, 2, a, 1, 2)
unsafe_copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray, Array}, soffs::Integer, n::Integer) in Base at bitarray.jl:419

julia> @which copyto!(a, 2, a, 1, 2)
copyto!(dest::AbstractArray, dstart::Integer, src::AbstractArray, sstart::Integer, n::Integer) in Base at abstractarray.jl:724

julia> versioninfo()
Julia Version 0.7.0-DEV.3736
Commit 4b1cf22f98 (2018-02-06 16:41 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E3-1505M v5 @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, skylake)
Environment:

This is also broken on v0.6.2.

@JeffBezanson JeffBezanson added kind:bug Indicates an unexpected problem or unintended behavior domain:arrays [a, r, r, a, y, s] labels Feb 9, 2018
@mbauman
Copy link
Sponsor Member

mbauman commented Feb 9, 2018

Thanks! Looks like the BitArray version has aliasing detection, but the generic version doesn't. As you noted, this specific case is a simple fix — we just need to add a copyto! method that checks bounds and dispatches appropriately.

@JeffBezanson
Copy link
Sponsor Member

unsafe_copyto! has an argument src::Union{BitArray,Array}, while copyto! has src::Array. We might just need to use the same Union type in both cases.

@HyperSphereStudio
Copy link

I just ran into this bug in my code, I looked over my logic so many times but I finally figured out it was this issue.

I ran jamii's code on my repl:

julia> a = BitVector([true, false, true])
3-element BitVector:
 1
 0
 1

julia> unsafe_copyto!(a, 2, a, 1, 2)
3-element BitVector:
 1
 1
 0

julia> a = BitVector([true, false, true])
3-element BitVector:
 1
 0
 1

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

julia> @which unsafe_copyto!(a, 2, a, 1, 2)
unsafe_copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray, Array}, soffs::Integer, n::Integer) in Base at bitarray.jl:456

julia> @which copyto!(a, 2, a, 1, 2)
copyto!(dest::AbstractArray, dstart::Integer, src::AbstractArray, sstart::Integer, n::Integer) in Base at abstractarray.jl:1057

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_DIR = C:\Users\JohnB\AppData\Local\Programs\Julia-1.7.0```

fredrikekre pushed a commit that referenced this issue Jul 25, 2022
1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`
KristofferC pushed a commit that referenced this issue Aug 6, 2022
1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`

(cherry picked from commit 0ea2b2d)
ffucci pushed a commit to ffucci/julia that referenced this issue Aug 11, 2022
…uliaLang#46161)

1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`
pcjentsch pushed a commit to pcjentsch/julia that referenced this issue Aug 18, 2022
…uliaLang#46161)

1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`
KristofferC pushed a commit that referenced this issue Dec 21, 2022
1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`

(cherry picked from commit 0ea2b2d)
KristofferC pushed a commit that referenced this issue Dec 21, 2022
1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`

(cherry picked from commit 0ea2b2d)
KristofferC pushed a commit that referenced this issue Dec 21, 2022
1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`

(cherry picked from commit 0ea2b2d)
KristofferC pushed a commit that referenced this issue Dec 21, 2022
1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`

(cherry picked from commit 0ea2b2d)
staticfloat pushed a commit that referenced this issue Dec 23, 2022
1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`

(cherry picked from commit 0ea2b2d)
KristofferC pushed a commit that referenced this issue Oct 10, 2023
1. map `copyto!(::BitArray, n1, ::BitArray, n2, l)` to `Base.unsafe_copyto!`
2. add missing unaliasing in `copyto!` for `AbstractArray`

(cherry picked from commit 0ea2b2d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s] kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants