File: cs_cumsum.c

package info (click to toggle)
suitesparse 1%3A3.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,788 kB
  • sloc: ansic: 106,134; cpp: 13,129; makefile: 6,679; fortran: 4,591; csh: 763; ruby: 603; perl: 236; sed: 164; awk: 29; sh: 8
file content (17 lines) | stat: -rw-r--r-- 564 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "cs.h"
/* p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c */
double cs_cumsum (int *p, int *c, int n)
{
    int i, nz = 0 ;
    double nz2 = 0 ;
    if (!p || !c) return (-1) ;     /* check inputs */
    for (i = 0 ; i < n ; i++)
    {
        p [i] = nz ;
        nz += c [i] ;
        nz2 += c [i] ;              /* also in double to avoid int overflow */
        c [i] = p [i] ;             /* also copy p[0..n-1] back into c[0..n-1]*/
    }
    p [n] = nz ;
    return (nz2) ;                  /* return sum (c [0..n-1]) */
}