From 2db890d81668b236835e576e4aa190047a39a7b1 Mon Sep 17 00:00:00 2001 From: Damian Rouson Date: Tue, 5 Apr 2022 16:13:50 -0700 Subject: [PATCH 1/2] refac(random): mv procedure definition to submod --- src/mod_random.f90 | 37 ++++++++++++++----------------------- src/nf_random_s.f90 | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 src/nf_random_s.f90 diff --git a/src/mod_random.f90 b/src/mod_random.f90 index d8c1b4af..ed631bdd 100644 --- a/src/mod_random.f90 +++ b/src/mod_random.f90 @@ -10,30 +10,21 @@ module mod_random private public :: randn - real(rk), parameter :: pi = 4 * atan(1._rk) - interface randn - module procedure :: randn1d, randn2d - end interface randn -contains - - function randn1d(n) result(r) - ! Generates n random numbers with a normal distribution. - integer(ik), intent(in) :: n - real(rk) :: r(n), r2(n) - call random_number(r) - call random_number(r2) - r = sqrt(-2 * log(r)) * cos(2 * pi * r2) - end function randn1d - - function randn2d(m, n) result(r) - ! Generates m x n random numbers with a normal distribution. - integer(ik), intent(in) :: m, n - real(rk) :: r(m, n), r2(m, n) - call random_number(r) - call random_number(r2) - r = sqrt(-2 * log(r)) * cos(2 * pi * r2) - end function randn2d + module function randn1d(n) result(r) + ! Generates n random numbers with a normal distribution. + implicit none + integer(ik), intent(in) :: n + real(rk) :: r(n) + end function randn1d + + module function randn2d(m, n) result(r) + ! Generates m x n random numbers with a normal distribution. + integer(ik), intent(in) :: m, n + real(rk) :: r(m, n) + end function randn2d + + end interface randn end module mod_random diff --git a/src/nf_random_s.f90 b/src/nf_random_s.f90 new file mode 100644 index 00000000..d7383f76 --- /dev/null +++ b/src/nf_random_s.f90 @@ -0,0 +1,26 @@ +submodule(mod_random) submod_random + + ! Provides a random number generator with + ! normal distribution, centered on zero. + + implicit none + + real(rk), parameter :: pi = 4 * atan(1._rk) + +contains + + module procedure randn1d + real(rk) :: r2(n) + call random_number(r) + call random_number(r2) + r = sqrt(-2 * log(r)) * cos(2 * pi * r2) + end procedure randn1d + + module procedure randn2d + real(rk) :: r2(m, n) + call random_number(r) + call random_number(r2) + r = sqrt(-2 * log(r)) * cos(2 * pi * r2) + end procedure randn2d + +end submodule submod_random From 4ec4b9b20b3050cfa202ccb3b8ac2966eabf8494 Mon Sep 17 00:00:00 2001 From: Damian Rouson Date: Tue, 5 Apr 2022 16:32:23 -0700 Subject: [PATCH 2/2] refac(random): rename files, module, submodule New names: nf_random_mod{.f90} nf_random_submod{.f90} --- src/mod_layer.f90 | 2 +- src/{mod_random.f90 => nf_random_mod.f90} | 4 ++-- src/{nf_random_s.f90 => nf_random_submod.f90} | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/{mod_random.f90 => nf_random_mod.f90} (93%) rename src/{nf_random_s.f90 => nf_random_submod.f90} (87%) diff --git a/src/mod_layer.f90 b/src/mod_layer.f90 index 78b6a20a..d2d98f71 100644 --- a/src/mod_layer.f90 +++ b/src/mod_layer.f90 @@ -4,7 +4,7 @@ module mod_layer use mod_activation use mod_kinds, only: ik, rk - use mod_random, only: randn + use nf_random_mod, only: randn implicit none diff --git a/src/mod_random.f90 b/src/nf_random_mod.f90 similarity index 93% rename from src/mod_random.f90 rename to src/nf_random_mod.f90 index ed631bdd..66262af0 100644 --- a/src/mod_random.f90 +++ b/src/nf_random_mod.f90 @@ -1,4 +1,4 @@ -module mod_random +module nf_random_mod ! Provides a random number generator with ! normal distribution, centered on zero. @@ -27,4 +27,4 @@ end function randn2d end interface randn -end module mod_random +end module nf_random_mod diff --git a/src/nf_random_s.f90 b/src/nf_random_submod.f90 similarity index 87% rename from src/nf_random_s.f90 rename to src/nf_random_submod.f90 index d7383f76..16d067b6 100644 --- a/src/nf_random_s.f90 +++ b/src/nf_random_submod.f90 @@ -1,4 +1,4 @@ -submodule(mod_random) submod_random +submodule(nf_random_mod) nf_random_submod ! Provides a random number generator with ! normal distribution, centered on zero. @@ -23,4 +23,4 @@ r = sqrt(-2 * log(r)) * cos(2 * pi * r2) end procedure randn2d -end submodule submod_random +end submodule nf_random_submod