Skip to content

Commit

Permalink
linalg.hpp: fix altsum and partaltsum not being pure
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Aug 4, 2024
1 parent 25c0726 commit 5fec561
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cpp/include/linalg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ namespace xph::linalg {
{
Tarr partaltsum;

double sign = -1.0;
partaltsum.reserve(arr.size() - window_size + 1);
std::ranges::copy(
arr | std::views::slide(window_size) | std::views::transform([](auto window) {
arr | std::views::slide(window_size) | std::views::transform([&](auto window) {
return std::accumulate(
window.begin(), window.end(), 0.0, [&](double cumaltsum, double num) {
static double sign = -1.0;
return cumaltsum + num * (sign = -sign);
});
}),
Expand Down Expand Up @@ -451,8 +451,8 @@ namespace xph::linalg {
void altsum(Tarr& arr)
{
static_assert(typename Tarr::value_type(-1.0) < 0);
decltype(arr.front()) sign = -1.0;
arr = { std::accumulate(arr.begin(), arr.end(), 0.0, [&](auto altsum, auto val) {
static decltype(val) sign = -1.0;
return altsum + val * (sign = -sign);
}) };
}
Expand Down

0 comments on commit 5fec561

Please sign in to comment.