Skip to content

Refactor: move procedure definitions to submodules #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mod_layer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 0 additions & 39 deletions src/mod_random.f90

This file was deleted.

30 changes: 30 additions & 0 deletions src/nf_random_mod.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module nf_random_mod

! Provides a random number generator with
! normal distribution, centered on zero.

use mod_kinds, only: ik, rk

implicit none

private
public :: randn

interface randn

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 nf_random_mod
26 changes: 26 additions & 0 deletions src/nf_random_submod.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
submodule(nf_random_mod) nf_random_submod

! 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 nf_random_submod