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

Array/vector comprehension and AbstractTrees Leaves iterator #138

Open
pitsianis opened this issue Aug 1, 2023 · 1 comment
Open

Array/vector comprehension and AbstractTrees Leaves iterator #138

pitsianis opened this issue Aug 1, 2023 · 1 comment

Comments

@pitsianis
Copy link

pitsianis commented Aug 1, 2023

Why the array comprehension behaves differently with the AbstractTrees.Leaves iterator?
In the following replacing Leaves(t) with, say, range(1,3,3), I do get the 2D array.

julia> using AbstractTrees

julia> t = [[1, 2], 3]
2-element Vector{Any}:
  [1, 2]
 3

julia> [(i,j) for i in Leaves(t), j in Leaves(t) ]
9-element Vector{Tuple{Int64, Int64}}:
 (1, 1)
 (2, 1)
 (3, 1)
 (1, 2)
 (2, 2)
 (3, 2)
 (1, 3)
 (2, 3)
 (3, 3)

julia> [(i,j) for i in collect(Leaves(t)), j in collect(Leaves(t)) ]
3×3 Matrix{Tuple{Int64, Int64}}:
 (1, 1)  (1, 2)  (1, 3)
 (2, 1)  (2, 2)  (2, 3)
 (3, 1)  (3, 2)  (3, 3)
@pitsianis
Copy link
Author

The Leaves iterator does not provide a length, so the array comprehension does not know the shape of the array. Perhaps that is the reason?

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

1 participant