Julia: How to easily see the source code of a function (e.g. `quantile` function from Statistics.jl Package)

Viewed 1746

What is an easy way to see what are the exact computations done by a function (e.g. quantile function from Statistics.jl Package). The goal being here just to understand the computations done by that particular function and not edit the entire package.

Many thanks in advance

3 Answers

Look it up in the online docs:

https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.quantile

and click on the "source" link at the bottom of the function description.

Note that, like many functions in Base, the function name is used for several functions, to support multiple data types. This means that thoroughly studying the source will require looking at more than one function.

There's Base.functionloc, which will find you the file and line a method is defined in; but you have to specify the specific type of the method you want want to see as a tuple argument:

julia> functionloc(cos, (Float64,))
("/usr/local/julia-1.0.0/bin/../share/julia/base/special/trig.jl", 100)

julia> functionloc(cos)
ERROR: function has multiple methods; please specify a type signature
...

You can try the @less macro.

Evaluates the arguments to the function or macro call, determines their types, and calls the less function on the resulting expression.

Related