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 implementation of [pm_mathCumSum](@ref pm_mathCumSum).
19 : !>
20 : !> \finmain
21 : !>
22 : !> \author
23 : !> \AmirShahmoradi, Sunday 3:33 AM, September 19, 2021, Dallas, TX
24 :
25 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 :
27 : !%%%%%%%%%%%%%%%%
28 : #if getCumSum_ENABLED
29 : !%%%%%%%%%%%%%%%%
30 :
31 11830 : if (0_IK < size(array, 1, IK)) then
32 11830 : if (present(direction) .and. present(action)) then
33 8704 : if (same_type_as(direction, forward)) then
34 4331 : if (same_type_as(action, nothing)) then
35 2168 : call setCumSum(cumsum, array, forward, nothing)
36 2163 : elseif (same_type_as(action, reverse)) then
37 2163 : call setCumSum(cumsum, array, forward, reverse)
38 : else
39 0 : error stop "@getCumSum(): Unrecognized action."
40 : end if
41 4373 : elseif (same_type_as(direction, backward)) then
42 4373 : if (same_type_as(action, nothing)) then
43 2117 : call setCumSum(cumsum, array, backward, nothing)
44 2256 : elseif (same_type_as(action, reverse)) then
45 2256 : call setCumSum(cumsum, array, backward, reverse)
46 : else
47 0 : error stop "@getCumSum(): Unrecognized action."
48 : end if
49 : else
50 0 : error stop "@getCumSum(): Unrecognized direction."
51 : end if
52 3126 : elseif (present(direction)) then
53 941 : if (same_type_as(direction, forward)) then
54 0 : call setCumSum(cumsum, array, forward, nothing)
55 941 : elseif (same_type_as(direction, backward)) then
56 941 : call setCumSum(cumsum, array, backward, nothing)
57 : else
58 0 : error stop "@getCumSum(): Unrecognized direction."
59 : end if
60 2185 : elseif (present(action)) then
61 994 : if (same_type_as(action, nothing)) then
62 0 : call setCumSum(cumsum, array, forward, nothing)
63 994 : elseif (same_type_as(action, reverse)) then
64 994 : call setCumSum(cumsum, array, forward, reverse)
65 : else
66 0 : error stop "@getCumSum(): Unrecognized action."
67 : end if
68 : else
69 1191 : call setCumSum(cumsum, array)
70 : end if
71 : end if
72 :
73 : !%%%%%%%%%%%%%%%%
74 : #elif setCumSum_ENABLED
75 : !%%%%%%%%%%%%%%%%
76 :
77 : #if New_ENABLED || (For_ENABLED && Non_ENABLED) || (Bac_ENABLED && Rev_ENABLED)
78 : integer(IK) :: i
79 : #endif
80 : integer(IK) :: lenArray
81 34732 : lenArray = size(array, kind = IK)
82 34732 : CHECK_ASSERTION(__LINE__, 0_IK < lenArray, SK_"@setCumSum(): The condition `0 < size(array)` must hold. size(array) = "//getStr(lenArray))
83 : #if Old_ENABLED && For_ENABLED && Non_ENABLED
84 72151 : do i = 2, lenArray
85 72151 : array(i) = array(i - 1) + array(i)
86 : end do
87 : #elif Old_ENABLED && For_ENABLED && Rev_ENABLED
88 478 : call setCumSum(array)
89 478 : call setReversed(array)
90 : #elif Old_ENABLED && Bac_ENABLED && Non_ENABLED
91 478 : call setReversed(array)
92 478 : call setCumSum(array)
93 : #elif Old_ENABLED && Bac_ENABLED && Rev_ENABLED
94 12 : do i = lenArray - 1, 1, -1
95 12 : array(i) = array(i + 1) + array(i)
96 : end do
97 : #elif New_ENABLED
98 43176 : CHECK_ASSERTION(__LINE__, lenArray == size(cumsum, 1, IK), SK_"@setCumSum(): The condition `size(array, 1, IK) == size(cumsum, 1, IK)` must hold. size(array), size(cumsum) = "//getStr([lenArray, size(cumsum, 1, IK)]))
99 : #if For_ENABLED && Non_ENABLED
100 3932 : cumsum(1) = array(1)
101 436717 : do i = 2, lenArray
102 436717 : cumsum(i) = cumsum(i - 1) + array(i)
103 : end do
104 : #elif For_ENABLED && Rev_ENABLED
105 3615 : cumsum(lenArray) = array(1)
106 19963 : do i = 2, lenArray
107 19963 : cumsum(lenArray - i + 1) = cumsum(lenArray - i + 2) + array(i)
108 : end do
109 : #elif Bac_ENABLED && Non_ENABLED
110 3588 : cumsum(1) = array(lenArray)
111 19778 : do i = 2, lenArray
112 19778 : cumsum(i) = cumsum(i - 1) + array(lenArray - i + 1)
113 : end do
114 : #elif Bac_ENABLED && Rev_ENABLED
115 3257 : cumsum(lenArray) = array(lenArray)
116 17602 : do i = lenArray - 1, 1, -1
117 17602 : cumsum(i) = cumsum(i + 1) + array(i)
118 : end do
119 : #else
120 : #error "Unrecognized interface."
121 : #endif
122 : #endif
123 :
124 : #else
125 : !%%%%%%%%%%%%%%%%%%%%%%%%
126 : #error "Unrecognized interface."
127 : !%%%%%%%%%%%%%%%%%%%%%%%%
128 : #endif
|