Jeff's approach should be included in the performance hints doc

On Tuesday, October 11, 2016 at 1:04:43 PM UTC-4, Jeff Bezanson wrote:
>
> If the performance of this matters, it will probably be faster to 
> iterate over `1:nfields(myt)`, as that will avoid (1) constructing the 
> array of symbols, (2) looking up the index within the type for that 
> field. 
>
> On Mon, Oct 10, 2016 at 7:20 PM, K leo <cnbi...@gmail.com <javascript:>> 
> wrote: 
> > Thanks so much Mauro.  That does it. 
> > 
> > On Monday, October 10, 2016 at 10:58:30 PM UTC+8, Mauro wrote: 
> >> 
> >> Try 
> >> 
> >> for fl in fieldnames(myt) 
> >>    push!(getfield(myt,fl), 0.) 
> >> end 
> >> 
> >> `fieldnames` returns the name of the field as a symbol, thus your 
> error. 
> >> 
> >> On Mon, 2016-10-10 at 16:41, K leo <cnbi...@gmail.com> wrote: 
> >> > I hope to expand all arrays in a type using something like the 
> >> > following: 
> >> > 
> >> > fields=fieldnames(myType) 
> >> >> for i=1:length(fields) 
> >> >>     push!(fields[i], 0.) 
> >> >> end 
> >> > 
> >> > 
> >> > But I get error saying no method matching push!(::Symbol, ::Float64) 
> >> > 
> >> > What else can I do for my purpose? 
>

Reply via email to