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

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

Detailed Description

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

Note that complex values are compared lexicographically.
However, when the input sequence is a scalar string, the individual characters comprise the elements/values that are compared against each other.
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]array: The input scalar sequence of,
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary len type-parameter,
or an array of,
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary len type-parameter,
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
  3. type logical of kind any supported by the processor (e.g., LK),
  4. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128),
  5. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
  6. type css_pdt of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) or
  7. type css_type of default kind SK,
containing the values whose lexicographic minimum and maximum values are to be found.
Returns
minMaxVal : The output scalar of,
  1. type character of length 2 of the same kind as the input scalar array rank 0 of type character,
or otherwise, vector of shape (1:2) of the same type and kind (and length-type parameter) as the input array of rank 1, containing minval(array) in the first element and `maxval(array) in the second element.
  1. If the input array is a scalar of type character of arbitrary length-type parameter, then minMaxVal(1) will be set to the largest value for the corresponding character kind in the processor collating sequence.
  2. If the input array is a vector of size zero, then minMaxVal(1) will be set to the largest value for the kind of minMaxVal(1).
  3. If the input array is a vector of containers, then the val component of minMaxVal(1) will remain unallocated on output.
  1. If the input array is a scalar of type character of arbitrary length-type parameter, then minMaxVal(2) will be set to the smallest value for the corresponding character kind in the processor collating sequence.
  2. If the input array is a vector of size zero, then minMaxVal(2) will be set to the smallest value for the kind of minMaxVal(2).
  3. If the input array is a vector of containers, then the val component of minMaxVal(2) will remain unallocated on output.


Possible calling interfaces ⛓

minMaxVal(1:2) = getMinMaxVal(array) ! on output, minMaxVal(1) <= minMaxVal(2) holds.
!
Generate and return an array of size two containing the minimum and maximum values of a sequence of v...
This module contains procedures and generic interfaces for finding the minimum and maximum of two inp...
Remarks
The procedures under discussion are pure.
Note
The procedures under this generic interface are particularly useful in combination with procedures of pm_arrayMembership and similar interfaces.
See also
setMinMaxVal
pm_arrayMembership
pm_mathMinMax


Example usage ⛓

1program example
2
3 use pm_kind, only: SK, LK, IK
5 use pm_distUnif, only: getUnifRand
6 use pm_io, only: display_type
7
8 implicit none
9
10 type(display_type) :: disp
11 disp = display_type(file = SK_"main.out.F90")
12
13 call disp%skip()
14 call disp%show("!%%%%%%%%%%%%%%%%%")
15 call disp%show("!character scalar.")
16 call disp%show("!%%%%%%%%%%%%%%%%%")
17 call disp%skip()
18
19 block
20 use pm_kind, only: TKG => SK ! All kinds are supported.
21 character(:,TKG), allocatable :: array
22 character(1,TKG) :: minmax(2)
23 call disp%skip()
24 call disp%show("array = 'ParaMonte is a Machine Learning Library.'")
25 array = 'ParaMonte is a Machine Learning Library.'
26 call disp%show("array")
27 call disp%show( array , deliml = SK_"""" )
28 call disp%show("minmax = getMinMaxVal(array)")
29 minmax = getMinMaxVal(array)
30 call disp%show("minmax")
31 call disp%show( minmax , deliml = SK_"""" )
32 call disp%show("minmax = getMinMaxVal(array(1:0))")
33 minmax = getMinMaxVal(array(1:0))
34 call disp%show("minmax")
35 call disp%show( minmax , deliml = SK_"""" )
36 call disp%show("minmax(1) == char(0)")
37 call disp%show( minmax(1) == char(0) )
38 call disp%skip()
39 end block
40
41 call disp%skip()
42 call disp%show("!%%%%%%%%%%%%%%%%")
43 call disp%show("!character array.")
44 call disp%show("!%%%%%%%%%%%%%%%%")
45 call disp%skip()
46
47 block
48 use pm_kind, only: TKG => SK ! All kinds are supported.
49 character(10,TKG), allocatable :: array(:)
50 character(10,TKG) :: minmax(2)
51 call disp%skip()
52 call disp%show('array = [character(10,TKG) :: "ParaMonte", "is", "a", "Monte", "Carlo", "Library."]')
53 array = [character(10,TKG) :: "ParaMonte", "is", "a", "Monte", "Carlo", "Library."]
54 call disp%show("array")
55 call disp%show( array , deliml = SK_"""" )
56 call disp%show("minmax = getMinMaxVal(array)")
57 minmax = getMinMaxVal(array)
58 call disp%show("minmax")
59 call disp%show( minmax , deliml = SK_"""" )
60 call disp%show("minmax = getMinMaxVal(array(1:0))")
61 minmax = getMinMaxVal(array(1:0))
62 call disp%show("minmax")
63 call disp%show( minmax , deliml = SK_"""" )
64 call disp%skip()
65 end block
66
67 call disp%skip()
68 call disp%show("!%%%%%%%%%%%%%")
69 call disp%show("!string array.")
70 call disp%show("!%%%%%%%%%%%%%")
71 call disp%skip()
72
73 block
74 use pm_kind, only: TKG => SK ! All kinds are supported.
75 use pm_container, only: css_type
76 type(css_type), allocatable :: array(:)
77 type(css_type) :: minmax(2)
78 call disp%skip()
79 call disp%show('array = css_type([character(10,TKG) :: "ParaMonte", "is", "a", "Monte", "Carlo", "Library."])')
80 array = css_type([character(10,TKG) :: "ParaMonte", "is", "a", "Monte", "Carlo", "Library."])
81 call disp%show("array")
82 call disp%show( array , deliml = SK_"""" )
83 call disp%show("minmax = getMinMaxVal(array)")
84 minmax = getMinMaxVal(array)
85 call disp%show("minmax")
86 call disp%show( minmax , deliml = SK_"""" )
87 call disp%show("minmax = getMinMaxVal(array(1:0))")
88 minmax = getMinMaxVal(array(1:0))
89 call disp%show("[allocated(minmax(1)%val), allocated(minmax(2)%val)]")
90 call disp%show( [allocated(minmax(1)%val), allocated(minmax(2)%val)] )
91 call disp%skip()
92 end block
93
94 call disp%skip()
95 call disp%show("!%%%%%%%%%%%%%%")
96 call disp%show("!integer array.")
97 call disp%show("!%%%%%%%%%%%%%%")
98 call disp%skip()
99
100 block
101 use pm_kind, only: TKG => IK ! All kinds are supported.
102 integer(TKG), allocatable :: array(:)
103 integer(TKG) :: minmax(2)
104 call disp%skip()
105 call disp%show('array = getUnifRand(-9, 9, getUnifRand(3_IK, 9_IK))')
106 array = getUnifRand(-9, 9, getUnifRand(3_IK, 9_IK))
107 call disp%show("array")
108 call disp%show( array )
109 call disp%show("minmax = getMinMaxVal(array)")
110 minmax = getMinMaxVal(array)
111 call disp%show("minmax")
112 call disp%show( minmax )
113 call disp%show("minmax = getMinMaxVal(array(1:0))")
114 minmax = getMinMaxVal(array(1:0))
115 call disp%show("minmax")
116 call disp%show( minmax )
117 call disp%skip()
118 end block
119
120 call disp%skip()
121 call disp%show("!%%%%%%%%%%%%%%")
122 call disp%show("!logical array.")
123 call disp%show("!%%%%%%%%%%%%%%")
124 call disp%skip()
125
126 block
127 use pm_kind, only: TKG => LK ! All kinds are supported.
128 logical(TKG), allocatable :: array(:)
129 logical(TKG) :: minmax(2)
130 call disp%skip()
131 call disp%show('array = getUnifRand(.false., .true., getUnifRand(3_IK, 9_IK))')
132 array = getUnifRand(.false., .true., getUnifRand(3_IK, 9_IK))
133 call disp%show("array")
134 call disp%show( array )
135 call disp%show("minmax = getMinMaxVal(array)")
136 minmax = getMinMaxVal(array)
137 call disp%show("minmax")
138 call disp%show( minmax )
139 call disp%show("minmax = getMinMaxVal(array(1:0))")
140 minmax = getMinMaxVal(array(1:0))
141 call disp%show("minmax")
142 call disp%show( minmax )
143 call disp%skip()
144 end block
145
146 call disp%skip()
147 call disp%show("!%%%%%%%%%%%%%%")
148 call disp%show("!complex array.")
149 call disp%show("!%%%%%%%%%%%%%%")
150 call disp%skip()
151
152 block
153 use pm_kind, only: TKG => CKS ! All kinds are supported.
154 complex(TKG), allocatable :: array(:)
155 complex(TKG) :: minmax(2)
156 call disp%skip()
157 call disp%show('array = getUnifRand((-9., -9.), (9., 9.), getUnifRand(3_IK, 9_IK))')
158 array = getUnifRand((-9., -9.), (9., 9.), getUnifRand(3_IK, 9_IK))
159 call disp%show("array")
160 call disp%show( array )
161 call disp%show("minmax = getMinMaxVal(array)")
162 minmax = getMinMaxVal(array)
163 call disp%show("minmax")
164 call disp%show( minmax )
165 call disp%show("minmax = getMinMaxVal(array(1:0))")
166 minmax = getMinMaxVal(array(1:0))
167 call disp%show("minmax")
168 call disp%show( minmax )
169 call disp%skip()
170 end block
171
172 call disp%skip()
173 call disp%show("!%%%%%%%%%%%")
174 call disp%show("!real array.")
175 call disp%show("!%%%%%%%%%%%")
176 call disp%skip()
177
178 block
179 use pm_kind, only: TKG => RKS ! All kinds are supported.
180 real(TKG), allocatable :: array(:)
181 real(TKG) :: minmax(2)
182 call disp%skip()
183 call disp%show('array = getUnifRand(-9, 9, getUnifRand(3_IK, 9_IK))')
184 array = getUnifRand(-9, 9, getUnifRand(3_IK, 9_IK))
185 call disp%show("array")
186 call disp%show( array )
187 call disp%show("minmax = getMinMaxVal(array)")
188 minmax = getMinMaxVal(array)
189 call disp%show("minmax")
190 call disp%show( minmax )
191 call disp%show("minmax = getMinMaxVal(array(1:0))")
192 minmax = getMinMaxVal(array(1:0))
193 call disp%show("minmax")
194 call disp%show( minmax )
195 call disp%skip()
196 end block
197
198end program example
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
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 the derived types for generating allocatable containers of scalar,...
This module contains classes and procedures for computing various statistical quantities related to t...
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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
Definition: pm_kind.F90:570
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
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
This is the css_type type for generating instances of container of scalar of string objects.
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!character scalar.
4!%%%%%%%%%%%%%%%%%
5
6
7array = 'ParaMonte is a Machine Learning Library.'
8array
9"ParaMonte is a Machine Learning Library."
10minmax = getMinMaxVal(array)
11minmax
12" ", " "
13minmax = getMinMaxVal(array(1:0))
14minmax
15"ÿ", "ÿ"
16minmax(1) == char(0)
17F
18
19
20!%%%%%%%%%%%%%%%%
21!character array.
22!%%%%%%%%%%%%%%%%
23
24
25array = [character(10,TKG) :: "ParaMonte", "is", "a", "Monte", "Carlo", "Library."]
26array
27"ParaMonte ", "is ", "a ", "Monte ", "Carlo ", "Library. "
28minmax = getMinMaxVal(array)
29minmax
30"Carlo ", "is "
31minmax = getMinMaxVal(array(1:0))
32minmax
33ÿÿÿÿÿÿÿÿÿÿ"", " "
34
35
36!%%%%%%%%%%%%%
37!string array.
38!%%%%%%%%%%%%%
39
40
41array = css_type([character(10,TKG) :: "ParaMonte", "is", "a", "Monte", "Carlo", "Library."])
42array
43"ParaMonte", "is", "a", "Monte", "Carlo", "Library."
44minmax = getMinMaxVal(array)
45minmax
46"Carlo", "is"
47minmax = getMinMaxVal(array(1:0))
48[allocated(minmax(1)%val), allocated(minmax(2)%val)]
49F, F
50
51
52!%%%%%%%%%%%%%%
53!integer array.
54!%%%%%%%%%%%%%%
55
56
57array = getUnifRand(-9, 9, getUnifRand(3_IK, 9_IK))
58array
59+4, -3, -7, -1
60minmax = getMinMaxVal(array)
61minmax
62-7, +4
63minmax = getMinMaxVal(array(1:0))
64minmax
65+2147483647, -2147483647
66
67
68!%%%%%%%%%%%%%%
69!logical array.
70!%%%%%%%%%%%%%%
71
72
73array = getUnifRand(.false., .true., getUnifRand(3_IK, 9_IK))
74array
75F, F, F, T, T, F, T
76minmax = getMinMaxVal(array)
77minmax
78F, T
79minmax = getMinMaxVal(array(1:0))
80minmax
81T, F
82
83
84!%%%%%%%%%%%%%%
85!complex array.
86!%%%%%%%%%%%%%%
87
88
89array = getUnifRand((-9., -9.), (9., 9.), getUnifRand(3_IK, 9_IK))
90array
91(+8.96193886, -2.91395736), (-2.41250229, -7.57991982), (-0.420238495, +1.46303010), (-8.68968773, -5.05590630), (-2.15227008, -4.25682068), (-5.52193356, +0.241690636), (+3.23806024, +5.44772243)
92minmax = getMinMaxVal(array)
93minmax
94(-8.68968773, -5.05590630), (+8.96193886, -2.91395736)
95minmax = getMinMaxVal(array(1:0))
96minmax
97(+0.340282347E+39, +0.340282347E+39), (-0.340282347E+39, -0.340282347E+39)
98
99
100!%%%%%%%%%%%
101!real array.
102!%%%%%%%%%%%
103
104
105array = getUnifRand(-9, 9, getUnifRand(3_IK, 9_IK))
106array
107-6.00000000, +6.00000000, +3.00000000, +5.00000000, +7.00000000, +3.00000000
108minmax = getMinMaxVal(array)
109minmax
110-6.00000000, +7.00000000
111minmax = getMinMaxVal(array(1:0))
112minmax
113+0.340282347E+39, -0.340282347E+39
114
115
Test:
test_pm_arrayMinMax
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 130 of file pm_arrayMinMax.F90.


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