Upgrading raw loops to use std::accumulate and other STL algorithms #1246
cvf-bcn-gituser
started this conversation in
Ideas
Replies: 1 comment
-
I would just like to add that I think that the above suggested change would probably make it less readable and therefore extendible. In general, I would like to extend the code painlessly. For example, in the spectral/flux.cpp module I would like to add reverse-coding (SFrc) and reverse rectification (SFrr) for an additional option to detect offsets that would not involve just adding more "else if" statements. But to do this, would need the use of a type of Factory pattern. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I was checking out the following raw loop in the CPP code modules in "src\algorithms\rhythm\superfluxnovelty"
With the STL lib algorithms"accumulate"
https://en.cppreference.com/w/cpp/algorithm/accumulate
we could replace this with one line, using a "capture by reference" to get something like this:
diffs = accumulate(begin[bands[i]),end(bands[i]), 0, [&] (int diffs,int j){ if (bands[i][j]-maxsBuffer[j]>0) return bands[i][j]-maxsBuffer[j]+diffs; return diffs;}
There are good examples of the use of the STL algorithm "find_if" in crest.cpp and entropy.cpp and perhaps it could be extended to other nested functions that are called regularly.
I was wondering if anyone has optimized any parts of the code in this way with better performance results?
Beta Was this translation helpful? Give feedback.
All reactions