@@ -33,44 +33,42 @@ to find a smaller or larger rank (that will have led to partial sorting of
3333
3434* ` arg_select ` is used to find the index of the k-th smallest entry of an array.
3535In this case the input array is not modified, but the user must provide an
36- input index array with the same size as ` array ` , having unique indices from
36+ input index array with the same size as ` array ` , having indices that are a permutation of
3737` 1:size(array) ` , which is modified instead. On return the index array is modified
3838such that ` all(array(index(1:k)) <= array(index(k))) ` and ` all(array(k) <= array(k+1:size(array))) ` .
3939The user can optionally specify ` left ` and ` right ` indices to constrain the search
4040for the k-th smallest value. This can be useful if you have previously called ` arg_select `
4141to find a smaller or larger rank (that will have led to partial sorting of
4242` index ` , thus implying some constraints on the location).
4343
44- #### Licensing
44+ ### Licensing
4545
4646The Fortran Standard Library is distributed under the MIT
4747License. It is worth noting that ` select ` and ` arg_select `
4848were derived using some code from quickSelect in the Coretran library, by Leon Foks,
4949https://github.com/leonfoks/coretran . Leon Foks has given permission for the code here
5050to be released under stdlib's MIT license.
5151
52- ### Specifications of the ` stdlib_selection ` procedures
52+ ## ` select ` - find the k-th smallest value in an input array
5353
54- #### ` select ` - find the k-th smallest value in an input array
55-
56- ##### Status
54+ ### Status
5755
5856Experimental
5957
60- ##### Description
58+ ### Description
6159
6260Returns the k-th smallest value of ` array(:) ` , and also partially sorts ` array(:) `
6361such that ` all(array(1:k) <= array(k)) ` and ` all(array(k) <= array((k+1):size(array))) `
6462
65- ##### Syntax
63+ ### Syntax
6664
6765` call [[stdlib_selection(module):select(interface)]]( array, k, kth_smallest [, left, right ] ) `
6866
69- ##### Class
67+ ### Class
7068
7169Generic subroutine.
7270
73- ##### Arguments
71+ ### Arguments
7472
7573` array ` : shall be a rank one array of any of the types:
7674` integer(int8) ` , ` integer(int16) ` , ` integer(int32) ` , ` integer(int64) ` ,
@@ -95,16 +93,13 @@ in `array(1:right)`. If `right` is not present, the default is `size(array)`. Th
9593to ` select ` are made, because the partial sorting of ` array ` implies constraints on where
9694we need to search.
9795
98- ##### Notes
96+ ### Notes
9997
10098Selection of a single value should have runtime of O(` size(array) ` ), so it is
10199asymptotically faster than sorting ` array ` entirely. The test program at the
102100end of this document shows that is the case.
103101
104- On return the elements of ` array ` will be partially sorted such that:
105- ` all( array(1:k-1) <= array(k) ) ` and ` all(array(k) <= array(k+1:size(array))) ` .
106-
107- ##### Example
102+ ### Example
108103
109104``` fortran
110105 program demo_select
@@ -136,27 +131,27 @@ On return the elements of `array` will be partially sorted such that:
136131 end program demo_select
137132```
138133
139- #### ` arg_select ` - find the kth smallest value in an input array
134+ ## ` arg_select ` - find the kth smallest value in an input array
140135
141- ##### Status
136+ ### Status
142137
143138Experimental
144139
145- ##### Description
140+ ### Description
146141
147142Returns the index of the k-th smallest value of ` array(:) ` , and also partially sorts
148143the index-array ` indx(:) ` such that ` all(array(indx(1:k)) <= array(indx(k))) ` and
149144` all(array(indx(k)) <= array(indx((k+1):size(array)))) `
150145
151- ##### Syntax
146+ ### Syntax
152147
153148` call [[stdlib_selection(module):arg_select(interface)]]( array, indx, k, kth_smallest [, left, right ] ) `
154149
155- ##### Class
150+ ### Class
156151
157152Generic subroutine.
158153
159- ##### Arguments
154+ ### Arguments
160155
161156` array ` : shall be a rank one array of any of the types:
162157` integer(int8) ` , ` integer(int16) ` , ` integer(int32) ` , ` integer(int64) ` ,
@@ -187,19 +182,21 @@ in `array(indx(1:right))`. If `right` is not present, the default is `size(array
187182to ` arg_select ` are made, because the reordering of ` indx ` implies constraints on
188183where we need to search.
189184
190- ##### Notes
185+ ### Notes
191186
192187` arg_select ` does not modify ` array ` , unlike ` select ` .
193188
194- While it is essential that that ` indx ` contains the integers ` 1:size(array) ` (in any
195- order), the code does not check for this.
189+ While it is essential that that ` indx ` contains a permutation of the integers ` 1:size(array) ` ,
190+ the code does not check for this. For example if ` size(array) == 4 ` , then we could have
191+ ` indx = [4, 2, 1, 3] ` or ` indx = [1, 2, 3, 4] ` , but not ` indx = [2, 1, 2, 4] ` . It is the user's
192+ responsibility to avoid such errors.
196193
197194Selection of a single value should have runtime of O(` size(array) ` ), so it is
198195asymptotically faster than sorting ` array ` entirely. The test program at the end of
199196these documents confirms that is the case.
200197
201198
202- ##### Example
199+ ### Example
203200
204201
205202``` fortran
0 commit comments