Here is my current conclusions:
function cartesian(l::Vararg{AbstractVector{T}})where T
v=vec(collect(Iterators.product(l...)))
end
f(n)=cartesian([1:i for i in 2:rand(n:n)]...)
function cartesian1(l::Vararg{AbstractVector{T}})::Matrix{T} where T
v=vec(collect(Iterators.product(l...)))
[y[i] for y in v,i in 1:length(l)]
end
g(n)=cartesian1([1:i for i in 2:rand(n:n)]...)
In the above cartesian
is the fastest. However f is not-stable because I do not know how to describe
the output type of cartesian
. On the other hand, g is type-stable because I can describe the type of cartesian1
. Thus even though f is faster than g, amidst a longer piece of code g performs better.
cartesian1 is not as fast as cartesian, but would be if I could transform more efficiently v in an array.
Any thoughts on that?