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

Return the minimum and maximum of the two input scalar values a and b in a and b, respectively, on output.
More...

Detailed Description

Return the minimum and maximum of the two input scalar values a and b in a and b, respectively, on output.

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,out]a: The input/output scalar, or array of the same rank, shape, and size other array-like arguments, 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).
On output, its value will be overwritten with min(a,b).
(optional, it must be present if and only if the argument b is also present.)
[in,out]b: The input/output scalar, or array of the same rank, shape, and size other array-like arguments, of the same type and kind as the input a.
On output, its value will be overwritten with max(a,b).
(optional, it must be present if and only if the argument a is also present.)
[in,out]pair: The input/output vector of size 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).
On output, its value will be overwritten with [min(a,b), max(a,b)].
(optional, it must be present if and only if the arguments a and b are missing.)


Possible calling interfaces

call setMinMax(a, b) ! on output, a <= b holds.
call setMinMax(pair) ! on output, pair(1) <= pair(2) holds.
!
Return the minimum and maximum of the two input scalar values a and b in a and b, respectively,...
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.
The rank and size of the two input arguments must be the same.
Remarks
The procedures under discussion are pure.
The procedures under discussion are elemental. The procedures under this generic interface are not elemental when the input argument pair is present.
Note
The procedures under this generic interface are particularly useful in combination with getLogAddExp and similar interfaces.
See also
getMinMax
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: setMinMax
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("call setMinMax(Pair_SK)")
37 call setMinMax(Pair_SK)
38 call disp%show("Pair_SK")
39 call disp%show( Pair_SK , deliml = SK_"""" )
40 call disp%skip()
41
42 call disp%skip()
43 call disp%show("Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]")
44 Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]
45 call disp%show("Pair_SK")
46 call disp%show( Pair_SK , deliml = SK_"""" )
47 call disp%show("call setMinMax(Pair_SK(1), Pair_SK(2))")
48 call setMinMax(Pair_SK(1), Pair_SK(2))
49 call disp%show("Pair_SK")
50 call disp%show( Pair_SK , deliml = SK_"""" )
51 call disp%skip()
52
53 call disp%skip()
54 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
55 call disp%show("!Get the min/max of integer values")
56 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
57 call disp%skip()
58
59 call disp%skip()
60 call disp%show("Pair_IK = [a_IK, b_IK]")
61 Pair_IK = [a_IK, b_IK]
62 call disp%show("Pair_IK")
63 call disp%show( Pair_IK )
64 call disp%show("call setMinMax(Pair_IK)")
65 call setMinMax(Pair_IK)
66 call disp%show("Pair_IK")
67 call disp%show( Pair_IK )
68 call disp%skip()
69
70 call disp%skip()
71 call disp%show("Pair_IK = [a_IK, b_IK]")
72 Pair_IK = [a_IK, b_IK]
73 call disp%show("Pair_IK")
74 call disp%show( Pair_IK )
75 call disp%show("call setMinMax(Pair_IK(1), Pair_IK(2))")
76 call setMinMax(Pair_IK(1), Pair_IK(2))
77 call disp%show("Pair_IK")
78 call disp%show( Pair_IK )
79 call disp%skip()
80
81 call disp%skip()
82 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
83 call disp%show("!Get the min/max of logical values")
84 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
85 call disp%skip()
86
87 call disp%skip()
88 call disp%show("Pair_LK = [a_LK, b_LK]")
89 Pair_LK = [a_LK, b_LK]
90 call disp%show("Pair_LK")
91 call disp%show( Pair_LK )
92 call disp%show("call setMinMax(Pair_LK)")
93 call setMinMax(Pair_LK)
94 call disp%show("Pair_LK")
95 call disp%show( Pair_LK )
96 call disp%skip()
97
98 call disp%skip()
99 call disp%show("Pair_LK = [a_LK, b_LK]")
100 Pair_LK = [a_LK, b_LK]
101 call disp%show("Pair_LK")
102 call disp%show( Pair_LK )
103 call disp%show("call setMinMax(Pair_LK(1), Pair_LK(2))")
104 call setMinMax(Pair_LK(1), Pair_LK(2))
105 call disp%show("Pair_LK")
106 call disp%show( Pair_LK )
107 call disp%skip()
108
109 call disp%skip()
110 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
111 call disp%show("!Get the min/max of complex values")
112 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
113 call disp%skip()
114
115 call disp%skip()
116 call disp%show("Pair_CK = [a_CK, b_CK]")
117 Pair_CK = [a_CK, b_CK]
118 call disp%show("Pair_CK")
119 call disp%show( Pair_CK )
120 call disp%show("call setMinMax(Pair_CK)")
121 call setMinMax(Pair_CK)
122 call disp%show("Pair_CK")
123 call disp%show( Pair_CK )
124 call disp%skip()
125
126 call disp%skip()
127 call disp%show("Pair_CK = [a_CK, b_CK]")
128 Pair_CK = [a_CK, b_CK]
129 call disp%show("Pair_CK")
130 call disp%show( Pair_CK )
131 call disp%show("call setMinMax(Pair_CK(1), Pair_CK(2))")
132 call setMinMax(Pair_CK(1), Pair_CK(2))
133 call disp%show("Pair_CK")
134 call disp%show( Pair_CK )
135 call disp%skip()
136
137 call disp%skip()
138 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
139 call disp%show("!Get the min/max of real values")
140 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
141 call disp%skip()
142
143 call disp%skip()
144 call disp%show("Pair_RK = [a_RK, b_RK]")
145 Pair_RK = [a_RK, b_RK]
146 call disp%show("Pair_RK")
147 call disp%show( Pair_RK )
148 call disp%show("call setMinMax(Pair_RK)")
149 call setMinMax(Pair_RK)
150 call disp%show("Pair_RK")
151 call disp%show( Pair_RK )
152 call disp%skip()
153
154 call disp%skip()
155 call disp%show("Pair_RK = [a_RK, b_RK]")
156 Pair_RK = [a_RK, b_RK]
157 call disp%show("Pair_RK")
158 call disp%show( Pair_RK )
159 call disp%show("call setMinMax(Pair_RK(1), Pair_RK(2))")
160 call setMinMax(Pair_RK(1), Pair_RK(2))
161 call disp%show("Pair_RK")
162 call disp%show( Pair_RK )
163 call disp%skip()
164
165 call disp%skip()
166 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
167 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
168 call disp%show("!Elemental min/max setting")
169 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
170 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%")
171 call disp%skip()
172
173 block
174 integer(IK), allocatable :: a(:), b(:)
175 a = [1, -2, 3, -4]
176 b = [-1, 2, -3, 4]
177 call disp%skip()
178 call disp%show("a")
179 call disp%show( a )
180 call disp%show("b")
181 call disp%show( b )
182 call disp%show("call setMinMax(a, b)")
183 call setMinMax(a, b)
184 call disp%show("a")
185 call disp%show( a )
186 call disp%show("b")
187 call disp%show( b )
188 call disp%skip()
189 end block
190
191end 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"
10call setMinMax(Pair_SK)
11Pair_SK
12"Heaven", "Hell "
13
14
15Pair_SK = [character(max(len(a_SK),len(b_SK)), SK) :: a_SK, b_SK]
16Pair_SK
17"Hell ", "Heaven"
18call setMinMax(Pair_SK(1), Pair_SK(2))
19Pair_SK
20"Heaven", "Hell "
21
22
23!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24!Get the min/max of integer values
25!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
27
28Pair_IK = [a_IK, b_IK]
29Pair_IK
30+10, +5
31call setMinMax(Pair_IK)
32Pair_IK
33+5, +10
34
35
36Pair_IK = [a_IK, b_IK]
37Pair_IK
38+10, +5
39call setMinMax(Pair_IK(1), Pair_IK(2))
40Pair_IK
41+5, +10
42
43
44!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45!Get the min/max of logical values
46!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48
49Pair_LK = [a_LK, b_LK]
50Pair_LK
51T, F
52call setMinMax(Pair_LK)
53Pair_LK
54F, T
55
56
57Pair_LK = [a_LK, b_LK]
58Pair_LK
59T, F
60call setMinMax(Pair_LK(1), Pair_LK(2))
61Pair_LK
62F, T
63
64
65!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66!Get the min/max of complex values
67!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68
69
70Pair_CK = [a_CK, b_CK]
71Pair_CK
72(+10.000000000000000, -5.0000000000000000), (+5.0000000000000000, +15.000000000000000)
73call setMinMax(Pair_CK)
74Pair_CK
75(+5.0000000000000000, +15.000000000000000), (+10.000000000000000, -5.0000000000000000)
76
77
78Pair_CK = [a_CK, b_CK]
79Pair_CK
80(+10.000000000000000, -5.0000000000000000), (+5.0000000000000000, +15.000000000000000)
81call setMinMax(Pair_CK(1), Pair_CK(2))
82Pair_CK
83(+5.0000000000000000, +15.000000000000000), (+10.000000000000000, -5.0000000000000000)
84
85
86!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87!Get the min/max of real values
88!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
90
91Pair_RK = [a_RK, b_RK]
92Pair_RK
93+10.000000000000000, +5.0000000000000000
94call setMinMax(Pair_RK)
95Pair_RK
96+5.0000000000000000, +10.000000000000000
97
98
99Pair_RK = [a_RK, b_RK]
100Pair_RK
101+10.000000000000000, +5.0000000000000000
102call setMinMax(Pair_RK(1), Pair_RK(2))
103Pair_RK
104+5.0000000000000000, +10.000000000000000
105
106
107!%%%%%%%%%%%%%%%%%%%%%%%%%
108!%%%%%%%%%%%%%%%%%%%%%%%%%
109!Elemental min/max setting
110!%%%%%%%%%%%%%%%%%%%%%%%%%
111!%%%%%%%%%%%%%%%%%%%%%%%%%
112
113
114a
115+1, -2, +3, -4
116b
117-1, +2, -3, +4
118call setMinMax(a, b)
119a
120-1, -2, -3, -4
121b
122+1, +2, +3, +4
123
124
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 789 of file pm_mathMinMax.F90.


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