ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation. |
Sort the input scalar string or contiguous
vector in ascending order, or return the sorted indices of the input scalar string or contiguous
array
of rank 1
in ascending order or in the user-specified order.
More...
Sort the input scalar string or contiguous
vector in ascending order, or return the sorted indices of the input scalar string or contiguous
array
of rank 1
in ascending order or in the user-specified order.
This generic interface either sorts the contents of an array or its indices in ascending order or via the user-specified custom input procedure isSorted()
.
The resulting output array or its index
will be in ascending order (or in the requested order as specified by isSorted()
.
There are currently twelve sorting algorithms implemented in this generic interface.
Only the default sorting method can be used for sorting the indices of an array.
However, all sorting methods can be used to sort the elements of the array.
The default algorithm is generally the fastest sorting method.
[in,out] | array | : The contiguous array of rank 1 of either
|
[out] | index | : The output contiguous array of rank 1 of type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) of the same length as the input argument array containing the rank (i.e., sorted indices) of array such that array(index(:)) is sorted in ascending order on return.The size of index must match that of array (or its length type parameter if array is a scalar string).Read index(i) as the index of the element of array that contains the i th smallest (or ranked) value in the array .This kind of ranking of values is widely known as ordinal ranking. In ordinal ranking, all items receive distinct ordinal numbers, including items that compare equal. The assignment of distinct ordinal numbers to items that compare equal can be done at random, or arbitrarily. But it is generally preferable to use a system that is arbitrary but consistent, as this gives stable results if the ranking is done multiple times. In computer data processing, ordinal ranking is also referred to as row numbering. (optional. If missing, the contents of the input array will be sorted in ascending order and returned instead. It can be present only if the input argument method is missing.) |
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 scalar string (i.e., an assumed-length scalar character ), then both input arguments to isSorted() are scalar characters of length 1 of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU).The following illustrates the generic interface of isSorted() , function isSorted(lhs, rhs) result(sorted)
TYPE(KIND) , intent(in) :: lhs, rhs
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 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) :: lhs, rhs
character(1, SK), intent(in) :: lhs, rhs
type(css_type) , intent(in) :: lhs, rhs
type(css_pdt) , intent(in) :: lhs, rhs
integer(IK) , intent(in) :: lhs, rhs
logical(LK) , intent(in) :: lhs, rhs
complex(CK) , intent(in) :: lhs, rhs
real(RK) , intent(in) :: lhs, rhs
This module contains the derived types for generating allocatable containers of scalar,... Definition: pm_container.F90:113 This is the css_pdt parameterized type for generating instances of container of scalar of string obje... Definition: pm_container.F90:783 This is the css_type type for generating instances of container of scalar of string objects. Definition: pm_container.F90:191 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 .) | |
method | : The input scalar constant that can be any of the following:
(optional. default = qsorti. It can be present only if the input argument index is missing.) |
Possible calling interfaces ⛓
array
and index
must be equal.CHECK_ENABLED=1
.pure
. The procedures under this generic interface are always impure
when the input argument isSorted()
is present.recursive
. The procedures are explicitly recursive
only if the input argument method
is set to any of the recursive
sorting algorithms.minloc
in the sorting routines appears to lead a slightly better performance than the manual search.index
elements from the end to the beginning or, rewrite the array with array = array( index(ubound(array, dim = 1) : lbound(array, dim = 1) : -1) )
.array = array(ubound(array, dim = 1) : lbound(array, dim = 1) : -1)
.isSorted()
with the appropriate comparison.
Example usage ⛓
ifort
compiler ⛓ ifort
compiler ⛓ gfortran
compiler ⛓ ifort
version 2021.5 ifort
version 2021.5 that also applies to this module. gfortran
version 10.3 gfortran
version 10.3 cannot not compile the allocation of PDT string container object temp
within the implementation of the corresponding procedures.
Remedy (as of ParaMonte Library version 2.0.0): For now, all allocatable Temp
objects are converted to automatic arrays.
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.
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.
Definition at line 5540 of file pm_arraySort.F90.