So there is something unstated about the way matrices, tuples, and iterators (i.e., Base.Generator) work that is causing me problems. I can make the hard things work (except for a few installation issues), but I have trouble almost every day with the equivalent of for
loops or vectorization.
Today’s example is that I’m trying to build a matrix. The details of the problem are complicated, but the complicated stuff works fine. The simplification of the stuff that doesn’t work is:
samps = [3, 2, 5, 8, 3]
5-element Vector{Int64}:
3
2
5
8
3
temp = [map(x -> x^k, samps) for k = 1:3]
3-element Vector{Vector{Int64}}:
[3, 2, 5, 8, 3]
[9, 4, 25, 64, 9]
[27, 8, 125, 512, 27]
Great, but I wanted a matrix. Should be a trite change, but I’ve tried about a dozen different things and have yet to figure out something that works. Two examples of things I tried:
convert(Matrix{Int64}, temp)
MethodError: no method matching Matrix{Int64}(::Vector{Vector{Int64}})
and
temp1 = vcat(map(x -> x^k, samps) for k = 1:3)
1-element Vector{Base.Generator{UnitRange{Int64}, var"#5#7"}}:
Base.Generator{UnitRange{Int64}, var"#5#7"}(var"#5#7"(), 1:3)
collect(temp1)
1-element Vector{Base.Generator{UnitRange{Int64}, var"#5#7"}}:
Base.Generator{UnitRange{Int64}, var"#5#7"}(var"#5#7"(), 1:3)
I also looked for a fill like solution, but didn’t find it.
The best solution would be to create the matrix directly with a one liner, without copy, and without conversion. I don’t need the fastest possible solution (this is not the Focal Point of Amdahl’s Law for the larger application), within a factor of 2 or 3 of C would be great.