Where is the `pdf` function in Distribution.jl implemented?

Hello Julia community,

julia> pdf(Normal(), 0.3)

I want to know how the pdf function is implemented, but the source code for Distribution.jl tells me nothing (in fact it looks like an infinite loop).

Am I missing something? Wouldn’t there at least have to have a 2\pi somewhere?

julia-1.1> d = Normal()
julia-1.1> @less pdf(d, 0.3) # shows this is implemented via a macro, so try something else
julia-1.1> @code_lowered pdf(d,0.3)
1 ─ %1 = (Base.getproperty)(d, :μ)
│   %2 = (Base.getproperty)(d, :σ)
│   %3 = (Distributions.normpdf)(%1, %2, x)
└──      return %3

julia-1.1> @less Distributions.normpdf(0.0,1.0,0.3) # this is what you want

Page up to see your beloved constant.


In case it is not clear: pdf and other relevant functions are implemented in StatsFuns.jl.


Technically, functions are not implemented, methods are. What you linked are some generic fallback methods for dealing with some general cases (and the first one doesn’t look like a function definition at all, maybe a bug?).

You can also use

@edit pdf(Normal(), 0.3)

to take you to the source code (if your editor is set up properly).

In this case it takes you to a macro defining functions using primitives from StatsFuns, which I agree is rather opaque.