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

Return the minimum and maximum values of the input sequence.
More...

Detailed Description

Return the minimum and maximum values of the input sequence.

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.
[out]vmin: The output scalar of,
  1. type character of length 1 of the same kind as the input scalar array rank 0 of type character,
or otherwise, of the same type and kind (and length-type parameter) as the input array of rank 1, containing the minimum value in the sequence.
  1. If the input array is a scalar of type character of arbitrary length-type parameter, then vmin 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 vmin will be set to the largest value for the kind of vmin.
  3. If the input array is a vector of containers, then the val component of vmin will remain unallocated on output.
[out]vmax: The output scalar of,
  1. type character of length 1 of the same kind as the input scalar array rank 0 of type character,
or otherwise, of the same type and kind (and length-type parameter) as the input array of rank 1, containing the maximum value in the sequence.
  1. If the input array is a scalar of type character of arbitrary length-type parameter, then vmax 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 vmax will be set to the smallest value for the kind of vmax.
  3. If the input array is a vector of containers, then the val component of vmax will remain unallocated on output.


Possible calling interfaces ⛓

call setMinMaxVal(array, vmin, vmax)
!
Return the minimum and maximum values of the input sequence.
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) :: vmin, vmax
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("call setMinMaxVal(array, vmin, vmax)")
29 call setMinMaxVal(array, vmin, vmax)
30 call disp%show("[vmin, vmax]")
31 call disp%show( [vmin, vmax] , deliml = SK_"""" )
32 call disp%show("call setMinMaxVal(array(1:0), vmin, vmax)")
33 call setMinMaxVal(array(1:0), vmin, vmax)
34 call disp%show("[vmin, vmax]")
35 call disp%show( [vmin, vmax] , deliml = SK_"""" )
36 call disp%show("vmin == char(0)")
37 call disp%show( vmin == 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) :: vmin, vmax
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("call setMinMaxVal(array, vmin, vmax)")
57 call setMinMaxVal(array, vmin, vmax)
58 call disp%show("[vmin, vmax]")
59 call disp%show( [vmin, vmax] , deliml = SK_"""" )
60 call disp%show("call setMinMaxVal(array(1:0), vmin, vmax)")
61 call setMinMaxVal(array(1:0), vmin, vmax)
62 call disp%show("[vmin, vmax]")
63 call disp%show( [vmin, vmax] , 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) :: vmin, vmax
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("call setMinMaxVal(array, vmin, vmax)")
84 call setMinMaxVal(array, vmin, vmax)
85 call disp%show("[vmin, vmax]")
86 call disp%show( [vmin, vmax] , deliml = SK_"""" )
87 call disp%show("call setMinMaxVal(array(1:0), vmin, vmax)")
88 call setMinMaxVal(array(1:0), vmin, vmax)
89 call disp%show("[allocated(vmin%val), allocated(vmax%val)]")
90 call disp%show( [allocated(vmin%val), allocated(vmax%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) :: vmin, vmax
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("call setMinMaxVal(array, vmin, vmax)")
110 call setMinMaxVal(array, vmin, vmax)
111 call disp%show("[vmin, vmax]")
112 call disp%show( [vmin, vmax] )
113 call disp%show("call setMinMaxVal(array(1:0), vmin, vmax)")
114 call setMinMaxVal(array(1:0), vmin, vmax)
115 call disp%show("[vmin, vmax]")
116 call disp%show( [vmin, vmax] )
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) :: vmin, vmax
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("call setMinMaxVal(array, vmin, vmax)")
136 call setMinMaxVal(array, vmin, vmax)
137 call disp%show("[vmin, vmax]")
138 call disp%show( [vmin, vmax] )
139 call disp%show("call setMinMaxVal(array(1:0), vmin, vmax)")
140 call setMinMaxVal(array(1:0), vmin, vmax)
141 call disp%show("[vmin, vmax]")
142 call disp%show( [vmin, vmax] )
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) :: vmin, vmax
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("call setMinMaxVal(array, vmin, vmax)")
162 call setMinMaxVal(array, vmin, vmax)
163 call disp%show("[vmin, vmax]")
164 call disp%show( [vmin, vmax] )
165 call disp%show("call setMinMaxVal(array(1:0), vmin, vmax)")
166 call setMinMaxVal(array(1:0), vmin, vmax)
167 call disp%show("[vmin, vmax]")
168 call disp%show( [vmin, vmax] )
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) :: vmin, vmax
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("call setMinMaxVal(array, vmin, vmax)")
188 call setMinMaxVal(array, vmin, vmax)
189 call disp%show("[vmin, vmax]")
190 call disp%show( [vmin, vmax] )
191 call disp%show("call setMinMaxVal(array(1:0), vmin, vmax)")
192 call setMinMaxVal(array(1:0), vmin, vmax)
193 call disp%show("[vmin, vmax]")
194 call disp%show( [vmin, vmax] )
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."
10call setMinMaxVal(array, vmin, vmax)
11[vmin, vmax]
12" ", "y"
13call setMinMaxVal(array(1:0), vmin, vmax)
14[vmin, vmax]
15"ÿ", " "
16vmin == 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. "
28call setMinMaxVal(array, vmin, vmax)
29[vmin, vmax]
30"Carlo ", "is "
31call setMinMaxVal(array(1:0), vmin, vmax)
32[vmin, vmax]
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."
44call setMinMaxVal(array, vmin, vmax)
45[vmin, vmax]
46"Carlo", "is"
47call setMinMaxVal(array(1:0), vmin, vmax)
48[allocated(vmin%val), allocated(vmax%val)]
49F, F
50
51
52!%%%%%%%%%%%%%%
53!integer array.
54!%%%%%%%%%%%%%%
55
56
57array = getUnifRand(-9, 9, getUnifRand(3_IK, 9_IK))
58array
59-9, -4, -9
60call setMinMaxVal(array, vmin, vmax)
61[vmin, vmax]
62-9, -4
63call setMinMaxVal(array(1:0), vmin, vmax)
64[vmin, vmax]
65+2147483647, -2147483647
66
67
68!%%%%%%%%%%%%%%
69!logical array.
70!%%%%%%%%%%%%%%
71
72
73array = getUnifRand(.false., .true., getUnifRand(3_IK, 9_IK))
74array
75T, F, T, F, F, T, F
76call setMinMaxVal(array, vmin, vmax)
77[vmin, vmax]
78F, T
79call setMinMaxVal(array(1:0), vmin, vmax)
80[vmin, vmax]
81T, F
82
83
84!%%%%%%%%%%%%%%
85!complex array.
86!%%%%%%%%%%%%%%
87
88
89array = getUnifRand((-9., -9.), (9., 9.), getUnifRand(3_IK, 9_IK))
90array
91(-7.89765787, -7.07636404), (+4.89765739, -7.86429787), (+1.15255356, -2.98675895)
92call setMinMaxVal(array, vmin, vmax)
93[vmin, vmax]
94(-7.89765787, -7.07636404), (+4.89765739, -7.86429787)
95call setMinMaxVal(array(1:0), vmin, vmax)
96[vmin, vmax]
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+3.00000000, -6.00000000, +6.00000000, -6.00000000, -3.00000000, -4.00000000
108call setMinMaxVal(array, vmin, vmax)
109[vmin, vmax]
110-6.00000000, +6.00000000
111call setMinMaxVal(array(1:0), vmin, vmax)
112[vmin, vmax]
113+0.340282347E+39, -0.340282347E+39
114
115
Test:
test_pm_arrayMinMax
Bug:

Status: Unresolved
Source: Intel Classic Fortran Compiler ifort version 2021.8.0 20221119, Intel LLVM Fortran Compiler ifx version 2023.0.0 20221201
Description: The Intel Classic Fortran Compiler ifort and Intel LLVM Fortran Compiler ifx as of the specified versions above cannot find the minimum and maximum of a constant empty array of type character.
This has prevented the definition of the constants COL_SEQ_BEG and COL_SEQ_END in the module pm_str which are also needed in this module.
For example, the following code yields an Internal Compiler Error:
character(1), parameter :: ARRAY_EMPTY(0) = [character(1)::]
character(*), parameter :: COL_SEQ_BEG = minval(ARRAY_EMPTY,1)
end
      catastrophic error: **Internal compiler error: segmentation violation signal raised**
      Please report this error along with the circumstances in which it occurred in a Software Problem Report.
      Note: File and line given may not be explicit cause of this error.


Remedy (as of ParaMonte Library version 2.0.0): For now, the empty arrays are constructed dynamically within the routines of this module.

Todo:
Critical Priority: The dynamic character allocation due to the bug described above must be eliminated within the implementation of this module as soon as the Intel compilers bugs are resolved.
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 682 of file pm_arrayMinMax.F90.


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