Skip to content

Commit 7fa847a

Browse files
committed
Merge branch 'master' into merge_tostring
2 parents c717724 + ce3a106 commit 7fa847a

26 files changed

+2408
-58
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: CI
33
on: [push, pull_request]
44

55
env:
6-
CI: "ON" # We can detect this in the build system and other vendors implement it
76
CMAKE_BUILD_PARALLEL_LEVEL: "2" # 2 cores on each GHA VM, enable parallel builds
87
CTEST_OUTPUT_ON_FAILURE: "ON" # This way we don't need a flag to ctest
98
CTEST_PARALLEL_LEVEL: "2"
@@ -28,7 +27,7 @@ jobs:
2827

2928
steps:
3029
- name: Checkout code
31-
uses: actions/checkout@v1
30+
uses: actions/checkout@v2
3231

3332
- name: Set up Python 3.x
3433
uses: actions/setup-python@v1 # Use pip to install latest CMake, & FORD/Jin2For, etc.
@@ -62,20 +61,19 @@ jobs:
6261
run: >-
6362
cmake -Wdev
6463
-DCMAKE_BUILD_TYPE=Release
65-
-DCMAKE_MAXIMUM_RANK=4
64+
-DCMAKE_MAXIMUM_RANK:String=4
6665
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
6766
-S . -B build
6867
6968
- name: Build and compile
70-
run: cmake --build build
69+
run: cmake --build build --parallel
7170

7271
- name: catch build fail
7372
run: cmake --build build --verbose --parallel 1
7473
if: failure()
7574

7675
- name: test
77-
run: ctest --parallel --output-on-failure
78-
working-directory: build
76+
run: ctest --test-dir build --parallel --output-on-failure
7977

8078
- name: Install project
8179
run: cmake --install build
@@ -110,7 +108,7 @@ jobs:
110108

111109
steps:
112110
- name: Checkout code
113-
uses: actions/checkout@v1
111+
uses: actions/checkout@v2
114112

115113
- name: Set up Python 3.x
116114
uses: actions/setup-python@v1
@@ -179,7 +177,7 @@ jobs:
179177
run: >-
180178
cmake -Wdev
181179
-DCMAKE_BUILD_TYPE=Release
182-
-DCMAKE_MAXIMUM_RANK=4
180+
-DCMAKE_MAXIMUM_RANK:String=4
183181
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
184182
-S . -B build
185183

.github/workflows/PR-review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- name: Check out code.
9-
uses: actions/checkout@v1
9+
uses: actions/checkout@v2
1010
- name: misspell
1111
uses: reviewdog/action-misspell@v1
1212
with:

.github/workflows/ci_windows.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: CI_windows
33
on: [push, pull_request]
44

55
env:
6-
CI: "ON"
76
CTEST_TIME_TIMEOUT: "5" # some failures hang forever
7+
CMAKE_GENERATOR: Ninja
88

99
jobs:
1010
msys2-build:
@@ -58,13 +58,12 @@ jobs:
5858
run: pip install fypp
5959

6060
- run: >-
61-
cmake -G Ninja
62-
-DCMAKE_SH="CMAKE_SH-NOTFOUND"
61+
cmake
6362
-Wdev
6463
-B build
6564
-DCMAKE_BUILD_TYPE=Debug
6665
-DCMAKE_Fortran_FLAGS_DEBUG="-Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all -fbacktrace"
67-
-DCMAKE_MAXIMUM_RANK=4
66+
-DCMAKE_MAXIMUM_RANK:String=4
6867
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
6968
env:
7069
FC: gfortran
@@ -79,8 +78,7 @@ jobs:
7978
if: failure()
8079

8180
- name: CTest
82-
run: ctest --output-on-failure --parallel -V -LE quadruple_precision
83-
working-directory: build
81+
run: ctest --test-dir build --output-on-failure --parallel -V -LE quadruple_precision
8482

8583
- uses: actions/upload-artifact@v1
8684
if: failure()

CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,26 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
3131
add_compile_options(-pedantic-errors)
3232
endif()
3333
add_compile_options(-std=f2018)
34-
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
35-
add_compile_options(-warn declarations,general,usage,interfaces,unused)
36-
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 18.0)
37-
add_compile_options(-stand f15)
34+
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
35+
if(WIN32)
36+
add_compile_options(/warn:declarations,general,usage,interfaces,unused)
37+
add_compile_options(/stand:f18)
3838
else()
39+
add_compile_options(-warn declarations,general,usage,interfaces,unused)
3940
add_compile_options(-stand f18)
4041
endif()
41-
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL PGI)
42-
add_compile_options(-Mdclchk)
4342
endif()
4443

