This function is introduced to capture a common routine for * traversing a SparseData, transforming each element as we go along and * summing up the transformed elements. The method is non-destructive to * the input SparseData. */
| 972 | * the input SparseData. |
| 973 | */ |
| 974 | double |
| 975 | accum_sdata_values_double(SparseData sdata, double (*func)(double)) |
| 976 | { |
| 977 | double accum=0.; |
| 978 | char *ix = sdata->index->data; |
| 979 | double *vals = (double *)sdata->vals->data; |
| 980 | int64 run_length; |
| 981 | |
| 982 | for (int i=0;i<sdata->unique_value_count;i++) |
| 983 | { |
| 984 | run_length = compword_to_int8(ix); |
| 985 | accum += func(vals[i])*run_length; |
| 986 | ix+=int8compstoragesize(ix); |
| 987 | } |
| 988 | return (accum); |
| 989 | } |
| 990 | |
| 991 | /* Computes the running sum of the elements of a SparseData */ |
| 992 | double sum_sdata_values_double(SparseData sdata) { |
no test coverage detected