vendor/scs/src/linalg.c in scs-0.3.1 vs vendor/scs/src/linalg.c in scs-0.3.2

- old
+ new

@@ -81,23 +81,40 @@ for (i = 0; i < n; ++i) { a[i] += sc * b[i]; } } +scs_float SCS(mean)(const scs_float *x, scs_int n) { + scs_int i; + scs_float mean = 0.; + for (i = 0; i < n; ++i) { + mean += x[i]; + } + return mean / n; +} + #else /* If we have BLAS / LAPACK we may as well use them */ +#ifdef __cplusplus +extern "C" { +#endif + scs_float BLAS(nrm2)(blas_int *n, const scs_float *x, blas_int *incx); scs_float BLAS(dot)(const blas_int *n, const scs_float *x, const blas_int *incx, const scs_float *y, const blas_int *incy); scs_float BLAS(lange)(const char *norm, const blas_int *m, const blas_int *n, const scs_float *a, blas_int *lda, scs_float *work); void BLAS(axpy)(blas_int *n, const scs_float *a, const scs_float *x, blas_int *incx, scs_float *y, blas_int *incy); void BLAS(scal)(const blas_int *n, const scs_float *sa, scs_float *sx, const blas_int *incx); +#ifdef __cplusplus +} +#endif + /* a *= b */ void SCS(scale_array)(scs_float *a, const scs_float b, scs_int len) { blas_int bone = 1; blas_int blen = (blas_int)len; BLAS(scal)(&blen, &b, a, &bone); @@ -133,8 +150,16 @@ void SCS(add_scaled_array)(scs_float *a, const scs_float *b, scs_int len, const scs_float sc) { blas_int bone = 1; blas_int blen = (blas_int)len; BLAS(axpy)(&blen, &sc, b, &bone, a, &bone); +} + +scs_float SCS(mean)(const scs_float *x, scs_int n) { + blas_int bone = 1; + blas_int bzero = 0; + blas_int blen = (blas_int)n; + scs_float y = 1.0; + return BLAS(dot)(&blen, x, &bone, &y, &bzero) / n; } #endif