4544
# --- compiler feature checks
4645
include(CheckFortranSourceCompiles)
4746
include(CheckFortranSourceRuns)
48-
check_fortran_source_runs("i=0; error stop i; end" f18errorstop SRC_EXT f90)
47+
check_fortran_source_runs("i=0; error stop i; end" f18errorstop)
4948
check_fortran_source_compiles("real, allocatable :: array(:, :, :, :, :, :, :, :, :, :); end" f03rank SRC_EXT f90)
5049
check_fortran_source_runs("use, intrinsic :: iso_fortran_env, only : real128; real(real128) :: x; x = x+1; end" f03real128)
5150

52-
option(CMAKE_MAXIMUM_RANK "Maximum array rank for generated procedures" 4)
51+
if(NOT DEFINED CMAKE_MAXIMUM_RANK)
52+
set(CMAKE_MAXIMUM_RANK 4 CACHE STRING "Maximum array rank for generated procedures")
53+
endif()
5354

5455
# --- find preprocessor
5556
find_program(FYPP fypp)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Important options are
136136
For example, to configure a build using the Ninja backend and generating procedures up to rank 7, which is installed to your home directory use
137137

138138
```sh
139-
cmake -B build -G Ninja -DCMAKE_MAXIMUM_RANK=7 -DCMAKE_INSTALL_PREFIX=$HOME/.local
139+
cmake -B build -G Ninja -DCMAKE_MAXIMUM_RANK:String=7 -DCMAKE_INSTALL_PREFIX=$HOME/.local
140140
```
141141

142142
To build the standard library run

doc/specs/stdlib_math.md

Lines changed: 188 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ title: math
1919

2020
#### Description
2121

22-
Returns a value which lies in the given interval [`xmin`, `xmax`] (interval is `xmin` and `xmax` inclusive) and is closest to the input value `x`.
22+
Returns a value which lies in the given interval [`xmin`, `xmax`] (interval is `xmin` and `xmax` inclusive) and is closest to the input value `x`.
2323

2424
#### Syntax
2525

@@ -35,8 +35,8 @@ Elemental function.
3535

3636
#### Argument(s)
3737

38-
`x`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
39-
`xmin`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
38+
`x`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
39+
`xmin`: scalar of either `integer` or `real` type. This argument is `intent(in)`.
4040
`xmax`: scalar of either `integer` or `real` type, which must be greater than or equal to `xmin`. This argument is `intent(in)`.
4141

4242
Note: All arguments must have same `type` and same `kind`.
@@ -90,3 +90,188 @@ program demo_clip_real
9090
! clipped_value <- 3.02500010
9191
end program demo_clip_real
9292
```
93+
94+
### `linspace` - Create a linearly spaced rank one array
95+
96+
#### Description
97+
98+
Returns a linearly spaced rank 1 array from [`start`, `end`]. Optionally, you can specify the length of the returned array by passing `n`.
99+
100+
#### Syntax
101+
102+
`res = [[stdlib_math(module):linspace(interface)]] (start, end [, n])`
103+
104+
#### Status
105+
106+
Experimental
107+
108+
#### Class
109+
110+
Function.
111+
112+
#### Argument(s)
113+
114+
`start`: Shall be scalar of any numeric type or kind. This argument is `intent(in)`.
115+
`end`: Shall be the same `type` and `kind` as `start`. This argument is `intent(in)`.
116+
`n`: Shall be an integer specifying the length of the output. This argument is `optional` and `intent(in)`.
117+
118+
#### Output value or Result value
119+
120+
The output is a rank 1 array whose length is either 100 (default value) or `n`.
121+
122+
If `n` == 1, return a rank 1 array whose only element is `end`.
123+
If `n` <= 0, return a rank 1 array with length 0.
124+
125+
If `start`/`end` are `real` or `complex` types, the `result` will be of the same type and kind as `start`/`end`.
126+
If `start`/`end` are `integer` types, the `result` will default to a `real(dp)` array.
127+
128+
#### Examples
129+
130+
##### Example 1:
131+
132+
Here inputs are of type `complex` and kind `dp`
133+
```fortran
134+
program demo_linspace_complex
135+
use stdlib_math, only: linspace
136+
use stdlib_kinds, only: dp
137+
implicit none
138+
139+
complex(dp) :: start = complex(10.0_dp, 5.0_dp)
140+
complex(dp) :: end = complex(-10.0_dp, 15.0_dp)
141+
142+
complex(dp) :: z(11)
143+
144+
z = linspace(start, end, 11)
145+
end program demo_linspace_complex
146+
```
147+
148+
##### Example 2:
149+
150+
Here inputs are of type `integer` and kind `int16`, with the result defaulting to `real(dp)`.
151+
```fortran
152+
program demo_linspace_int16
153+
use stdlib_math, only: linspace
154+
use stdlib_kinds, only: int16, dp
155+
implicit none
156+
157+
integer(int16) :: start = 10_int16
158+
integer(int16) :: end = 23_int16
159+
160+
real(dp) :: r(15)
161+
162+
r = linspace(start, end, 15)
163+
end program demo_linspace_int16
164+
```
165+
166+
### `logspace` - Create a logarithmically spaced rank one array
167+
168+
#### Description
169+
170+
Returns a logarithmically spaced rank 1 array from [`base`^`start`, `base`^`end`]. The default size of the array is 50. Optionally, you can specify the length of the returned array by passing `n`. You can also specify the `base` used to compute the range (default 10).
171+
172+
#### Syntax
173+
174+
`res = [[stdlib_math(module):logspace(interface)]] (start, end [, n [, base]])`
175+
176+
#### Status
177+
178+
Experimental
179+
180+
#### Class
181+
182+
Function.
183+
184+
#### Argument(s)
185+
186+
`start`: Shall be a scalar of any numeric type. All kinds are supported for real and complex arguments. For integers, only the default kind is currently implemented. This argument is `intent(in)`.
187+
`end`: Shall be the same `type` and `kind` as `start`. This argument is `intent(in)`.
188+
`n`: Shall be an integer specifying the length of the output. This argument is `optional` and `intent(in)`.
189+
`base` : Shall be a scalar of any numeric type. All kinds are supported for real and complex arguments. For integers, only the default kind is currently implemented. This argument is `optional` and `intent(in)`.
190+
191+
#### Output value or Result value
192+
193+
The output is a rank 1 array whose length is either 50 (default value) or `n`.
194+
195+
If `n` == 1, return a rank 1 array whose only element is `base`^`end`.
196+
If `n` <= 0, return a rank 1 array with length 0
197+
198+
The `type` and `kind` of the output is dependent on the `type` and `kind` of the passed parameters.
199+
200+
For function calls where the `base` is not specified: `logspace(start, end)`/`logspace(start, end, n)`, the `type` and `kind` of
201+
the output follows the same scheme as above for `linspace`.
202+
>If `start`/`end` are `real` or `complex` types, the `result` will be the same type and kind as `start`/`end`.
203+
>If `start`/`end` are integer types, the `result` will default to a `real(dp)` array.
204+
205+
For function calls where the `base` is specified, the `type` and `kind` of the result is in accordance with the following table:
206+
207+
| `start`/`end` | `n` | `base` | `output` |
208+
| ------------- | --- | ------ | -------- |
209+
| `real(KIND)` | `Integer` | `real(KIND)` | `real(KIND)` |
210+
| " " | " " | `complex(KIND)` | `complex(KIND)` |
211+
| " " | " " | `Integer` | `real(KIND)` |
212+
| `complex(KIND)` | " " | `real(KIND)` | `complex(KIND)` |
213+
| " " | " " | `complex(KIND)` | `complex(KIND)` |
214+
| " " | " " | `Integer` | `complex(KIND)` |
215+
| `Integer` | " " | `real(KIND)` | `real(KIND)` |
216+
| " " | " " | `complex(KIND)` | `complex(KIND)` |
217+
| " " | " " | `Integer` | `Integer` |
218+
219+
#### Examples
220+
221+
##### Example 1:
222+
223+
Here inputs are of type `complex` and kind `dp`. `n` and `base` is not specified and thus default to 50 and 10, respectively.
224+
```fortran
225+
program demo_logspace_complex
226+
use stdlib_math, only: logspace
227+
use stdlib_kinds, only: dp
228+
implicit none
229+
230+
complex(dp) :: start = (10.0_dp, 5.0_dp)
231+
complex(dp) :: end = (-10.0_dp, 15.0_dp)
232+
233+
complex(dp) :: z(11) ! Complex values raised to complex powers results in complex values
234+
235+
z = logspace(start, end, 11)
236+
end program demo_logspace_complex
237+
```
238+
239+
##### Example 2:
240+
241+
Here inputs are of type `integer` and default kind. `base` is not specified and thus defaults to 10.
242+
```fortran
243+
program demo_logspace_int
244+
use stdlib_math, only: logspace
245+
use stdlib_kinds, only: dp
246+
implicit none
247+
248+
integer :: start = 10
249+
integer :: end = 23
250+
integer :: n = 15
251+
252+
real(dp) :: r(n) ! Integer values raised to real powers results in real values
253+
254+
r = logspace(start, end, n)
255+
end program demo_logspace_int
256+
```
257+
258+
##### Example 3:
259+
260+
Here `start`/`end` are of type `real` and double precision. `base` is type `complex` and also double precision.
261+
```fortran
262+
program demo_logspace_rstart_cbase
263+
use stdlib_math, only: logspace
264+
use stdlib_kinds, only: dp
265+
implicit none
266+
267+
real(dp) :: start = 0.0_dp
268+
real(dp) :: end = 3.0_dp
269+
integer :: n = 4
270+
complex(dp) :: base = (0.0_dp, 1.0_dp)
271+
272+
complex(dp) :: z(n) ! complex values raised to real powers result in complex values
273+
274+
z = logspace(start, end, n, base)
275+
276+
end program demo_logspace_rstart_cbase
277+
```

0 commit comments

Comments
 (0)