Skip to content

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented May 25, 2016

This came up from the following behavior on my 64-bit system:

julia> BitArray(Int64(10))
10-element BitArray{1}:
 false
 false
 false
 false
 false
 false
 false
 false
 false
 false

julia> BitArray(Int32(10))
ERROR: MethodError: `convert` has no method matching convert(::Type{BitArray{N}}, ::Int32)
This may have arisen from a call to the constructor BitArray{N}(...),
since type constructors fall back to convert methods.
Closest candidates are:
  call{T}(::Type{T}, ::Any)
  convert{T,N}(::Type{BitArray{N}}, ::AbstractArray{T,N})
  convert{T}(::Type{T}, ::T)
  ...
 in call at essentials.jl:56

julia> falses(Int64(10))
10-element BitArray{1}:
 false
 false
 false
 false
 false
 false
 false
 false
 false
 false

julia> falses(Int32(10))
ERROR: MethodError: `convert` has no method matching convert(::Type{BitArray{N}}, ::Int32)
This may have arisen from a call to the constructor BitArray{N}(...),
since type constructors fall back to convert methods.
Closest candidates are:
  call{T}(::Type{T}, ::Any)
  convert{T,N}(::Type{BitArray{N}}, ::AbstractArray{T,N})
  convert{T}(::Type{T}, ::T)
  ...
 in call at essentials.jl:56
 in falses at bitarray.jl:238

CC: @carlobaldassi

base/bitarray.jl Outdated
end
nc = num_bit_chunks(n)
chunks = Array{UInt64}(nc)
chunks = Array(UInt64, nc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong conflict resolution with #16498

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I must have started editing this before pulling from master.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appveyor's getting confused about mergability again...

@tkelman tkelman closed this May 25, 2016
@tkelman tkelman reopened this May 25, 2016
@martinholters
Copy link
Member

You could use convert(Dims, dims) instead of map(Int,dims). IMHO the intention is clearer that way, and IIUC, the code generated when all entries in dims are already Int is also more efficient.

@carlobaldassi
Copy link
Member

LGTM. As far as I can tell from comparing the outputs of @code_llvm BitArray(10,10), the compiler is able to infer that map(Int,dims) is a no-op when dims is already Int.

@quinnj
Copy link
Member Author

quinnj commented May 31, 2016

Thanks for taking a look @carlobaldassi.

@quinnj quinnj merged commit 301156b into master May 31, 2016
@quinnj quinnj deleted the jq/bitarray branch May 31, 2016 13:07
@carlobaldassi
Copy link
Member

Should probably be backported, too.

@tkelman
Copy link
Contributor

tkelman commented May 31, 2016

Standard caveat that if you rely on this working, be careful about patch version in REQUIRE when a release with the backport is available.

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 this pull request may close these issues.

5 participants