Milan,

Thanks for this!  That is quite a difference, I might be making some 
changes to my code!

Chris

On Thursday, January 28, 2016 at 5:36:07 AM UTC-5, Milan Bouchet-Valat 
wrote:
>
> Le mercredi 27 janvier 2016 à 22:37 -0800, Christopher Alexander a 
> écrit : 
> > Try something like this: 
> > 
> > adjCloseMuVec = Vector{Float32}(nFullYears) 
> > or 
> > adjCloseMuVec = zeros(Float32, nFullYears) 
> > 
> > This will init a vector of the proper size.  I think zeros is 
> > slightly faster, but someone can correct me if that is not the case. 
> Actually that's the other way around. zeros() is slower because it 
> needs to fill the array with zeros. You can check this with some very 
> simple benchmarking: 
>
> julia> f() = for i in 1:100000 adjCloseMuVec = Vector{Float32}(10000) end 
> f (generic function with 1 method) 
>
> julia> g() = for i in 1:100000 adjCloseMuVec = zeros(Float32, 10000) end 
> g (generic function with 1 method) 
>
> julia> @time f() 
>   0.164794 seconds (202.00 k allocations: 3.731 GB, 52.40% gc time) 
>
> julia> @time f() 
>   0.135390 seconds (200.00 k allocations: 3.731 GB, 52.57% gc time) 
>
> julia> @time g() 
>   1.184917 seconds (201.75 k allocations: 3.731 GB, 10.57% gc time) 
>
> julia> @time g() 
>   1.175267 seconds (200.00 k allocations: 3.731 GB, 10.38% gc time) 
>
>
> This overhead could be reduced/eliminated by using calloc, and could 
> even become the default, see 
> https://github.com/JuliaLang/julia/issues/9147 
>
> Given how high is the overhead, it looks like that change would be a 
> good idea. 
>
>
> Regards 
>
>
> > Chris 
> > 
> > On Thursday, January 28, 2016 at 1:26:09 AM UTC-5, Michael Landis 
> > wrote: 
> > > I am trying to compute some historical means and volatilities with 
> > > Julia, but I've been having some difficulty getting the 
> > > declarations and/or assignments right... 
> > > 
> > > When I try a declaration, like either of these: 
> > >   adjCloseMuVec::Vector{Float32};     # or... 
> > >   adjCloseMuVec::Vector{Float32,nFullYears}; 
> > > I get:  UndefVarError: adjCloseMuVec not defined 
> > >   
> > > When I try: 
> > > adjCloseMuVec = Vector{Float32};   # and later try: 
> > > reshape(adjCloseMuVec,nFullYears); 
> > > I get:  MethodError: `reshape` has no method matching 
> > > reshape(::Type{Array{Float32,1}}, ::Int32) 
> > > 
> > > When I try: 
> > > adjCloseMuVec = Vector{Float32,nFullYears}; 
> > > I get: too many parameters for type typealias 
> > > 
> > > So, the only acceptable path would seem to be: 
> > > adjCloseMuVec = Vector{Float32}; 
> > > but when I later try: 
> > > adjCloseMuVec[curYr] = Float32(adjCloseMu);   # or... 
> > > setindex!(adjCloseMuVec, Float32(adjCloseMu), curYr); 
> > > I get: MethodError: `setIndex!` has no method matching 
> > > setindex!(::Type{Array{Float32,1}}, ::Float32, ::Int64) 
> > > 
> > > So, I'm mystified as to the correct syntax.  Any suggestions on an 
> > > acceptable way to declare a Vector of Int32 and load values into 
> > > it? 
> > > 
>

Reply via email to