Line data Source code
1 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3 : !!!! !!!!
4 : !!!! ParaMonte: Parallel Monte Carlo and Machine Learning Library. !!!!
5 : !!!! !!!!
6 : !!!! Copyright (C) 2012-present, The Computational Data Science Lab !!!!
7 : !!!! !!!!
8 : !!!! This file is part of the ParaMonte library. !!!!
9 : !!!! !!!!
10 : !!!! LICENSE !!!!
11 : !!!! !!!!
12 : !!!! https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md !!!!
13 : !!!! !!!!
14 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16 :
17 : !> \brief
18 : !> This include file contains procedure implementations of [pm_arrayMinMax](@ref pm_arrayMinMax).
19 : !>
20 : !> \author
21 : !> \AmirShahmoradi, Sunday 3:33 AM, September 19, 2021, Dallas, TX
22 :
23 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 :
25 : ! DEfine the comparison operation.
26 : #if LK_ENABLED
27 : #define IS_MORE(a,b) a .and. .not. b
28 : #define IS_LESS(a,b) b .and. .not. a
29 : #elif CK_ENABLED
30 : #define IS_MORE(a,b) a%re > b%re .or. (a%re == b%re .and. a%im > b%im)
31 : #define IS_LESS(a,b) a%re < b%re .or. (a%re == b%re .and. a%im < b%im)
32 : #elif BSSK_ENABLED || PSSK_ENABLED
33 : #define IS_MORE(a,b) a%val > b%val
34 : #define IS_LESS(a,b) a%val < b%val
35 : #else
36 : #define IS_MORE(a,b) a > b
37 : #define IS_LESS(a,b) a < b
38 : #endif
39 : !%%%%%%%%%%%%%%%%%%%
40 : #if getMinMaxVal_ENABLED
41 : !%%%%%%%%%%%%%%%%%%%
42 :
43 : #if SK_ENABLED && D0_ENABLED
44 2 : call setMinMaxVal(array, minMaxVal(1:1), minMaxVal(2:2))
45 : #else
46 12 : call setMinMaxVal(array, minMaxVal(1), minMaxVal(2))
47 : #endif
48 :
49 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 : #elif setMinMaxVal_ENABLED && D0_ENABLED && SK_ENABLED
51 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 :
53 : integer(IK) :: iell
54 : character(1,SKC), allocatable :: empty(:)
55 4 : allocate(empty(0))
56 4 : vmin = minval(empty)
57 4 : vmax = maxval(empty)
58 84 : do iell = 1, len(array, IK)
59 80 : if (IS_MORE(vmin, array(iell : iell))) vmin = array(iell : iell)
60 84 : if (IS_LESS(vmax, array(iell : iell))) vmax = array(iell : iell)
61 : end do
62 4 : deallocate(empty)
63 :
64 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 : #elif setMinMaxVal_ENABLED && D1_ENABLED
66 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 :
68 : integer(IK) :: iell
69 : #if BSSK_ENABLED || PSSK_ENABLED
70 4 : if (size(array, 1, IK) == 0_IK) return
71 2 : vmin = array(1)
72 2 : vmax = array(1)
73 : #elif SK_ENABLED
74 4 : character(len(vmin, IK),SKC), allocatable :: empty(:)
75 4 : if (allocated(empty)) deallocate(empty)
76 4 : allocate(empty(0))
77 4 : vmin = minval(empty)
78 4 : vmax = maxval(empty)
79 : #elif IK_ENABLED
80 4 : vmin = +huge(0_IKC)
81 4 : vmax = -huge(0_IKC)
82 : #elif LK_ENABLED
83 4 : vmin = .true._LKC
84 4 : vmax = .false._LKC
85 : #elif CK_ENABLED
86 : complex(CKC), parameter :: POSINF = cmplx(+huge(0._CKC), +huge(0._CKC), CKC)
87 : complex(CKC), parameter :: NEGINF = cmplx(-huge(0._CKC), -huge(0._CKC), CKC)
88 4 : vmin = POSINF
89 4 : vmax = NEGINF
90 : #elif RK_ENABLED
91 4 : vmin = +huge(0._RKC)
92 4 : vmax = -huge(0._RKC)
93 : #else
94 : #error "Unrecognized interface."
95 : #endif
96 99 : do iell = 1, size(array, 1, IK)
97 77 : if (IS_MORE(vmin, array(iell))) vmin = array(iell)
98 99 : if (IS_LESS(vmax, array(iell))) vmax = array(iell)
99 : end do
100 :
101 : #else
102 : !%%%%%%%%%%%%%%%%%%%%%%%%
103 : #error "Unrecognized interface."
104 : !%%%%%%%%%%%%%%%%%%%%%%%%
105 : #endif
106 : #undef IS_MORE
107 : #undef IS_LESS
|