cs_cumsum.c
Go to the documentation of this file.
1 #include "cs.h"
2 /* p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c */
3 double cs_cumsum (int *p, int *c, int n)
4 {
5  int i, nz = 0 ;
6  double nz2 = 0 ;
7  if (!p || !c) return (-1) ; /* check inputs */
8  for (i = 0 ; i < n ; i++)
9  {
10  p [i] = nz ;
11  nz += c [i] ;
12  nz2 += c [i] ; /* also in double to avoid int overflow */
13  c [i] = p [i] ; /* also copy p[0..n-1] back into c[0..n-1]*/
14  }
15  p [n] = nz ;
16  return (nz2) ; /* return sum (c [0..n-1]) */
17 }
double cs_cumsum(int *p, int *c, int n)
Definition: cs_cumsum.c:3


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:31