Skip to content

Commit bf41273

Browse files
committed
Removed loops and add CMAKE_MAXIMUM_RANK
2 parents c7a6070 + 26f23a5 commit bf41273

File tree

7 files changed

+76
-179
lines changed

7 files changed

+76
-179
lines changed

.github/workflows/CI.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
run: brew install gcc@${GCC_V} || brew upgrade gcc@${GCC_V} || true
5858

5959
- name: Configure with CMake
60-
run: cmake -Wdev -DCMAKE_BUILD_TYPE=Release -S . -B build
60+
run: cmake -Wdev -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAXIMUM_RANK=5 -S . -B build
6161

6262
- name: Build and compile
6363
run: cmake --build build
@@ -80,6 +80,6 @@ jobs:
8080
- name: Test manual makefiles
8181
if: contains(matrix.os, 'ubuntu') && contains(matrix.gcc_v, '9')
8282
run: |
83-
make -f Makefile.manual
83+
make -f Makefile.manual FYPPFLAGS="-DMAXRANK=5"
8484
make -f Makefile.manual test
8585
make -f Makefile.manual clean

.github/workflows/ci_windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Install fypp
1919
run: pip install fypp
2020

21-
- run: cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -Wdev -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_Fortran_FLAGS_DEBUG="-Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all -fbacktrace"
21+
- run: cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -Wdev -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_Fortran_FLAGS_DEBUG="-Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all -fbacktrace" -DCMAKE_MAXIMUM_RANK=5
2222

2323
env:
2424
FC: gfortran

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ check_fortran_source_compiles("error stop i; end" f18errorstop SRC_EXT f90)
1818
check_fortran_source_compiles("real, allocatable :: array(:, :, :, :, :, :, :, :, :, :); end" f03rank SRC_EXT f90)
1919
check_fortran_source_runs("use, intrinsic :: iso_fortran_env, only : real128; real(real128) :: x; x = x+1; end" f03real128)
2020

21+
if(DEFINED CMAKE_MAXIMUM_RANK)
22+
set(CMAKE_MAXIMUM_RANK ${CMAKE_MAXIMUM_RANK})
23+
endif()
24+
2125
add_subdirectory(src)

src/CMakeLists.txt

+19-13
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,25 @@ foreach(infileName IN LISTS fppFiles)
1919
set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${infileName}")
2020

2121
# Custom command to do the processing
22-
if(f03rank)
23-
add_custom_command(
24-
OUTPUT "${outfile}"
25-
COMMAND fypp "${infile}" "${outfile}"
26-
MAIN_DEPENDENCY "${infile}"
27-
VERBATIM)
28-
else()
29-
add_custom_command(
30-
OUTPUT "${outfile}"
31-
COMMAND fypp -DVERSION90 "${infile}" "${outfile}"
32-
MAIN_DEPENDENCY "${infile}"
33-
VERBATIM)
34-
endif()
22+
if(DEFINED CMAKE_MAXIMUM_RANK)
23+
add_custom_command(
24+
OUTPUT "${outfile}"
25+
COMMAND fypp -DMAXRANK=${CMAKE_MAXIMUM_RANK} "${infile}" "${outfile}"
26+
MAIN_DEPENDENCY "${infile}"
27+
VERBATIM)
28+
elseif(f03rank)
29+
add_custom_command(
30+
OUTPUT "${outfile}"
31+
COMMAND fypp "${infile}" "${outfile}"
32+
MAIN_DEPENDENCY "${infile}"
33+
VERBATIM)
34+
else()
35+
add_custom_command(
36+
OUTPUT "${outfile}"
37+
COMMAND fypp -DVERSION90 "${infile}" "${outfile}"
38+
MAIN_DEPENDENCY "${infile}"
39+
VERBATIM)
40+
endif()
3541

3642
# Finally add output file to a list
3743
set(outFiles ${outFiles} "${outfile}")

src/stdlib_experimental_stats.fypp

+27-25
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ interface mean
4949
module function mean_2_${k1}$_${k1}$(x, dim) result(res)
5050
${t1}$, intent(in) :: x(:,:)
5151
integer, intent(in) :: dim
52-
${t1}$ :: res(size(x)/size(x, dim))
52+
${t1}$ :: res(merge(size(x, 1), size(x, 2), mask = 1 < dim ))
5353
end function mean_2_${k1}$_${k1}$
5454
#:endfor
5555

5656
#:for i1, k1, t1 in ikti
5757
module function mean_2_${k1}$_dp(x, dim) result(res)
5858
${t1}$, intent(in) :: x(:,:)
5959
integer, intent(in) :: dim
60-
real(dp) :: res(size(x)/size(x, dim))
60+
real(dp) :: res(merge(size(x, 1), size(x, 2), mask = 1 < dim ))
6161
end function mean_2_${k1}$_dp
6262
#:endfor
6363

