If it's in a function, you can just make the function generic, but a bigger
issue is that that push! pattern is bound to be quite slow. It's *much*
better if you can allocate the entire array up front. I'm having a hard
time coming up with examples based on what you wrote – it's a little too
vague. Do you have a more specific example?




On Thu, May 1, 2014 at 12:19 PM, Ethan Anderes <ethanande...@gmail.com>wrote:

> I have a question which is somewhat related to this question (
> https://groups.google.com/forum/m/?fromgroups#!topic/julia-users/bldp27KJCjY)
> but mine is more of a style question rather than a language design question.
>
> I find myself often  filling an array of Array{Float64,1}'s in julia.
> I usually do this by initializing an empty array then using push!
>
> x = Array{Float64,1}[]
> while someconditional
>         nextvec = getvec(...)
>         push!(x,nextvec)
> end
>
> I'm wondering how to make the Float64 specification more flexible so that
> the code works when used by someone on a machine using Float32, for
> example, but still keep the performance of having the entries of x all a
> homogeneous type. I would be tempted to initialize
> x=Array{FloatingPoint,1}[] but that allows some entries of x to be
> Array{Float64,1} and others to be Array{Float32,1} for example.
>
>
>
>

Reply via email to