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

Indexed assignment with logical indices: subarray.jl error #45903

Closed
sebastiantk opened this issue Jul 1, 2022 · 0 comments · Fixed by #45904
Closed

Indexed assignment with logical indices: subarray.jl error #45903

sebastiantk opened this issue Jul 1, 2022 · 0 comments · Fixed by #45904

Comments

@sebastiantk
Copy link

Hi,

I have run into the following error:
I have a BitArray whose entries I want to change based on another array

A = BitArray(rand(0:1, 3,3))
pos = randn(3,3)
A[pos .< 0]  .= 0

This yields the error message:

ERROR: ArgumentError: number of indices (1) must match the parent dimensionality (2)
Stacktrace:
[1] check_parent_index_match(parent::BitMatrix, #unused#::Tuple{Bool})
@ Base ./subarray.jl:43
[2] check_parent_index_match(parent::BitMatrix, indices::Tuple{Vector{Int64}})
@ Base ./subarray.jl:41
[3] SubArray
@ ./subarray.jl:21 [inlined]
[4] SubArray
@ ./subarray.jl:32 [inlined]
[5] SubArray
@ ./subarray.jl:28 [inlined]
[6] materialize!(B::Base.Broadcast.BitMaskedBitArray{2, 2}, bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(identity), Tuple{Int64}})
@ Base.Broadcast ./broadcast.jl:1174
[7] top-level scope
@ REPL[10]:1

The indexing works without an error, the error only appears when I try to assign the new value.

Also, using Cartesian indices instead produces the expected result:

A = BitArray(rand(0:1, 3,3))
pos = randn(3,3)
A[findall(pos .< 0)]  .= 0

versioninfo()
Julia Version 1.7.2
Commit bf53498 (2022-02-06 15:21 UTC)
Platform Info:
OS: macOS (arm64-apple-darwin21.2.0)
CPU: Apple M1 Pro
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, cyclone)
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =

@giordano giordano linked a pull request Jul 3, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant