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

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...

Detailed Description

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,
  1. 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.
  2. 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,
  1. the constant nothing or equivalently, an object of type nothing_type, implying no action to be performed on the elements of the output cumsum.
  2. 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

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_io, only: display_type
5 use pm_mathCumSum, only: getCumSum, forward, backward, nothing, reverse
6
7 implicit none
8
9 type(display_type) :: disp
10
11 disp = display_type(file = "main.out.F90")
12
13 block
14 use pm_kind, only: IKG => IK
15 integer(IKG), allocatable :: array(:)
16 call disp%skip
17 call disp%show("array = [1, 2, 3, 4]")
18 array = [1, 2, 3, 4]
19 call disp%show("getCumSum(array)")
20 call disp%show( getCumSum(array) )
21 call disp%show("getCumSum(array, action = reverse)")
22 call disp%show( getCumSum(array, action = reverse) )
23 call disp%show("getCumSum(array, direction = backward)")
24 call disp%show( getCumSum(array, direction = backward) )
25 call disp%show("getCumSum(array, direction = backward, action = reverse)")
26 call disp%show( getCumSum(array, direction = backward, action = reverse) )
27 call disp%skip
28 end block
29
30 block
31 use pm_kind, only: CKG => CKS
32 complex(CKG), allocatable :: array(:)
33 call disp%skip
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)
36 call disp%show("getCumSum(array)")
37 call disp%show( getCumSum(array) )
38 call disp%show("getCumSum(array, action = reverse)")
39 call disp%show( getCumSum(array, action = reverse) )
40 call disp%show("getCumSum(array, direction = backward)")
41 call disp%show( getCumSum(array, direction = backward) )
42 call disp%show("getCumSum(array, direction = backward, action = reverse)")
43 call disp%show( getCumSum(array, direction = backward, action = reverse) )
44 call disp%skip
45 end block
46
47 block
48 use pm_kind, only: RKG => RKS
49 real(RKG), allocatable :: array(:)
50 call disp%skip
51 call disp%show("array = [1, 2, 3, 4]")
52 array = [1, 2, 3, 4]
53 call disp%show("getCumSum(array)")
54 call disp%show( getCumSum(array) )
55 call disp%show("getCumSum(array, action = reverse)")
56 call disp%show( getCumSum(array, action = reverse) )
57 call disp%show("getCumSum(array, direction = backward)")
58 call disp%show( getCumSum(array, direction = backward) )
59 call disp%show("getCumSum(array, direction = backward, action = reverse)")
60 call disp%show( getCumSum(array, direction = backward, action = reverse) )
61 call disp%skip
62 end block
63
64 block
65 use pm_kind, only: RKG => RKH
66 real(RKG), allocatable :: array(:)
67 call disp%skip
68 call disp%show("array = [1, 2, 3, 4]")
69 array = [1, 2, 3, 4]
70 call disp%show("getCumSum(array)")
71 call disp%show( getCumSum(array) )
72 call disp%show("getCumSum(array, action = reverse)")
73 call disp%show( getCumSum(array, action = reverse) )
74 call disp%show("getCumSum(array, direction = backward)")
75 call disp%show( getCumSum(array, direction = backward) )
76 call disp%show("getCumSum(array, direction = backward, action = reverse)")
77 call disp%show( getCumSum(array, direction = backward, action = reverse) )
78 call disp%skip
79 end block
80
81end program example
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 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 RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
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
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
2array = [1, 2, 3, 4]
3getCumSum(array)
4+1, +3, +6, +10
5getCumSum(array, action = reverse)
6+10, +6, +3, +1
7getCumSum(array, direction = backward)
8+4, +7, +9, +10
9getCumSum(array, direction = backward, action = reverse)
10+10, +9, +7, +4
11
12
13array = cmplx([real(CKG) :: 1, 2, 3, 4], -[real(CKG) :: 1, 2, 3, 4], CKG)
14getCumSum(array)
15(+1.00000000, -1.00000000), (+3.00000000, -3.00000000), (+6.00000000, -6.00000000), (+10.0000000, -10.0000000)
16getCumSum(array, action = reverse)
17(+10.0000000, -10.0000000), (+6.00000000, -6.00000000), (+3.00000000, -3.00000000), (+1.00000000, -1.00000000)
18getCumSum(array, direction = backward)
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)
22
23
24array = [1, 2, 3, 4]
25getCumSum(array)
26+1.00000000, +3.00000000, +6.00000000, +10.0000000
27getCumSum(array, action = reverse)
28+10.0000000, +6.00000000, +3.00000000, +1.00000000
29getCumSum(array, direction = backward)
30+4.00000000, +7.00000000, +9.00000000, +10.0000000
31getCumSum(array, direction = backward, action = reverse)
32+10.0000000, +9.00000000, +7.00000000, +4.00000000
33
34
35array = [1, 2, 3, 4]
36getCumSum(array)
37+1.00000000000000000000000000000000000, +3.00000000000000000000000000000000000, +6.00000000000000000000000000000000000, +10.0000000000000000000000000000000000
38getCumSum(array, action = reverse)
39+10.0000000000000000000000000000000000, +6.00000000000000000000000000000000000, +3.00000000000000000000000000000000000, +1.00000000000000000000000000000000000
40getCumSum(array, direction = backward)
41+4.00000000000000000000000000000000000, +7.00000000000000000000000000000000000, +9.00000000000000000000000000000000000, +10.0000000000000000000000000000000000
42getCumSum(array, direction = backward, action = reverse)
43+10.0000000000000000000000000000000000, +9.00000000000000000000000000000000000, +7.00000000000000000000000000000000000, +4.00000000000000000000000000000000000
44
45
Test:
test_pm_mathCumSum
Todo:
Normal Priority: This generic interface can be expanded to include input arrays with Weights.


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:
Fatemeh Bagheri, Tuesday 08:49 PM, August 10, 2021, Dallas, TX

Definition at line 129 of file pm_mathCumSum.F90.


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