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

Generate and return an array of size two containing the minimum and maximum of the two input values in the first and second elements, respectively.
More...

Detailed Description

Generate and return an array of size two containing the minimum and maximum of the two input values in the first and second elements, respectively.

Note that strings and complex values are compared lexicographically.
See pm_complexCompareLex and pm_container for more information on the relevant lexical comparison operators.
Also, note that a logical .false. is less than .true. in this module.

Parameters
[in]a: The input scalar of the same type and kind as the output minMax.
(optional, it must be present if and only if the input argument b is also present.)
[in]b: The input scalar of the same type and kind as the output minMax.
(optional, it must be present if and only if the input argument a is also present.)
[in]pair: The input vector of length 2 of the same type and kind as the output minMax.
(optional, it must be present if and only if the input arguments a and b are missing.)
Returns
minMax : The output vector of shape (2) of either
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary len type-parameter, or
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or
  3. type logical of kind any supported by the processor (e.g., LK) or
  4. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or
  5. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128).
containing min(a,b) or minval(pair) in the first element and max(a,b) or maxval(pair) in the second element.


Possible calling interfaces

minMax(1:2) = getMinMax(a, b) ! on output, minMax(1) <= minMax(2) holds.
minMax(1:2) = getMinMax(pair(1:2)) ! on output, minMax(1) <= minMax(2) holds.
!
Generate and return an array of size two containing the minimum and maximum of the two input values i...
This module contains procedures and generic interfaces for finding the minimum and maximum of two inp...
Warning
If the two input arguments a and b are of type character, then they are assumed to have the same length.
Otherwise, the output minMax will have a length type parameter that is the maximum of the two input values.
This means that array padding with blanks will occur for the value of the shorter string.
For clarifications, see the examples below.
Remarks
The procedures under discussion are pure.
Note
The procedures under this generic interface are particularly useful in combination with getLogAddExp and similar interfaces.
See also
setMinMax
getLogAddExp


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, CK, RK ! all intrinsic types and kinds are supported.
4 use pm_io, only: display_type
5 use pm_mathMinMax, only: getMinMax
6
7 implicit none
8
9 type(display_type) :: disp
10
11 character(:, SK), allocatable :: a_SK, b_SK, Pair_SK(:)
12 integer(IK) :: a_IK, b_IK, Pair_IK(2)
13 logical(LK) :: a_LK, b_LK, Pair_LK(2)
14 complex(CK) :: a_CK, b_CK, Pair_CK(2)
15 real(RK) :: a_RK, b_RK, Pair_RK(2)
16
17 a_SK = "Hell" ; b_SK = "Heaven"
18 a_IK = 10_IK ; b_IK = 5_IK
19 a_LK = .true._LK ; b_LK = .false._LK
20 a_CK = (+10._CK, -5._CK); b_CK = (+5._CK, +15._CK)
21 a_RK = 10._RK ; b_RK = 5._RK
22
23 disp = display_type(file = "main.out.F90")
24
25 call disp%skip()
26 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show("!Get the min/max of string values")
28 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
29 call disp%skip()
30
31 call disp%skip()
32 call disp%show("Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]")
33 Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]
34 call disp%show("Pair_SK")
35 call disp%show( Pair_SK , deliml = SK_"""" )
36 call disp%show("getMinMax(Pair_SK)")
37 call disp%show( getMinMax(Pair_SK) , deliml = SK_"""" )
38 call disp%skip()
39
40 call disp%skip()
41 call disp%show("Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]")
42 Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]
43 call disp%show("Pair_SK")
44 call disp%show( Pair_SK , deliml = SK_"""" )
45 call disp%show("getMinMax(Pair_SK(1), Pair_SK(2))")
46 call disp%show( getMinMax(Pair_SK(1), Pair_SK(2)) , deliml = SK_"""" )
47 call disp%skip()
48
49 call disp%skip()
50 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
51 call disp%show("!Get the min/max of integer values")
52 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
53 call disp%skip()
54
55 call disp%skip()
56 call disp%show("Pair_IK = [a_IK, b_IK]")
57 Pair_IK = [a_IK, b_IK]
58 call disp%show("Pair_IK")
59 call disp%show( Pair_IK )
60 call disp%show("getMinMax(Pair_IK)")
61 call disp%show( getMinMax(Pair_IK) )
62 call disp%skip()
63
64 call disp%skip()
65 call disp%show("Pair_IK = [a_IK, b_IK]")
66 Pair_IK = [a_IK, b_IK]
67 call disp%show("Pair_IK")
68 call disp%show( Pair_IK )
69 call disp%show("getMinMax(Pair_IK(1), Pair_IK(2))")
70 call disp%show( getMinMax(Pair_IK(1), Pair_IK(2)) )
71 call disp%skip()
72
73 call disp%skip()
74 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
75 call disp%show("!Get the min/max of logical values")
76 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
77 call disp%skip()
78
79 call disp%skip()
80 call disp%show("Pair_LK = [a_LK, b_LK]")
81 Pair_LK = [a_LK, b_LK]
82 call disp%show("Pair_LK")
83 call disp%show( Pair_LK )
84 call disp%show("getMinMax(Pair_LK)")
85 call disp%show( getMinMax(Pair_LK) )
86 call disp%skip()
87
88 call disp%skip()
89 call disp%show("Pair_LK = [a_LK, b_LK]")
90 Pair_LK = [a_LK, b_LK]
91 call disp%show("Pair_LK")
92 call disp%show( Pair_LK )
93 call disp%show("getMinMax(Pair_LK(1), Pair_LK(2))")
94 call disp%show( getMinMax(Pair_LK(1), Pair_LK(2)) )
95 call disp%skip()
96
97 call disp%skip()
98 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
99 call disp%show("!Get the min/max of complex values")
100 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
101 call disp%skip()
102
103 call disp%skip()
104 call disp%show("Pair_CK = [a_CK, b_CK]")
105 Pair_CK = [a_CK, b_CK]
106 call disp%show("Pair_CK")
107 call disp%show( Pair_CK )
108 call disp%show("getMinMax(Pair_CK)")
109 call disp%show( getMinMax(Pair_CK) )
110 call disp%skip()
111
112 call disp%skip()
113 call disp%show("Pair_CK = [a_CK, b_CK]")
114 Pair_CK = [a_CK, b_CK]
115 call disp%show("Pair_CK")
116 call disp%show( Pair_CK )
117 call disp%show("getMinMax(Pair_CK(1), Pair_CK(2))")
118 call disp%show( getMinMax(Pair_CK(1), Pair_CK(2)) )
119 call disp%skip()
120
121 call disp%skip()
122 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
123 call disp%show("!Get the min/max of real values")
124 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
125 call disp%skip()
126
127 call disp%skip()
128 call disp%show("Pair_RK = [a_RK, b_RK]")
129 Pair_RK = [a_RK, b_RK]
130 call disp%show("Pair_RK")
131 call disp%show( Pair_RK )
132 call disp%show("getMinMax(Pair_RK)")
133 call disp%show( getMinMax(Pair_RK) )
134 call disp%skip()
135
136 call disp%skip()
137 call disp%show("Pair_RK = [a_RK, b_RK]")
138 Pair_RK = [a_RK, b_RK]
139 call disp%show("Pair_RK")
140 call disp%show( Pair_RK )
141 call disp%show("getMinMax(Pair_RK(1), Pair_RK(2))")
142 call disp%show( getMinMax(Pair_RK(1), Pair_RK(2)) )
143 call disp%skip()
144
145end 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
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
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
Definition: pm_kind.F90:542
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
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
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!Get the min/max of string values
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]
8Pair_SK
9"Hell ", "Heaven"
10getMinMax(Pair_SK)
11"Heaven", "Hell "
12
13
14Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]
15Pair_SK
16"Hell ", "Heaven"
17getMinMax(Pair_SK(1), Pair_SK(2))
18"Heaven", "Hell "
19
20
21!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22!Get the min/max of integer values
23!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
25
26Pair_IK = [a_IK, b_IK]
27Pair_IK
28+10, +5
29getMinMax(Pair_IK)
30+5, +10
31
32
33Pair_IK = [a_IK, b_IK]
34Pair_IK
35+10, +5
36getMinMax(Pair_IK(1), Pair_IK(2))
37+5, +10
38
39
40!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41!Get the min/max of logical values
42!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43
44
45Pair_LK = [a_LK, b_LK]
46Pair_LK
47T, F
48getMinMax(Pair_LK)
49F, T
50
51
52Pair_LK = [a_LK, b_LK]
53Pair_LK
54T, F
55getMinMax(Pair_LK(1), Pair_LK(2))
56F, T
57
58
59!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60!Get the min/max of complex values
61!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62
63
64Pair_CK = [a_CK, b_CK]
65Pair_CK
66(+10.000000000000000, -5.0000000000000000), (+5.0000000000000000, +15.000000000000000)
67getMinMax(Pair_CK)
68(+5.0000000000000000, +15.000000000000000), (+10.000000000000000, -5.0000000000000000)
69
70
71Pair_CK = [a_CK, b_CK]
72Pair_CK
73(+10.000000000000000, -5.0000000000000000), (+5.0000000000000000, +15.000000000000000)
74getMinMax(Pair_CK(1), Pair_CK(2))
75(+5.0000000000000000, +15.000000000000000), (+10.000000000000000, -5.0000000000000000)
76
77
78!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79!Get the min/max of real values
80!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81
82
83Pair_RK = [a_RK, b_RK]
84Pair_RK
85+10.000000000000000, +5.0000000000000000
86getMinMax(Pair_RK)
87+5.0000000000000000, +10.000000000000000
88
89
90Pair_RK = [a_RK, b_RK]
91Pair_RK
92+10.000000000000000, +5.0000000000000000
93getMinMax(Pair_RK(1), Pair_RK(2))
94+5.0000000000000000, +10.000000000000000
95
96
Test:
test_pm_mathMinMax
Todo:
Low Priority: This generic interface can be expanded to include the possibility of passing user-defined custom comparison.


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, Thursday 1:45 AM, August 22, 2019, Dallas, TX

Definition at line 117 of file pm_mathMinMax.F90.


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