ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation. |
Generate and return the sorted elements of the input scalar string or contiguous
vector in ascending order, or the sorted indices of the input scalar string or contiguous
array
of rank 1
in ascending order or in the user-specified order.
More...
Generate and return the sorted elements of the input scalar string or contiguous
vector in ascending order, or 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 sorting
will be in ascending order (or in the requested order as specified by isSorted()
.
[in] | array | : The contiguous array of rank 1 of either
|
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 sorting is missing.) |
sorting
: The output object whose type and kind depends on the specified input method
:method
is set to isort or an object of type set to isort_type, then the output sorting
is of type integer
of default kind IK of rank 1
of the same size as the number of elements in the input array
containing the sorted indices of the elements of the input array.<br> **Read
sorting(i)as the index of the element of
arraythat contains the
ith smallest (or ranked) value in the
array`.**method
is missing or set to any other value than the above, then the output sorting
is of the same type, kind, rank, and shape as the input array
, containing the sorted elements of the input array.
Possible calling interfaces ⛓
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.pure
in release
build and impure
in debug
and testing
builds. The procedures under this generic interface are always impure
when the input argument isSorted()
is present.minloc
in the sorting routines appears to lead a slightly better performance than the manual search.sorting
indices, simply call the output sorting
indices from the end to the beginning or, rewrite the array with array = array(sorting(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 ⛓
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 3349 of file pm_arraySort.F90.