Le dimanche 28 février 2016 à 21:33 +0100, FQ a écrit : > for documentation, see > > http://docs.julialang.org/en/release-0.4/manual/documentation/#functions-methods See also https://github.com/JuliaLang/julia/pull/15136
> so, you could put that last sentence of your documentation above the > array implementation, and in single double quotes. When someone uses > ?calcWindAtHeight in REPL, both documentation texts will be displayed > one after another > > note that you mixed up the words "function" and "method" in your > email; > a method is a specific implementation for a type, and a function is > the > entirety of all its methods. so in your example you have a function > "calcWindAtHeight", which has two methods. > > Am 28.02.2016 um 21:12 schrieb Uwe Fechner: > > > > Thank's a lot! > > > > My code looks now like this: > > > > const Z_REF = 10.0 # reference height for wind profile law > > const ALPHA = 0.23375 # exponent of the wind profile law for Cabauw > > > > """ > > calcWindAtHeight(v_wind_gnd, z) > > > > Calculate the average wind speed for the given ground wind speed > > `v_wind_gnd` at a given height `z`. > > The ground wind speed is measured at the height `Z_REF`, a > > constant, > > that must have been defined > > before. The exponential wind profile law is used in combination > > with the > > exponent `ALPHA`, that must > > have been defined before, too. If `z` is an array, the method will > > return an array. > > """ > > function calcWindAtHeight(v_wind_gnd, z::AbstractFloat) > > v_wind_gnd * (z / Z_REF)^ALPHA > > end > > > > function calcWindAtHeight(v_wind_gnd, Z::AbstractArray) > > [calcWindAtHeight(v_wind_gnd, z) for z in Z] > > end > > > > I tried to write the comment only once, now. Is this the correct > > way to > > document > > a method with two functions? > > > > Uwe > > > > On Sunday, February 28, 2016 at 8:56:57 PM UTC+1, FQ wrote: > > > > you can get the vectorized version in one line using a > > comprehension: > > > > calcWindAtHeight(v_wind_gnd, Z::AbstractArray) = > > [calcWindAtHeight(v_wind_gnd,z) for z in Z] > > > > i did a quick test and it seems to be about the same > > speed/slightly > > faster than your version. > > > > you could also use map and a lambda function: > > calcWindAtHeight(v_wind_gnd, Z::AbstractArray) = > > map((z)->calcWindAtHeight(v_wind_gnd,z),Z) > > > > this seems to be significantly slower though, so i'd recommend > > the > > comprehension. > > > > PS: if you do want to do speed tests, you can use the @time > > macro, just > > put it in front of your function call > >
