ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_arraySelect::setSelected Interface Reference

Return the rankth smallest (or ordered) value in the input array by first sorting its elements in ascending order (optionally only between the specified indices [lb, ub]).
More...

Detailed Description

Return the rankth smallest (or ordered) value in the input array by first sorting its elements in ascending order (optionally only between the specified indices [lb, ub]).

By default, the array will be sorted in ascending order, unless the user-specific isSorted() external function is supplied to define a custom sorting criterion.

Parameters
[out]selection: The output scalar of either of the same type and kind as the input array argument, containing the rankth smallest value in the input array.
[in,out]array: The input/output contiguous array of shape (:) of either
  • type css_type (scalar string container of default kind SK) or
  • type css_pdt (scalar string container of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU)) or
  • type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU), or
  • type logical of kind any supported by the processor (e.g., LK), or
  • type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64), or
  • type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  • type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
or,
  • a scalar assumed-length character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
containing the potentially unsorted sequence of values that is to be sorted and whose rankth smallest value is to be reported as the output selection.
On return, the first rankth elements of array will be sorted in ascending order or in the user-specified order as determined by the user-supplied external isSorted() argument.
[in]rank: The input integer of default kind IK, representing the index of the rankth smallest value in the input array or the rankth ordered value according to the user-supplied external logical function isSorted().
isSorted: The external user-specified function that takes two input scalar arguments of the same type and kind as the input array.
It returns a scalar logical of default kind LK that is .true. if the first input scalar argument is sorted with respect to the second input argument according to the user-defined condition within isSorted, otherwise, it is .false..
If array is a Fortran string (i.e., an assumed-length scalar character), then both input arguments to isSorted() are character(1,SK) of default kind SK.
The following illustrates the generic interface of isSorted(),
function isSorted(a,b) result (sorted)
use pm_kind, only: IK, LK
TYPE(KIND) , intent(in) :: a, b
logical(LK) :: sorted
end function
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
where TYPE(KIND) is the same as the type and kind of the input argument array, which can be one of the following.
character(*, SK), intent(in) :: a, b
character(1, SK), intent(in) :: a, b
type(css_type) , intent(in) :: a, b
type(css_pdt) , intent(in) :: a, b
integer(IK) , intent(in) :: a, b
real(RK) , intent(in) :: a, b
This module contains the derived types for generating allocatable containers of scalar,...
This is the css_pdt parameterized type for generating instances of container of scalar of string obje...
This is the css_type type for generating instances of container of scalar of string objects.
where the specified kind type parameters (SK, IK, LK, CK, RK) can refer to any of the supported kinds by the processor.
This user-defined equivalence check is extremely useful where a user-defined sorting criterion other than simple ascending order is needed, for example, when the case-sensitivity of an input string or array of strings is irrelevant or when sorting of the absolute values matters excluding the signs of the numbers, or when descending order is desired.
In such cases, user can define a custom sorting condition within the user-defined external function isSorted to achieve the goal.
(optional, the default sorting condition is ascending order, that is a < b.)
[in]lb: The optional input scalar integer of default kind IK representing the lower bound of the segment of array below which the array elements are assumed to be in ascending order, such that only the elements starting with and beyond lb require sorting.
If the initial segment of the input array is ordered, specifying this lower bound will lead to better performance of the algorithm.
(optional, default = 1_IK)
[in]ub: The optional input scalar integer of default kind IK representing the upper bound of the segment of array above which the array elements are assumed to be in ascending order, such that only the elements ending with and below ub require sorting.
If the final segment of the input array is ordered, specifying this upper bound will lead to better performance of the algorithm.
(optional, default = size(array, kind = IK))


Possible calling interfaces

