MyraMath
myramath
utility
cumsum.h
Go to the documentation of this file.
1
// ========================================================================= //
2
// This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3
// and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4
// ========================================================================= //
5
6
#ifndef MYRAMATH_UTILITY_CUMSUM_H
7
#define MYRAMATH_UTILITY_CUMSUM_H
8
14
#include <vector>
15
16
namespace
myra
{
17
19
template
<
class
T> std::vector<T>
cumsum
(
const
std::vector<T>& v)
20
{
21
std::vector<T> answer(v.size()+1,0);
22
for
(std::size_t i = 0; i < v.size(); ++i)
23
answer[i+1] = answer[i] + v[i];
24
return
answer;
25
}
26
27
}
// namespace myra
28
29
#endif
myra::cumsum
std::vector< T > cumsum(const std::vector< T > &v)
Returns cumulative sum. For example, cumsum({4,8,9,13}) = {0,4,12,21,34}.
Definition:
cumsum.h:19
myra
Definition:
syntax.dox:1
Generated on Sun Aug 4 2024 12:26:05 for MyraMath by
1.8.13