-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
1D comprehensions with multiple variables #4867
Comments
I think the |
What about the use of two L = [ i+j for i=1:10 for j=i:10 if (i+j)%2>0 ] # returns a 1D array See my comment #550 (comment) |
Yeah that's a good idea. |
I'm not super keen on the double |
|
If the I also think the I like @RaulDurand proposal, but the other way around is also possible: double for to get a matrix and comma's to vectorize. |
I like @daviddelaat proposal, feels much more natural than 2 |
That would also break all existing code that uses multidimensional arrays. |
Actually I'd like |
+1 for product |
May be I am wrong but children = Child[]
for parent in parents
for child in parent.children
push!(children, child)
end
end On the other hand, trying to make a direct translation into a comprehension we could have: children = [ child for parent in parents for child in parent.children ] or even, including an children = [ child for parent in parents for child in parent.children if child.age<12 ] When I work with finite elements, usually I have to do: all_dofs = Dof[]
for elem in elems
for node in elem.nodes
for dof in node.dofs
push!(all_dofs, dof)
end
end
end A similar translation into a comprehension leads to: all_dofs = [ dof for elem in elems for node in elem.nodes for dof in node.dofs ] The use of multiple IMHO, I think that the use of commas are ok for multidimensional arrays since it is similar to the use of commas for indexing (for example A[i,j] or B[i,j,k]) and the array sizes in each dimension are known a priori. |
this also uses the new lowering for typed comprehensions, allowing all comprehensions on unknown-length iterables (fixes #1457)
this also uses the new lowering for typed comprehensions, allowing all comprehensions on unknown-length iterables (fixes #1457)
this also uses the new lowering for typed comprehensions, allowing all comprehensions on unknown-length iterables (fixes #1457)
this also uses the new lowering for typed comprehensions, allowing all comprehensions on unknown-length iterables (fixes #1457)
JuliaLang#4867) this also uses the new lowering for typed comprehensions, allowing all comprehensions on unknown-length iterables (fixes JuliaLang#1457)
I just tried to do
Unfortunately, this produces an error that
i
is undefined, since this produces a 2D array in Julia.Related to discussion in #550, especially #550 (comment), but there, the proposal is to force 1D array creation in the presence of an
if
clause (which makes sense).I'm not sure there's a good solution here, mainly because I don't know how popular/common the 2D comprehension syntax is.
The text was updated successfully, but these errors were encountered: