Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions doc/specs/stdlib_selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Generic subroutine.

`array` : shall be a rank one array of any of the types:
`integer(int8)`, `integer(int16)`, `integer(int32)`, `integer(int64)`,
`real(sp)`, `real(dp)`, `real(xdp), `real(qp)`. It is an `intent(in)` argument. On input it is
`real(sp)`, `real(dp)`, `real(xdp)`, `real(qp)`. It is an `intent(in)` argument. On input it is
the array in which we search for the k-th smallest entry.

`indx`: shall be a rank one array with the same size as `array`, containing all integers
Expand Down Expand Up @@ -198,7 +198,7 @@ The code does not support `NaN` elements in `array`; it will run, but there is
no consistent interpretation given to the order of `NaN` entries of `array`
compared to other entries.

While it is essential that that `indx` contains a permutation of the integers `1:size(array)`,
While it is essential that `indx` contains a permutation of the integers `1:size(array)`,
the code does not check for this. For example if `size(array) == 4`, then we could have
`indx = [4, 2, 1, 3]` or `indx = [1, 2, 3, 4]`, but not `indx = [2, 1, 2, 4]`. It is the user's
responsibility to avoid such errors.
Expand Down
10 changes: 6 additions & 4 deletions src/stdlib_selection.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ contains
r = size(a, kind=ip)
if(present(right)) r = right

if(k < 1_ip .or. k > size(a, kind=ip) .or. l > r .or. l < 1_ip .or. &
r > size(a, kind=ip)) then
if(l > r .or. l < 1_ip .or. r > size(a, kind=ip) &
.or. k < l .or. k > r & !i.e. if k is not in the interval [l; r]
) then
error stop "select must have 1 <= k <= size(a), and 1 <= left <= right <= size(a)";
end if

Expand Down Expand Up @@ -201,8 +202,9 @@ contains
error stop "arg_select must have size(a) == size(indx)"
end if

if(k < 1_ip .or. k > size(a, kind=ip) .or. l > r .or. l < 1_ip .or. &
r > size(a, kind=ip)) then
if(l > r .or. l < 1_ip .or. r > size(a, kind=ip) &
.or. k < l .or. k > r & !i.e. if k is not in the interval [l; r]
) then
error stop "arg_select must have 1 <= k <= size(a), and 1 <= left <= right <= size(a)";
end if

Expand Down