call setSelected(selection, array, rank, lb = lb, ub = ub)
call setSelected(selection, array, rank, isSorted, lb = lb, ub = ub)
Return the rankth smallest (or ordered) value in the input array by first sorting its elements in asc...
This module contains procedures and generic interfaces for selecting the th smallest element in unsor...
Warning
If lb is present as an input argument, its value must be larger than 0 and less than ub or its default value.
Furthermore, the specified rank must be larger than or equal to the specified value for lb.
If ub is present as an input argument, its value must be less than or equal to the length of array and larger than ub or its default value.
Furthermore, the specified rank must be smaller than or equal to the specified value for ub.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The functions under this generic interface are impure when the external input argument isSorted() is present.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
See also
getSelected
setRankDense
setRankOrdinal
setRankFractional
setRankStandard
setRankModified
setSorted
setSorted
getRemoved
setReversed
getReplaced
setReplaced
setSplit


Example usage

1program example
2
3 use pm_io, only: display_type
4 use pm_kind, only: SK, IK, LK
5 use pm_kind, only: RKL, RKD, RKH
6 use pm_kind, only: IKL, IKS, IKD, IKH
8
9 implicit none
10
11 integer(IK) , parameter :: NP = 6_IK
12
13 ! 1-dimensional array of real values.
14
15 real(RKL) :: array_RKL (NP), selection_RKL
16 real(RKD) :: array_RKD (NP), selection_RKD
17 real(RKH) :: array_RKH(NP), selection_RKH
18
19 ! 1-dimensional array of integer values.
20
21 integer(IKL) :: array_IKL (NP), selection_IKL
22 integer(IKS) :: array_IKS (NP), selection_IKS
23 integer(IKD) :: array_IKD (NP), selection_IKD
24 integer(IKH) :: array_IKH (NP), selection_IKH
25
26 ! Character array
27
28 character(:, SK), allocatable :: string_SK
29 character(1, SK) :: selectionString_SK
30
31 character(10,SK), allocatable :: array_SK(:)
32 character(10,SK) :: selectionarray_SK
33
34
35 integer(IK) :: i, rank
36
37 type(display_type) :: disp
38 disp = display_type(file = "main.out.F90")
39
40 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 ! Define the unselected arrays.
42 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43
44 call random_number(array_RKL); array_RKL = array_RKL - 0.5_RKL
45 call random_number(array_RKD); array_RKD = array_RKD - 0.5_RKD
46 call random_number(array_RKH); array_RKH = array_RKH - 0.5_RKH
47
48 array_IKL = int(array_RKH * huge(0_IKL), kind = IKL)
49 array_IKS = int(array_RKH * huge(0_IKS), kind = IKS)
50 array_IKD = int(array_RKH * huge(0_IKD), kind = IKD)
51 array_IKH = int(array_RKH * huge(0_IKH), kind = IKH)
52
53 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 ! Select arrays in ascending order.
55 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 call disp%skip()
58 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
59 call disp%show("!Select the `rank`th smallest element in the input `integer` Array.")
60 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
61 call disp%skip()
62
63 rank = 3_IK
64 call disp%skip()
65 call disp%show("rank")
66 call disp%show( rank )
67 call disp%show("array_IKL")
68 call disp%show( array_IKL )
69 call disp%show("call setSelected(selection_IKL, array_IKL, rank)")
70 call setSelected(selection_IKL, array_IKL, rank)
71 call disp%show("selection_IKL")
72 call disp%show( selection_IKL )
73 call disp%show("array_IKL")
74 call disp%show( array_IKL )
75 call disp%skip()
76
77 rank = 4_IK
78 call disp%skip()
79 call disp%show("rank")
80 call disp%show( rank )
81 call disp%show("array_IKS")
82 call disp%show( array_IKS )
83 call disp%show("call setSelected(selection_IKS, array_IKS, rank)")
84 call setSelected(selection_IKS, array_IKS, rank)
85 call disp%show("selection_IKS")
86 call disp%show( selection_IKS )
87 call disp%show("array_IKS")
88 call disp%show( array_IKS )
89 call disp%skip()
90
91 rank = 1_IK
92 call disp%skip()
93 call disp%show("rank")
94 call disp%show( rank )
95 call disp%show("array_IKD")
96 call disp%show( array_IKD )
97 call disp%show("call setSelected(selection_IKD, array_IKD, rank)")
98 call setSelected(selection_IKD, array_IKD, rank)
99 call disp%show("selection_IKD")
100 call disp%show( selection_IKD )
101 call disp%show("array_IKD")
102 call disp%show( array_IKD )
103 call disp%skip()
104
105 rank = 5_IK
106 call disp%skip()
107 call disp%show("rank")
108 call disp%show( rank )
109 call disp%show("array_IKH")
110 call disp%show( array_IKH )
111 call disp%show("call setSelected(selection_IKH, array_IKH, rank)")
112 call setSelected(selection_IKH, array_IKH, rank)
113 call disp%show("selection_IKH")
114 call disp%show( selection_IKH )
115 call disp%show("array_IKH")
116 call disp%show( array_IKH )
117 call disp%skip()
118
119 call disp%skip()
120 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
121 call disp%show("!Select the `rank`th smallest element in the input `real` Array.")
122 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
123 call disp%skip()
124
125 rank = 3_IK
126 call disp%skip()
127 call disp%show("rank")
128 call disp%show( rank )
129 call disp%show("array_RKL")
130 call disp%show( array_RKL )
131 call disp%show("call setSelected(selection_RKL, array_RKL, rank)")
132 call setSelected(selection_RKL, array_RKL, rank)
133 call disp%show("selection_RKL")
134 call disp%show( selection_RKL )
135 call disp%show("array_RKL")
136 call disp%show( array_RKL )
137 call disp%skip()
138
139 rank = 2_IK
140 call disp%skip()
141 call disp%show("rank")
142 call disp%show( rank )
143 call disp%show("array_RKD")
144 call disp%show( array_RKD )
145 call disp%show("call setSelected(selection_RKD, array_RKD, rank)")
146 call setSelected(selection_RKD, array_RKD, rank)
147 call disp%show("selection_RKD")
148 call disp%show( selection_RKD )
149 call disp%show("array_RKD")
150 call disp%show( array_RKD )
151 call disp%skip()
152
153 rank = size(array_RKH, kind = IK)
154 call disp%skip()
155 call disp%show("rank")
156 call disp%show( rank )
157 call disp%show("array_RKH")
158 call disp%show( array_RKH )
159 call disp%show("call setSelected(selection_RKH, array_RKH, rank)")
160 call setSelected(selection_RKH, array_RKH, rank)
161 call disp%show("selection_RKH")
162 call disp%show( selection_RKH )
163 call disp%show("array_RKH")
164 call disp%show( array_RKH )
165 call disp%skip()
166
167 call disp%skip()
168 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
169 call disp%show("!Select the `rank`th smallest element in the input Fortran `string` (character) array.")
170 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
171 call disp%skip()
172
173 array_SK = [ "ParaMonte " &
174 , "V.2 " &
175 , "is " &
176 , "a " &
177 , "Parallel " &
178 , "Monte " &
179 , "Carlo " &
180 , "and " &
181 , "Machine " &
182 , "Learning " &
183 , "Library. " &
184 ]
185
186 rank = 3_IK
187 call disp%skip()
188 call disp%show("rank")
189 call disp%show( rank )
190 call disp%show("array_SK")
191 call disp%show( array_SK, deliml = SK_"""" )
192 call disp%show("call setSelected(Selectionarray_SK, array_SK, rank)")
193 call setSelected(Selectionarray_SK, array_SK, rank)
194 call disp%show("Selectionarray_SK")
195 call disp%show( Selectionarray_SK, deliml = SK_"""" )
196 call disp%show("array_SK")
197 call disp%show( array_SK, deliml = SK_"""" )
198 call disp%skip()
199
200 call disp%skip()
201 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
202 call disp%show("!Select the `rank`th smallest element in the input Fortran `string` (character) scalar.")
203 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
204 call disp%skip()
205
206 rank = 3_IK
207 string_SK = "ParaMonte"
208 call disp%skip()
209 call disp%show("rank")
210 call disp%show( rank )
211 call disp%show("string_SK")
212 call disp%show( string_SK, deliml = SK_"""" )
213 call disp%show("call setSelected(selectionString_SK, string_SK, rank)")
214 call setSelected(selectionString_SK, string_SK, rank)
215 call disp%show("selectionString_SK")
216 call disp%show( selectionString_SK, deliml = SK_"""" )
217 call disp%show("string_SK")
218 call disp%show( string_SK, deliml = SK_"""" )
219 call disp%skip()
220
221 call disp%skip()
222 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
223 call disp%show("!Select the `rank`th smallest element in the input array of containers of Fortran `string` (character) scalars.")
224 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
225 call disp%skip()
226
227#if PDT_ENABLED
228 block
229 use pm_container, only: css_pdt
230 type(strc) :: selection
231 type(strc), allocatable :: array(:)
232 array = [ strc("ParaMonte") &
233 , strc("V.2") &
234 , strc("is") &
235 , strc("a") &
236 , strc("Parallel") &
237 , strc("Monte") &
238 , strc("Carlo") &
239 , strc("and") &
240 , strc("Machine") &
241 , strc("Learning") &
242 , strc("Library.") &
243 ]
244
245 rank = 3_IK
246 call disp%skip()
247 call disp%show("rank")
248 call disp%show( rank )
249 call disp%show("array")
250 call disp%show( array, deliml = SK_"""" )
251 call disp%show("call setSelected(selection, array, rank)")
252 call setSelected(selection, array, rank)
253 call disp%show("selection")
254 call disp%show( selection, deliml = SK_"""" )
255 call disp%show("array")
256 call disp%show( array, deliml = SK_"""" )
257 call disp%skip()
258 end block
259#endif
260
261 call disp%skip()
262 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
263 call disp%show("!Select according to an input user-defined comparison function.")
264 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
265 call disp%skip()
266
267 array_IKL = int([((-2)**i, i = 1, NP)], kind = IKL)
268 rank = 3_IK
269 call disp%skip()
270 call disp%show("!Select the `rank`th largest element via an input custom-designed `isSorted()` function.")
271 call disp%skip()
272 call disp%show("rank")
273 call disp%show( rank )
274 call disp%show("array_IKL")
275 call disp%show( array_IKL )
276 call disp%show("call setSelected(selection_IKL, array_IKL, rank, isSorted_IKL)")
277 call setSelected(selection_IKL, array_IKL, rank, isSorted_IKL)
278 call disp%show("selection_IKL")
279 call disp%show( selection_IKL )
280 call disp%show("array_IKL")
281 call disp%show( array_IKL )
282 call disp%skip()
283
284 call random_number(array_RKL); array_RKL = array_RKL - 0.5_RKL
285 call disp%skip()
286 call disp%show("!Select the `rank`th smallest element solely based on the magnitude of numbers using a custom comparison function.")
287 call disp%skip()
288 rank = 3_IK
289 call disp%show("rank")
290 call disp%show( rank )
291 call disp%show("array_RKL")
292 call disp%show( array_RKL )
293 call disp%show("call setSelected(selection_RKL, array_RKL, rank, isSorted_RKL)")
294 call setSelected(selection_RKL, array_RKL, rank, isSorted_RKL)
295 call disp%show("selection_RKL")
296 call disp%show( selection_RKL )
297 call disp%show("array_RKL")
298 call disp%show( array_RKL )
299 call disp%skip()
300
301 string_SK = "ParaMonte"
302 call disp%skip()
303 call disp%show("!Select the `rank`th smallest element with case-sensitivity (default behavior).")
304 call disp%skip()
305 rank = 3_IK
306 call disp%show("rank")
307 call disp%show( rank )
308 call disp%show("string_SK")
309 call disp%show( string_SK, deliml = SK_"""" )
310 call disp%show("call setSelected(selectionString_SK, string_SK, rank)")
311 call setSelected(selectionString_SK, string_SK, rank)
312 call disp%show("selectionString_SK")
313 call disp%show( selectionString_SK, deliml = SK_"""" )
314 call disp%show("string_SK")
315 call disp%show( string_SK, deliml = SK_"""" )
316 call disp%skip()
317
318 string_SK = "ParaMonte"
319 call disp%skip()
320 call disp%show("!Select the `rank`th smallest element WITHOUT case-sensitivity via a custom-designed input comparison function.")
321 call disp%skip()
322 rank = 3_IK
323 call disp%show("rank")
324 call disp%show( rank )
325 call disp%show("string_SK")
326 call disp%show( string_SK, deliml = SK_"""" )
327 call disp%show("call setSelected(selectionString_SK, string_SK, rank, isSorted_SK)")
328 call setSelected(selectionString_SK, string_SK, rank, isSorted_SK)
329 call disp%show("selectionString_SK")
330 call disp%show( selectionString_SK, deliml = SK_"""" )
331 call disp%show("string_SK")
332 call disp%show( string_SK, deliml = SK_"""" )
333 call disp%skip()
334
335 call disp%skip()
336 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
337 call disp%show("!Expedite the selection process for a partially sorted array via optional arguments `lb` or `ub`.")
338 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
339 call disp%skip()
340
341 array_IKL = [-3_IKL, -1_IKL, -2_IKL, 1_IKL, 2_IKL, 3_IKL] ! all elements after index `3` are sorted (`ub = 3_IK`).
342 rank = 3_IK
343 call disp%skip()
344 call disp%show("rank")
345 call disp%show( rank )
346 call disp%show("array_IKL")
347 call disp%show( array_IKL )
348 call disp%show("call setSelected(selection_IKL, array_IKL, rank, ub = 3_IK) ! all elements after index `3` are sorted (`ub = 3_IK`).")
349 call setSelected(selection_IKL, array_IKL, rank, ub = 3_IK)
350 call disp%show("selection_IKL")
351 call disp%show( selection_IKL )
352 call disp%show("array_IKL")
353 call disp%show( array_IKL )
354 call disp%skip()
355
356 array_IKL = [-3_IKL, -1_IKL, 3_IKL, -2_IKL, 2_IKL, 1_IKL]
357 call disp%skip()
358 call disp%show("!Select the second, fourth, and fifth smallest elements of the array sequentially in order.")
359 call disp%skip()
360 block
361 integer(IK) :: i, RankList(0:3) = [0_IK, 2_IK, 4_IK, 5_IK]
362 call disp%show("RankList")
363 call disp%show( RankList )
364 do i = 1, size(RankList(1:))
365 call disp%skip()
366 call disp%show("RankList(i)")
367 call disp%show( RankList(i) )
368 call disp%show("array_IKL")
369 call disp%show( array_IKL )
370 call disp%show("call setSelected(selection_IKL, array_IKL, rank = RankList(i), lb = RankList(i-1)+1) ! all elements after `lb` need sorting.")
371 call setSelected(selection_IKL, array_IKL, rank = RankList(i), lb = RankList(i-1)+1)
372 call disp%show("selection_IKL")
373 call disp%show( selection_IKL )
374 call disp%show("array_IKL")
375 call disp%show( array_IKL )
376 end do
377 end block
378 call disp%skip()
379
380contains
381
382 function isSorted_IKL(a,b) result(isSorted)
383 use pm_kind, only: LK, IKL
384 integer(IKL) , intent(in) :: a, b
385 logical(LK) :: isSorted
386 isSorted = a > b
387 end function
388
389 function isSorted_RKL(a,b) result(isSorted)
390 use pm_kind, only: LK, IKL
391 integer(IKL) , intent(in) :: a, b
392 logical(LK) :: isSorted
393 isSorted = abs(a) < abs(b)
394 end function
395
396 function isSorted_SK(a,b) result(isSorted)
397 use pm_strASCII, only: getStrLower
398 use pm_kind, only: LK, SK
399 character(1, SK), intent(in) :: a, b
400 logical(LK) :: isSorted
401 isSorted = getStrLower(a) < getStrLower(b)
402 end function
403
404end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return the input string where the uppercase English alphabets are all converted to lower...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
integer, parameter IKS
The single-precision integer kind in Fortran mode. On most platforms, this is a 32-bit integer kind.
Definition: pm_kind.F90:563
integer, parameter IKL
The scalar integer constant of intrinsic default kind, representing the lowest range integer kind typ...
Definition: pm_kind.F90:749
integer, parameter IKH
The scalar integer constant of intrinsic default kind, representing the highest range integer kind ty...
Definition: pm_kind.F90:828
integer, parameter RKL
The scalar integer constant of intrinsic default kind, representing the lowest-precision real kind ty...
Definition: pm_kind.F90:779
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
Definition: pm_kind.F90:568
integer, parameter IKD
The double precision integer kind in Fortran mode. On most platforms, this is a 64-bit integer kind.
Definition: pm_kind.F90:564
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
This module contains the uncommon and hardly representable ASCII characters as well as procedures for...
Definition: pm_strASCII.F90:61
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!Select the `rank`th smallest element in the input `integer` Array.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7rank
8+3
9array_IKL
10-15, +22, +35, -58, -37, +18
11call setSelected(selection_IKL, array_IKL, rank)
12selection_IKL
13-15
14array_IKL
15-58, -37, -15, +18, +22, +35
16
17
18rank
19+4
20array_IKS
21-269016567, +376543992, +608022936, -984665298, -638599535, +307249953
22call setSelected(selection_IKS, array_IKS, rank)
23selection_IKS
24+307249953
25array_IKS
26-269016567, -984665298, -638599535, +307249953, +376543992, +608022936
27
28
29rank
30+1
31array_IKD
32-1155417358637922813, +1617244134978819075, +2611438627240684292, -4229105254552435210, -2742764122318010190, +1319628503186055477
33call setSelected(selection_IKD, array_IKD, rank)
34selection_IKD
35-4229105254552435210
36array_IKD
37-4229105254552435210, -2742764122318010190, -1155417358637922813, +1319628503186055477, +1617244134978819075, +2611438627240684292
38
39
40rank
41+5
42array_IKH
43-21313688313115246263541118042306740224, +29832888662662060948620098916456005632, +48172540020908299828374339394305654784, -78013222291509058970981584993305690112, -50595067818952934224369323711014289408, +24342849270645575027537694594983706624
44call setSelected(selection_IKH, array_IKH, rank)
45selection_IKH
46+29832888662662060948620098916456005632
47array_IKH
48-21313688313115246263541118042306740224, -78013222291509058970981584993305690112, -50595067818952934224369323711014289408, +24342849270645575027537694594983706624, +29832888662662060948620098916456005632, +48172540020908299828374339394305654784
49
50
51!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52!Select the `rank`th smallest element in the input `real` Array.
53!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55
56rank
57+3
58array_RKL
59-0.203167796, +0.703667402E-1, +0.414119005, -0.392831445, -0.765180588E-2, +0.331009507
60call setSelected(selection_RKL, array_RKL, rank)
61selection_RKL
62-0.765180588E-2
63array_RKL
64-0.392831445, -0.203167796, -0.765180588E-2, +0.703667402E-1, +0.331009507, +0.414119005
65
66
67rank
68+2
69array_RKD
70-0.78607442126927496E-1, +0.47571444967619991, +0.31105935457639422, +0.31554229192827310, -0.17600373113216772, +0.44151907425803649
71call setSelected(selection_RKD, array_RKD, rank)
72selection_RKD
73-0.78607442126927496E-1
74array_RKD
75-0.17600373113216772, -0.78607442126927496E-1, +0.31105935457639422, +0.31554229192827310, +0.47571444967619991, +0.44151907425803649
76
77
78rank
79+6
80array_RKH
81-0.125270601036269912651325575585172178, +0.175341960458347601391938629560310348, +0.283132743296691331013384594967629678, -0.458520510465561249704508686515329256, -0.297371082003248446645118993843835517, +0.143074409002811575804946900434862879
82call setSelected(selection_RKH, array_RKH, rank)
83selection_RKH
84+0.283132743296691331013384594967629678
85array_RKH
86-0.125270601036269912651325575585172178, -0.458520510465561249704508686515329256, -0.297371082003248446645118993843835517, +0.143074409002811575804946900434862879, +0.175341960458347601391938629560310348, +0.283132743296691331013384594967629678
87
88
89!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90!Select the `rank`th smallest element in the input Fortran `string` (character) array.
91!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
93
94rank
95+3
96array_SK
97"ParaMonte ", "V.2 ", "is ", "a ", "Parallel ", "Monte ", "Carlo ", "and ", "Machine ", "Learning ", "Library. "
98call setSelected(Selectionarray_SK, array_SK, rank)
99Selectionarray_SK
100"Library. "
101array_SK
102"Carlo ", "Learning ", "Library. ", "Machine ", "Monte ", "V.2 ", "Parallel ", "and ", "a ", "is ", "ParaMonte "
103
104
105!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106!Select the `rank`th smallest element in the input Fortran `string` (character) scalar.
107!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109
110rank
111+3
112string_SK
113"ParaMonte"
114call setSelected(selectionString_SK, string_SK, rank)
115selectionString_SK
116"a"
117string_SK
118"MPaaenotr"
119
120
121!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122!Select the `rank`th smallest element in the input array of containers of Fortran `string` (character) scalars.
123!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124
125
126!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127!Select according to an input user-defined comparison function.
128!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129
130
131!Select the `rank`th largest element via an input custom-designed `isSorted()` function.
132
133rank
134+3
135array_IKL
136-2, +4, -8, +16, -32, +64
137call setSelected(selection_IKL, array_IKL, rank, isSorted_IKL)
138selection_IKL
139+4
140array_IKL
141+64, +16, +4, -2, -32, -8
142
143
144!Select the `rank`th smallest element solely based on the magnitude of numbers using a custom comparison function.
145
146rank
147+3
148array_RKL
149+0.144464016, -0.426781118, +0.397746682, +0.481497347, -0.160893619, +0.220654011
150call setSelected(selection_RKL, array_RKL, rank, isSorted_RKL)
151selection_RKL
152+0.481497347
153array_RKL
154+0.220654011, -0.426781118, +0.481497347, -0.160893619, +0.144464016, +0.397746682
155
156
157!Select the `rank`th smallest element with case-sensitivity (default behavior).
158
159rank
160+3
161string_SK
162"ParaMonte"
163call setSelected(selectionString_SK, string_SK, rank)
164selectionString_SK
165"a"
166string_SK
167"MPaaenotr"
168
169
170!Select the `rank`th smallest element WITHOUT case-sensitivity via a custom-designed input comparison function.
171
172rank
173+3
174string_SK
175"ParaMonte"
176call setSelected(selectionString_SK, string_SK, rank, isSorted_SK)
177selectionString_SK
178"e"
179string_SK
180"aaeMrontP"
181
182
183!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184!Expedite the selection process for a partially sorted array via optional arguments `lb` or `ub`.
185!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186
187
188rank
189+3
190array_IKL
191-3, -1, -2, +1, +2, +3
192call setSelected(selection_IKL, array_IKL, rank, ub = 3_IK) ! all elements after index `3` are sorted (`ub = 3_IK`).
193selection_IKL
194-1
195array_IKL
196-3, -2, -1, +1, +2, +3
197
198
199!Select the second, fourth, and fifth smallest elements of the array sequentially in order.
200
201RankList
202+0, +2, +4, +5
203
204RankList(i)
205+2
206array_IKL
207-3, -1, +3, -2, +2, +1
208call setSelected(selection_IKL, array_IKL, rank = RankList(i), lb = RankList(i-1)+1) ! all elements after `lb` need sorting.
209selection_IKL
210-2
211array_IKL
212-3, -2, -1, +1, +2, +3
213
214RankList(i)
215+4
216array_IKL
217-3, -2, -1, +1, +2, +3
218call setSelected(selection_IKL, array_IKL, rank = RankList(i), lb = RankList(i-1)+1) ! all elements after `lb` need sorting.
219selection_IKL
220+1
221array_IKL
222-3, -2, -1, +1, +2, +3
223
224RankList(i)
225+5
226array_IKL
227-3, -2, -1, +1, +2, +3
228call setSelected(selection_IKL, array_IKL, rank = RankList(i), lb = RankList(i-1)+1) ! all elements after `lb` need sorting.
229selection_IKL
230+2
231array_IKL
232-3, -2, -1, +1, +2, +3
233
234
Test:
test_pm_arraySelect
Todo:
Low Priority: This generic interface can be extended to higher-rank input objects.


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 1725 of file pm_arraySelect.F90.


The documentation for this interface was generated from the following file: