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

Don't call vec in stack_rest? #10

Closed
mcabbott opened this issue Apr 27, 2020 · 0 comments · Fixed by #14
Closed

Don't call vec in stack_rest? #10

mcabbott opened this issue Apr 27, 2020 · 0 comments · Fixed by #14

Comments

@mcabbott
Copy link
Owner

From https://discourse.julialang.org/t/efficient-way-of-turning-iterator-into-a-matrix/38309:

julia> nums = (i^2 for i in Iterators.filter(_->rand(Bool), 1:100));

julia> Base.haslength(nums)
false

julia> stack(nums)'
1×44 LinearAlgebra.Adjoint{Int64,Array{Int64,1}}:
 1  4  9  49  81  144  196  324  361  400  484  529    6241  6561  7396  7744  7921  8649  10000

julia> vecs = ([i,i^2] for i in Iterators.filter(_->rand(Bool), 1:100));

julia> stack(vecs)
2×54 Array{Int64,2}:
 2   7   9   10   11   13   14   16   17   18   20      90    92    94    95    96    98    100
 4  49  81  100  121  169  196  256  289  324  400     8100  8464  8836  9025  9216  9604  10000

julia> tups = ((i,i^2) for i in Iterators.filter(_->rand(Bool), 1:100));

julia> stack(tups)
ERROR: MethodError: no method matching vec(::Tuple{Int64,Int64})

julia> stack((i,i^2) for i in  1:100) # with a length, no problem
2×100 Array{Int64,2}:
 1  2  3   4   5   6   7   8   9   10   11   12      94    95    96    97    98    99    100
 1  4  9  16  25  36  49  64  81  100  121  144     8836  9025  9216  9409  9604  9801  10000
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