I was just trying to use pdf_norm
from the stdlib
until my compiler kindly gave me the bad news that this function is impure… As such, it can’t be used in pure procedures and do concurrent
loops, which, IMO, significantly limits its practical application. Probably, the same occurs in many other stdlib
modules/procedures.
As far as I can see it, the impure attribute comes from the choice of calling the impure procedure error_stop()
… Hence, my question:
- Is the “benefit” of calling the impure procedure
error_stop()
– versus what could be achieved with a pureerror stop message
– really worth the cost of downgrading the whole procedure to impure?
#:for k1, t1 in REAL_KINDS_TYPES
impure elemental function pdf_norm_${t1[0]}$${k1}$(x, loc, scale) result(res)
!
! Normal distribution probability density function
!
${t1}$, intent(in) :: x, loc, scale
${t1}$ :: res
${t1}$, parameter :: sqrt_2_pi = sqrt(2.0_${k1}$ * acos(-1.0_${k1}$))
if(scale == 0._${k1}$) call error_stop("Error(pdf_norm): Normal" &
//"distribution scale parameter must be non-zero")
res = exp(- 0.5_${k1}$ * ((x - loc) / scale) * (x - loc) / scale) / &
(sqrt_2_Pi * scale)
end function pdf_norm_${t1[0]}$${k1}$
#:endfor