1 // =============================================================================
2 // === spqr_cumsum =============================================================
3 // =============================================================================
4
5 #include "spqr.hpp"
6
7 // Overwrite a vector of length n with its cumulative sum of length n+1.
8 // On input, X [0:n-1] contains the counts. On output, X [k] is replaced with
9 // the sum of the input counts X [0:k-1]. No work is done if n < 0 or if
10 // X is NULL. Long overflow is not checked (SuiteSparseQR doesn't need it;
11 // it has already been checked whereever this function is used).
12
spqr_cumsum(Long n,Long * X)13 Long spqr_cumsum
14 (
15 // input, not modified
16 Long n,
17
18 // input/output
19 Long *X // size n+1. X = cumsum ([0 X])
20 )
21 {
22 Long itot, t, x, k ;
23
24 // -------------------------------------------------------------------------
25 // X = cumsum ([0 X])
26 // -------------------------------------------------------------------------
27
28 itot = 0 ;
29 if (X != NULL)
30 {
31 for (k = 0 ; k < n ; k++)
32 {
33 t = itot ; // t = sum (X [0:k-1])
34 x = X [k] ;
35 itot += x ;
36 X [k] = t ;
37 }
38 X [n] = itot ;
39 }
40
41 return (itot) ;
42 }
43