Skip to content

Improve compilation load by splitting stdlib_stats_moment submodule #283

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

Merged
merged 2 commits into from
Dec 28, 2020
Merged
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
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ set(fppFiles
stdlib_stats_cov.fypp
stdlib_stats_mean.fypp
stdlib_stats_moment.fypp
stdlib_stats_moment_all.fypp
stdlib_stats_moment_mask.fypp
stdlib_stats_moment_scalar.fypp
stdlib_stats_var.fypp
stdlib_quadrature.fypp
stdlib_quadrature_trapz.fypp
Expand Down
6 changes: 6 additions & 0 deletions src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ SRC = f18estop.f90 \
stdlib_stats.f90 \
stdlib_stats_mean.f90 \
stdlib_stats_moment.f90 \
stdlib_stats_moment_all.f90 \
stdlib_stats_moment_mask.f90 \
stdlib_stats_moment_scalar.f90 \
stdlib_stats_var.f90

LIB = libstdlib.a
Expand Down Expand Up @@ -79,4 +82,7 @@ stdlib_quadrature.f90: stdlib_quadrature.fypp
stdlib_stats.f90: stdlib_stats.fypp
stdlib_stats_mean.f90: stdlib_stats_mean.fypp
stdlib_stats_moment.f90: stdlib_stats_moment.fypp
stdlib_stats_moment_all.f90: stdlib_stats_moment_all.fypp
stdlib_stats_moment_mask.f90: stdlib_stats_moment_mask.fypp
stdlib_stats_moment_scalar.f90: stdlib_stats_moment_scalar.fypp
stdlib_stats_var.f90: stdlib_stats_var.fypp
311 changes: 0 additions & 311 deletions src/stdlib_stats_moment.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -11,93 +11,6 @@ submodule (stdlib_stats) stdlib_stats_moment

contains

#:for k1, t1 in RC_KINDS_TYPES
#:for rank in RANKS
#:set RName = rname("moment_all",rank, t1, k1)
module function ${RName}$(x, order, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
${t1}$, intent(in), optional :: center
logical, intent(in), optional :: mask
${t1}$ :: res

real(${k1}$) :: n

if (.not.optval(mask, .true.)) then
res = ieee_value(1._${k1}$, ieee_quiet_nan)
return
end if

n = real(size(x, kind = int64), ${k1}$)

if (present(center)) then
res = sum((x - center)**order) / n
else
res = sum((x - mean(x))**order) / n
end if

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in INT_KINDS_TYPES
#:for rank in RANKS
#:set RName = rname("moment_all",rank, t1, k1, 'dp')
module function ${RName}$(x, order, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
real(dp), intent(in), optional :: center
logical, intent(in), optional :: mask
real(dp) :: res

real(dp) :: n

if (.not.optval(mask, .true.)) then
res = ieee_value(1._dp, ieee_quiet_nan)
return
end if

n = real(size(x, kind = int64), dp)

if (present(center)) then
res = sum((real(x, dp) - center)**order) / n
else
res = sum((real(x, dp) - mean(x))**order) / n
end if

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in RC_KINDS_TYPES
#:for rank in REDRANKS
#:set RName = rname("moment_scalar",rank, t1, k1)
module function ${RName}$(x, order, dim, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
integer, intent(in) :: dim
${t1}$, intent(in) :: center
logical, intent(in), optional :: mask
${t1}$ :: res${reduced_shape('x', rank, 'dim')}$

if (.not.optval(mask, .true.)) then
res = ieee_value(1._${k1}$, ieee_quiet_nan)
return
end if

if (dim >= 1 .and. dim <= ${rank}$) then
res = sum((x - center)**order, dim) / size(x, dim)
else
call error_stop("ERROR (moment): wrong dimension")
end if

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in RC_KINDS_TYPES
#:for rank in RANKS
#:set RName = rname("moment",rank, t1, k1)
Expand Down Expand Up @@ -146,33 +59,6 @@ contains
#:endfor


#:for k1, t1 in INT_KINDS_TYPES
#:for rank in REDRANKS
#:set RName = rname("moment_scalar",rank, t1, k1, 'dp')
module function ${RName}$(x, order, dim, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
integer, intent(in) :: dim
real(dp),intent(in) :: center
logical, intent(in), optional :: mask
real(dp) :: res${reduced_shape('x', rank, 'dim')}$

if (.not.optval(mask, .true.)) then
res = ieee_value(1._dp, ieee_quiet_nan)
return
end if

if (dim >= 1 .and. dim <= ${rank}$) then
res = sum( (real(x, dp) - center)**order, dim) / size(x, dim)
else
call error_stop("ERROR (moment): wrong dimension")
end if

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in INT_KINDS_TYPES
#:for rank in RANKS
#:set RName = rname("moment",rank, t1, k1, 'dp')
Expand Down Expand Up @@ -221,201 +107,4 @@ contains
#:endfor
#:endfor


#:for k1, t1 in RC_KINDS_TYPES
#:for rank in RANKS
#:set RName = rname("moment_mask_all",rank, t1, k1)
module function ${RName}$(x, order, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
${t1}$, intent(in), optional :: center
logical, intent(in) :: mask${ranksuffix(rank)}$
${t1}$ :: res

real(${k1}$) :: n

n = real(count(mask, kind = int64), ${k1}$)

if (present(center)) then
res = sum((x - center)**order, mask) / n
else
res = sum((x - mean(x, mask))**order, mask) / n
end if

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in INT_KINDS_TYPES
#:for rank in RANKS
#:set RName = rname("moment_mask_all",rank, t1, k1, 'dp')
module function ${RName}$(x, order, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
real(dp),intent(in), optional :: center
logical, intent(in) :: mask${ranksuffix(rank)}$
real(dp) :: res

real(dp) :: n

n = real(count(mask, kind = int64), dp)

if (present(center)) then
res = sum((real(x, dp) - center)**order, mask) / n
else
res = sum((real(x, dp) - mean(x,mask))**order, mask) / n
end if

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in RC_KINDS_TYPES
#:for rank in REDRANKS
#:set RName = rname("moment_mask_scalar",rank, t1, k1)
module function ${RName}$(x, order, dim, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
integer, intent(in) :: dim
${t1}$, intent(in) :: center
logical, intent(in) :: mask${ranksuffix(rank)}$
${t1}$ :: res${reduced_shape('x', rank, 'dim')}$

if (dim >= 1 .and. dim <= ${rank}$) then
res = sum((x - center)**order, dim, mask) / count(mask, dim)
else
call error_stop("ERROR (moment): wrong dimension")
end if

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in RC_KINDS_TYPES
#:for rank in RANKS
#:set RName = rname("moment_mask",rank, t1, k1)
module function ${RName}$(x, order, dim, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
integer, intent(in) :: dim
${t1}$, intent(in), optional :: center${reduced_shape('x', rank, 'dim')}$
logical, intent(in) :: mask${ranksuffix(rank)}$
${t1}$ :: res${reduced_shape('x', rank, 'dim')}$

integer :: i
real(${k1}$) :: n${reduced_shape('x', rank, 'dim')}$
${t1}$, allocatable :: mean_${ranksuffix(rank-1)}$

n = real(count(mask, dim), ${k1}$)

res = 0
select case(dim)
#:for fi in range(1, rank+1)
case(${fi}$)
if (present(center)) then
do i = 1, size(x, ${fi}$)
res = res + merge( (x${select_subarray(rank, [(fi, 'i')])}$ -&
center)**order,&
#:if t1[0] == 'r'
0._${k1}$,&
#:else
cmplx(0,0,kind=${k1}$),&
#:endif
mask${select_subarray(rank, [(fi, 'i')])}$)
end do
else
allocate(mean_, source = mean(x, ${fi}$, mask))
do i = 1, size(x, ${fi}$)
res = res + merge( (x${select_subarray(rank, [(fi, 'i')])}$ - mean_)**order,&
#:if t1[0] == 'r'
0._${k1}$,&
#:else
cmplx(0,0,kind=${k1}$),&
#:endif
mask${select_subarray(rank, [(fi, 'i')])}$)
end do
deallocate(mean_)
end if
#:endfor
case default
call error_stop("ERROR (moment): wrong dimension")
end select
res = res / n

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in INT_KINDS_TYPES
#:for rank in REDRANKS
#:set RName = rname("moment_mask_scalar",rank, t1, k1, 'dp')
module function ${RName}$(x, order, dim, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
integer, intent(in) :: dim
real(dp), intent(in) :: center
logical, intent(in) :: mask${ranksuffix(rank)}$
real(dp) :: res${reduced_shape('x', rank, 'dim')}$

if (dim >= 1 .and. dim <= ${rank}$) then
res = sum(( real(x, dp) - center)**order, dim, mask) / count(mask, dim)
else
call error_stop("ERROR (moment): wrong dimension")
end if

end function ${RName}$
#:endfor
#:endfor


#:for k1, t1 in INT_KINDS_TYPES
#:for rank in RANKS
#:set RName = rname("moment_mask",rank, t1, k1, 'dp')
module function ${RName}$(x, order, dim, center, mask) result(res)
${t1}$, intent(in) :: x${ranksuffix(rank)}$
integer, intent(in) :: order
integer, intent(in) :: dim
real(dp), intent(in), optional :: center${reduced_shape('x', rank, 'dim')}$
logical, intent(in) :: mask${ranksuffix(rank)}$
real(dp) :: res${reduced_shape('x', rank, 'dim')}$

integer :: i
real(dp) :: n${reduced_shape('x', rank, 'dim')}$
real(dp), allocatable :: mean_${ranksuffix(rank-1)}$

n = real(count(mask, dim), dp)

res = 0
select case(dim)
#:for fi in range(1, rank+1)
case(${fi}$)
if (present(center)) then
do i = 1, size(x, ${fi}$)
res = res + merge((real(x${select_subarray(rank, [(fi, 'i')])}$, dp) -&
center)**order,&
0._dp, mask${select_subarray(rank, [(fi, 'i')])}$)
end do
else
allocate(mean_, source = mean(x, ${fi}$, mask))
do i = 1, size(x, ${fi}$)
res = res + merge((real(x${select_subarray(rank, [(fi, 'i')])}$, dp) - mean_)&
**order,&
0._dp, mask${select_subarray(rank, [(fi, 'i')])}$)
end do
deallocate(mean_)
end if
#:endfor
case default
call error_stop("ERROR (moment): wrong dimension")
end select
res = res / n

end function ${RName}$
#:endfor
#:endfor

end submodule
Loading