Generate and return the cumulative sum of the input array, optionally in the backward direction and, optionally reverse the output cumulative sum array upon return.
More...
Generate and return the cumulative sum of the input array, optionally in the backward direction and, optionally reverse the output cumulative sum array upon return.
- Parameters
-
[in] | array | : The input contiguous array of shape (:) of either,
-
type
integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or,
-
type
complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or,
-
type
real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
whose cumulative sum will have to be computed. |
[in] | direction | : The input scalar object that can be,
-
the constant forward or equivalently, an object of type forward_type, implying that the output cumulative sum has be computed from the first element to the last element of the input
array .
even though the increments will still be written from the first element of cumsum to the last.
-
the constant backward or equivalently, an object of type backward_type, implying that the output cumulative sum has be computed from the last element to the first element of the input
array even though the increments will still be written from the first element of cumsum to the last.
(optional, default = forward) |
[in] | action | : The input scalar object that can be,
-
the constant nothing or equivalently, an object of type nothing_type, implying no action to be performed on the elements of the output
cumsum .
-
the constant reverse or equivalently, an object of type reverse_type, implying that the order of the elements of the output
cumsum will have be reversed upon return, such that its last element becomes the first.
(optional, default = nothing) |
- Returns
cumsum
: The output array of the same size, shape, type, and kind as the input array
containing the cumulative sum of array
in the specified direction.
Possible calling interfaces ⛓
cumsum(:)
= getCumSum(array(:), direction
= direction,
action = action)
Generate and return the cumulative sum of the input array, optionally in the backward direction and,...
This module contains the procedures and interfaces for computing the cumulative sum of an array.
- Warning
- The
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.
By default, these procedures are pure
in release
build and impure
in debug
and testing
builds.
- See also
- setCumSum
getCumPropExp
setCumPropExp
Example usage ⛓
9 type(display_type) :: disp
15 integer(IKG),
allocatable :: array(:)
17 call disp%show(
"array = [1, 2, 3, 4]")
21 call disp%show(
"getCumSum(array, action = reverse)")
23 call disp%show(
"getCumSum(array, direction = backward)")
25 call disp%show(
"getCumSum(array, direction = backward, action = reverse)")
32 complex(CKG),
allocatable :: array(:)
34 call disp%show(
"array = cmplx([real(CKG) :: 1, 2, 3, 4], -[real(CKG) :: 1, 2, 3, 4], CKG)")
35 array
= cmplx([
real(CKG) ::
1,
2,
3,
4],
-[
real(CKG) ::
1,
2,
3,
4], CKG)
38 call disp%show(
"getCumSum(array, action = reverse)")
40 call disp%show(
"getCumSum(array, direction = backward)")
42 call disp%show(
"getCumSum(array, direction = backward, action = reverse)")
49 real(RKG),
allocatable :: array(:)
51 call disp%show(
"array = [1, 2, 3, 4]")
55 call disp%show(
"getCumSum(array, action = reverse)")
57 call disp%show(
"getCumSum(array, direction = backward)")
59 call disp%show(
"getCumSum(array, direction = backward, action = reverse)")
66 real(RKG),
allocatable :: array(:)
68 call disp%show(
"array = [1, 2, 3, 4]")
72 call disp%show(
"getCumSum(array, action = reverse)")
74 call disp%show(
"getCumSum(array, direction = backward)")
76 call disp%show(
"getCumSum(array, direction = backward, action = reverse)")
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
9getCumSum(array, direction
= backward,
action = reverse)
13array
= cmplx([
real(CKG) ::
1,
2,
3,
4],
-[
real(CKG) ::
1,
2,
3,
4], CKG)
15(
+1.00000000,
-1.00000000), (
+3.00000000,
-3.00000000), (
+6.00000000,
-6.00000000), (
+10.0000000,
-10.0000000)
17(
+10.0000000,
-10.0000000), (
+6.00000000,
-6.00000000), (
+3.00000000,
-3.00000000), (
+1.00000000,
-1.00000000)
19(
+4.00000000,
-4.00000000), (
+7.00000000,
-7.00000000), (
+9.00000000,
-9.00000000), (
+10.0000000,
-10.0000000)
20getCumSum(array, direction
= backward,
action = reverse)
21(
+10.0000000,
-10.0000000), (
+9.00000000,
-9.00000000), (
+7.00000000,
-7.00000000), (
+4.00000000,
-4.00000000)
26+1.00000000,
+3.00000000,
+6.00000000,
+10.0000000
28+10.0000000,
+6.00000000,
+3.00000000,
+1.00000000
30+4.00000000,
+7.00000000,
+9.00000000,
+10.0000000
31getCumSum(array, direction
= backward,
action = reverse)
32+10.0000000,
+9.00000000,
+7.00000000,
+4.00000000
37+1.00000000000000000000000000000000000,
+3.00000000000000000000000000000000000,
+6.00000000000000000000000000000000000,
+10.0000000000000000000000000000000000
39+10.0000000000000000000000000000000000,
+6.00000000000000000000000000000000000,
+3.00000000000000000000000000000000000,
+1.00000000000000000000000000000000000
41+4.00000000000000000000000000000000000,
+7.00000000000000000000000000000000000,
+9.00000000000000000000000000000000000,
+10.0000000000000000000000000000000000
42getCumSum(array, direction
= backward,
action = reverse)
43+10.0000000000000000000000000000000000,
+9.00000000000000000000000000000000000,
+7.00000000000000000000000000000000000,
+4.00000000000000000000000000000000000
- Test:
- test_pm_mathCumSum
- Todo:
- Normal Priority: This generic interface can be expanded to include input arrays with
Weight
s.
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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Fatemeh Bagheri, Tuesday 08:49 PM, August 10, 2021, Dallas, TX
Definition at line 129 of file pm_mathCumSum.F90.