This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/vendor/github.com/montanaflynn/stats/cumulative_sum.go
Pradyumna Kaushik bac60e872a Unit testing for def/ module.
Added unit tests to test code in def/ module.
2019-10-12 06:48:45 +00:00

21 lines
380 B
Go

package stats
// CumulativeSum calculates the cumulative sum of the input slice
func CumulativeSum(input Float64Data) ([]float64, error) {
if input.Len() == 0 {
return Float64Data{}, EmptyInput
}
cumSum := make([]float64, input.Len())
for i, val := range input {
if i == 0 {
cumSum[i] = val
} else {
cumSum[i] = cumSum[i-1] + val
}
}
return cumSum, nil
}