Skip to content

Commit

Permalink
stat_dev: simplified merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdp1 committed Jan 20, 2020
1 parent 22ff6e4 commit e0e3092
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 54 deletions.
35 changes: 14 additions & 21 deletions src/stdlib_experimental_stat.f90
Original file line number Diff line number Diff line change
Expand Up @@ -144,59 +144,52 @@ end function mean_3_all_int64_dp
module function mean_3_sp_sp(x, dim) result(res)
real(sp), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(sp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_sp_sp
module function mean_3_dp_dp(x, dim) result(res)
real(dp), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_dp_dp
module function mean_3_qp_qp(x, dim) result(res)
real(qp), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(qp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_qp_qp

module function mean_3_int8_dp(x, dim) result(res)
integer(int8), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_int8_dp
module function mean_3_int16_dp(x, dim) result(res)
integer(int16), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_int16_dp
module function mean_3_int32_dp(x, dim) result(res)
integer(int32), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_int32_dp
module function mean_3_int64_dp(x, dim) result(res)
integer(int64), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_int64_dp

end interface
Expand Down
10 changes: 4 additions & 6 deletions src/stdlib_experimental_stat.fypp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,19 @@ end function mean_3_all_${k1}$_dp
module function mean_3_${k1}$_${k1}$(x, dim) result(res)
${t1}$, intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
${t1}$ :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_${k1}$_${k1}$
#:endfor

#:for i1, k1, t1 in ikti
module function mean_3_${k1}$_dp(x, dim) result(res)
${t1}$, intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )
end function mean_3_${k1}$_dp
#:endfor

Expand Down
35 changes: 14 additions & 21 deletions src/stdlib_experimental_stat_mean.f90
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,9 @@ end function mean_3_all_int64_dp
module function mean_3_sp_sp(x, dim) result(res)
real(sp), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(sp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down Expand Up @@ -328,10 +327,9 @@ end function mean_3_sp_sp
module function mean_3_dp_dp(x, dim) result(res)
real(dp), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down Expand Up @@ -361,10 +359,9 @@ end function mean_3_dp_dp
module function mean_3_qp_qp(x, dim) result(res)
real(qp), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(qp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down Expand Up @@ -395,10 +392,9 @@ end function mean_3_qp_qp
module function mean_3_int8_dp(x, dim) result(res)
integer(int8), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down Expand Up @@ -428,10 +424,9 @@ end function mean_3_int8_dp
module function mean_3_int16_dp(x, dim) result(res)
integer(int16), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down Expand Up @@ -461,10 +456,9 @@ end function mean_3_int16_dp
module function mean_3_int32_dp(x, dim) result(res)
integer(int32), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down Expand Up @@ -494,10 +488,9 @@ end function mean_3_int32_dp
module function mean_3_int64_dp(x, dim) result(res)
integer(int64), intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down
10 changes: 4 additions & 6 deletions src/stdlib_experimental_stat_mean.fypp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ end function mean_3_all_${k1}$_dp
module function mean_3_${k1}$_${k1}$(x, dim) result(res)
${t1}$, intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
${t1}$ :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down Expand Up @@ -159,10 +158,9 @@ end function mean_3_${k1}$_${k1}$
module function mean_3_${k1}$_dp(x, dim) result(res)
${t1}$, intent(in) :: x(:,:,:)
integer, intent(in) :: dim
integer :: j_
real(dp) :: res( &
merge(size(x,2),size(x,1),mask = any((/(j_, j_ = dim, rank(x))/) == 1)), &
merge(size(x,3),size(x,2),mask = any((/(j_, j_ = dim, rank(x))/) == 2)) )
merge(size(x,1),size(x,2),mask = 1 < dim ), &
merge(size(x,2),size(x,3),mask = 2 < dim ) )

integer :: i, j

Expand Down

0 comments on commit e0e3092

Please sign in to comment.