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

creation of BitArray using comprehension #3166

Closed
diegozea opened this issue May 21, 2013 · 6 comments
Closed

creation of BitArray using comprehension #3166

diegozea opened this issue May 21, 2013 · 6 comments
Assignees
Milestone

Comments

@diegozea
Copy link
Contributor

Now is necessary create a Bool Array using list comprehension an after that make the conversion to BitArray:

julia> BitArray[ ab_index_array[res]!=0 for res in seq ]
ERROR: no method convert(Type{BitArray{N}},Bool)
 in anonymous at no file

julia> Bool[ab_index_array[res]!=0 for res in seq ]
100000000-element Bool Array:
 false
  true
      ⋮
 false
 false

julia> convert(BitArray,Bool[ab_index_array[res]!=0 for res in seq ])
100000000-element BitArray:
 false
  true
     ⋮
 false
 false
@PythonNut
Copy link
Contributor

On another note, can we also make a Nullable{T} comprehension into an NullableArray{T,1} (discussed in #8423)?

@StefanKarpinski
Copy link
Member

This seem to call for some more general mechanism. The same thing would be handy for using array literals that contain null to construct NullableArray objects.

@PythonNut
Copy link
Contributor

Is there any way we can do something like C++ template specializations, and make the in-memory representation of a Array{Nullable{T},1} identical to a NullableArray{T,1}?

@johnmyleswhite
Copy link
Member

I think there's two separate issues here:

  • The array-of-structs to struct-of-arrays transform needed to turn Array{Nullable{T}} into NullableArray{T}
  • The ability to use something like list comprehensions that generates something other than an array as output.

Both are interesting, although the second point seems to cause more trouble for beginners (who don't seem to think about the first point) since they keep failing to understand why comprehensions don't produce DataArray objects.

@StefanKarpinski StefanKarpinski modified the milestones: 0.6.0, 1.0 Sep 13, 2016
@stevengj
Copy link
Member

This should be do-able with the new generalized comprehension syntax, but it looks like we need to add a constructor method:

julia> BitVector(rand(Bool) for i = 1:10)
ERROR: MethodError: Cannot `convert` an object of type Base.Generator{UnitRange{Int64},##5#6} to an object of type BitArray{1}
This may have arisen from a call to the constructor BitArray{1}(...),
since type constructors fall back to convert methods.
 in BitArray{1}(::Base.Generator{UnitRange{Int64},##5#6}) at ./sysimg.jl:53

@carlobaldassi carlobaldassi self-assigned this Sep 22, 2016
@StefanKarpinski
Copy link
Member

Since we can use generators now, I'm removing the breaking label and accepting this.

@StefanKarpinski StefanKarpinski removed breaking This change will break code needs decision A decision on this change is needed labels Oct 11, 2016
carlobaldassi added a commit that referenced this issue Oct 19, 2016
in particular, can now use generators.
Fixes #3166
carlobaldassi added a commit that referenced this issue Oct 19, 2016
in particular, can now use generators.
Fixes #3166
carlobaldassi added a commit that referenced this issue Oct 19, 2016
in particular, can now use generators.
Fixes #3166
carlobaldassi added a commit that referenced this issue Oct 19, 2016
in particular, can now use generators.
Fixes #3166
fcard pushed a commit to fcard/julia that referenced this issue Feb 28, 2017
in particular, can now use generators.
Fixes JuliaLang#3166
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

No branches or pull requests

6 participants