@@ -66,7 +66,9 @@ interface mean
6666
#{if rank > 0}#(${":" + ",:" * (rank - 1)}$)#{endif}#
6767
#:enddef
6868

69-
#:if VERSION90
69+
#:if defined('MAXRANK')
70+
#:set ranks = range(3,MAXRANK+1)
71+
#:elif VERSION90
7072
#:set ranks = range(3,8)
7173
#:else
7274
#:set ranks = range(3,16)
@@ -75,47 +77,47 @@ interface mean
7577

7678
#:for i1, k1, t1 in iktr
7779
#:for rank in ranks
78-
module function mean_${rank}$_all_${k1}$_${k1}$(x) result(res)
79-
${t1}$, intent(in) :: x${ranksuffix(rank)}$
80-
${t1}$ :: res
81-
end function mean_${rank}$_all_${k1}$_${k1}$
80+
module function mean_${rank}$_all_${k1}$_${k1}$(x) result(res)
81+
${t1}$, intent(in) :: x${ranksuffix(rank)}$
82+
${t1}$ :: res
83+
end function mean_${rank}$_all_${k1}$_${k1}$
8284
#:endfor
8385
#:endfor
8486

8587
#:for i1, k1, t1 in ikti
8688
#:for rank in ranks
87-
module function mean_${rank}$_all_${k1}$_dp(x) result(res)
88-
${t1}$, intent(in) :: x${ranksuffix(rank)}$
89-
real(dp) :: res
90-
end function mean_${rank}$_all_${k1}$_dp
89+
module function mean_${rank}$_all_${k1}$_dp(x) result(res)
90+
${t1}$, intent(in) :: x${ranksuffix(rank)}$
91+
real(dp) :: res
92+
end function mean_${rank}$_all_${k1}$_dp
9193
#:endfor
9294
#:endfor
9395

9496
#:for i1, k1, t1 in iktr
9597
#:for rank in ranks
96-
module function mean_${rank}$_${k1}$_${k1}$(x, dim) result(res)
97-
${t1}$, intent(in) :: x${ranksuffix(rank)}$
98-
integer, intent(in) :: dim
99-
${t1}$ :: res( &
98+
module function mean_${rank}$_${k1}$_${k1}$(x, dim) result(res)
99+
${t1}$, intent(in) :: x${ranksuffix(rank)}$
100+
integer, intent(in) :: dim
101+
${t1}$ :: res( &
100102
#:for imerge in range(1,rank-1)
101-
merge(size(x,${imerge}$),size(x,${imerge + 1}$),mask = ${imerge}$ < dim ), &
103+
merge(size(x,${imerge}$),size(x,${imerge + 1}$),mask = ${imerge}$ < dim ), &
102104
#:endfor
103-
merge(size(x,${rank-1}$),size(x,${rank}$),mask = ${rank-1}$ < dim ) )
104-
end function mean_${rank}$_${k1}$_${k1}$
105+
merge(size(x,${rank-1}$),size(x,${rank}$),mask = ${rank-1}$ < dim ) )
106+
end function mean_${rank}$_${k1}$_${k1}$
105107
#:endfor
106108
#:endfor
107109

108110
#:for i1, k1, t1 in ikti
109111
#:for rank in ranks
110-
module function mean_${rank}$_${k1}$_dp(x, dim) result(res)
111-
${t1}$, intent(in) :: x${ranksuffix(rank)}$
112-
integer, intent(in) :: dim
113-
real(dp) :: res( &
112+
module function mean_${rank}$_${k1}$_dp(x, dim) result(res)
113+
${t1}$, intent(in) :: x${ranksuffix(rank)}$
114+
integer, intent(in) :: dim
115+
real(dp) :: res( &
114116
#:for imerge in range(1,rank-1)
115-
merge(size(x,${imerge}$),size(x,${imerge + 1}$),mask = ${imerge}$ < dim ), &
117+
merge(size(x,${imerge}$),size(x,${imerge + 1}$),mask = ${imerge}$ < dim ), &
116118
#:endfor
117-
merge(size(x,${rank-1}$),size(x,${rank}$),mask = ${rank-1}$ < dim ) )
118-
end function mean_${rank}$_${k1}$_dp
119+
merge(size(x,${rank-1}$),size(x,${rank}$),mask = ${rank-1}$ < dim ) )
120+
end function mean_${rank}$_${k1}$_dp
119121
#:endfor
120122
#:endfor
121123

0 commit comments

Comments
 (0)