On Tuesday, 2 September 2014 03:00:10 UTC-4, Jason Merrill wrote: > > On Monday, September 1, 2014 2:33:31 PM UTC-7, Alex Townsend wrote: >> >> I have written a package FastGauss.jl available here: >> >> https://github.com/ajt60gaibb/FastGauss.jl >> > >> I am a Julia beginner (only been learning for 2 weeks) so I am assuming >> the code can be >> improved in a million and one ways. Please tell me if I've done something >> that Julia does >> not like. I am not sure if it is appropriate to make this an official >> package. >> > > One thing to look out for is making sure your functions have consistent > return types. E.g. in > https://github.com/ajt60gaibb/FastGauss.jl/blob/91e2ac656b856876563d5aacf7b5a405e068b3da/src/GaussLobatto.jl#L4 > > you have > Thanks! I tried to get the return types consistent, but obviously missed a few. I've been trying to use @code_typed to tell me this information, but reading the output is a little difficult (at the moment).
> > if ( n == 1 ) > error("Lobatto undefined for n = 1.") > elseif ( n == 2 ) > x = ([-1.0,1.0],[1.0,1.0]) > elseif ( n == 3 ) > x = ([-1, 0, 1], [1.0, 4.0, 1.0]/3) > # ... > > In the n==2 case, you're returning a tuple of two float vectors, but in > the n==3 case, you're returning a tuple with one Int vector and one float > vector. > > This issue crops up in a few other places, including sometimes returning a > number and other times returning a vector. > > Another thing you might want to consider is devectorizing compound > operations on vectors to avoid allocating containers to store intermediate > results (either using https://github.com/lindahua/Devectorize.jl or > manually). To pick one random place where this might be relevant: > https://github.com/ajt60gaibb/FastGauss.jl/blob/5e3a8a2f9a7e327622bdd43f69bb712afcb16743/src/GaussJacobi.jl#L36 > Good point. This makes a _huge_ difference in speed. Thank you. I had heard that devectorize was a good thing in Julia, but I'm from MATLAB where it's the opposite. I'll go through the code and update. > > I'm not 100% sure whether this will be relevant to your API, but many high > performance Julia libs expose mutating versions of functions (marked with > an ! at the end) that normally return arrays, allowing the caller to > instead pass in a preallocated array for the result to be stored in that > could potentially be reused from call to call. > OK. I'll have a closer look at some commands with the ! suffix. > > If a quadrature rule may in some cases be used only once, it might be nice > if there were a way to apply the quadrature method to a function on the fly > without ever generating the entire node and weight vector. > Thank you very much Jason.