Skip to content

Commit 99ce6e0

Browse files
committed
clean + add examples of call with sigma<=0 and do concurrent
1 parent 1abb80b commit 99ce6e0

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

example/stats_distribution_normal/example_normal_pdf.f90

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,56 @@ program example_normal_pdf
44
norm => rvs_normal
55

66
implicit none
7-
real :: x(3, 4, 5), a(3, 4, 5), b(3, 4, 5)
7+
real, dimension(3, 4, 5) :: x, mu, sigma
8+
real :: xsum
89
complex :: loc, scale
9-
integer :: seed_put, seed_get
10+
integer :: seed_put, seed_get, i
1011

1112
seed_put = 1234567
1213
call random_seed(seed_put, seed_get)
1314

14-
print *, norm_pdf(1.0, 0., 1.) !a probability density at 1.0 in standard normal
15-
16-
! 0.241970733
15+
! probability density at x=1.0 in standard normal
16+
print *, norm_pdf(1.0, 0., 1.)
17+
! 0.241970733
1718

19+
! probability density at x=2.0 with mu=-1.0 and sigma=2.0
1820
print *, norm_pdf(2.0, -1.0, 2.0)
19-
!a probability density at 2.0 with mu=-1.0 sigma=2.0
21+
! 6.47588000E-02
2022

21-
!6.47588000E-02
23+
! probability density at x=1.0 with mu=1.0 and sigma=-1.0 (out of range)
24+
print *, norm_pdf(1.0, 1.0, -1.0)
25+
! NaN
2226

27+
! standard normal random variates array
2328
x = reshape(norm(0.0, 1.0, 60), [3, 4, 5])
24-
! standard normal random variates array
25-
26-
a(:, :, :) = 0.0
27-
b(:, :, :) = 1.0
28-
print *, norm_pdf(x, a, b) ! standard normal probability density array
29-
30-
! 0.340346158 0.285823315 0.398714304 0.391778737 0.389345556
31-
! 0.364551932 0.386712372 0.274370432 0.215250477 0.378006011
32-
! 0.215760440 0.177990928 0.278640658 0.223813817 0.356875211
33-
! 0.285167664 0.378533930 0.390739858 0.271684974 0.138273031
34-
! 0.135456234 0.331718773 0.398283750 0.383706540
35-
29+
30+
! standard normal probability density array
31+
mu(:, :, :) = 0.0
32+
sigma(:, :, :) = 1.0
33+
print *, norm_pdf(x, mu, sigma)
34+
! 0.340346158 0.285823315 0.398714304 0.391778737 0.389345556
35+
! 0.364551932 0.386712372 0.274370432 0.215250477 0.378006011
36+
! 0.215760440 0.177990928 0.278640658 0.223813817 0.356875211
37+
! 0.285167664 0.378533930 0.390739858 0.271684974 0.138273031
38+
! 0.135456234 0.331718773 0.398283750 0.383706540
39+
40+
! probability density array where sigma<=0.0 for certain elements
41+
print *, norm_pdf([1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 0.0, -1.0])
42+
! 0.398942292 NaN NaN
43+
44+
! `pdf_normal` is pure and, thus, can be called concurrently
45+
xsum = 0.0
46+
do concurrent (i=1:size(x,3))
47+
xsum = xsum + sum(norm_pdf(x(:,:,i), mu(:,:,i), sigma(:,:,i)))
48+
end do
49+
print *, xsum
50+
! 18.0754433
51+
52+
! complex normal probability density function at x=(1.5,1.0) with real part
53+
! of mu=1.0, sigma=1.0 and imaginary part of mu=-0.5, sigma=2.0
3654
loc = (1.0, -0.5)
3755
scale = (1.0, 2.)
3856
print *, norm_pdf((1.5, 1.0), loc, scale)
39-
! a complex normal probability density function at (1.5,1.0) with real part
40-
! of mu=1.0, sigma=1.0 and imaginary part of mu=-0.5, sigma=2.0
41-
42-
! 5.30100204E-02
57+
! 5.30100204E-02
4358

4459
end program example_normal_pdf

0 commit comments

Comments
 (0)