MyraMath
myramath
utility
diff.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_DIFF_H
7
#define MYRAMATH_UTILITY_DIFF_H
8
14
#include <vector>
15
#include <myramath/utility/detail/ssize.h>
16
17
namespace
myra
{
18
20
template
<
class
T> std::vector<T>
diff
(
const
std::vector<T>& v)
21
{
22
int
I = ssize(v)-1;
23
std::vector<T> answer(I);
24
for
(
int
i = 0; i < I; ++i)
25
answer[i] = v[i+1]-v[i];
26
return
answer;
27
}
28
29
}
// namespace myra
30
31
#endif
myra::diff
std::vector< T > diff(const std::vector< T > &v)
Returns finite difference. For example, diff({0,4,12,21,34}) = {4,8,9,13}.
Definition:
diff.h:20
myra
Definition:
syntax.dox:1
Generated on Sun Aug 4 2024 12:26:05 for MyraMath by
1.8.13