Skip to content

Commit

Permalink
bring efel to c++17 standard (#327)
Browse files Browse the repository at this point in the history
* Set C++17 standard

* Fix efel logging on windows for caching test

* remove unused using std::greater_equal statements

* add using std::distance to LibV1

* fix indentation in LibV1

* using std::distance in LibV5

* using std::find_if in LibV5
  • Loading branch information
anilbey authored Oct 19, 2023
1 parent 782cccc commit 3ae9246
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 116 deletions.
40 changes: 18 additions & 22 deletions efel/cppcore/LibV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
#include <sstream>
#include <iomanip>

using std::bind2nd;
using std::distance;
using std::find_if;
using std::greater;
using std::greater_equal;
using std::less_equal;
using std::list;
using std::min_element;
using std::max_element;
Expand Down Expand Up @@ -378,7 +375,7 @@ static int __AHP_depth_abs_slow_indices(const vector<double>& t,
distance(t.begin(),
find_if(t.begin() + peakindices[i + 1],
t.begin() + peakindices[i + 2],
bind2nd(greater_equal<double>(), t_start))),
[t_start](double val) { return val >= t_start; })),
v.begin() + peakindices[i + 2]));
}
return adas_indices.size();
Expand Down Expand Up @@ -983,10 +980,11 @@ static int __time_constant(const vector<double>& v, const vector<double>& t,
// int stimendindex;
// for(stimendindex = 0; t[stimendindex] < stimEnd; stimendindex++) ;
// int stimmiddleindex = (stimstartindex + stimendindex) / 2;
int stimmiddleindex = distance(
t.begin(),
find_if(t.begin() + stimstartindex, t.end(),
bind2nd(greater_equal<double>(), (stimStart + stimEnd) / 2.)));
double mid_stim = (stimStart + stimEnd) / 2.;
auto it_mid_stim = find_if(t.begin() + stimstartindex, t.end(),
[mid_stim](double val) { return val >= mid_stim; });
int stimmiddleindex = distance(t.begin(), it_mid_stim);

if (stimstartindex >= v.size() || stimmiddleindex < 0 ||
static_cast<size_t>(stimmiddleindex) >= v.size()) {
return -1;
Expand All @@ -1006,8 +1004,8 @@ static int __time_constant(const vector<double>& v, const vector<double>& t,
// find start of the decay
int i_start = 0;
while (find_if(dvdt.begin() + i_start, dvdt.begin() + i_start + 5,
bind2nd(greater<double>(), -min_derivative)) !=
dvdt.begin() + i_start + 5) {
[min_derivative](double val) { return val > -min_derivative; }) != dvdt.begin() + i_start + 5)
{
if (dvdt.begin() + i_start + 5 == dvdt.end()) {
GErrorStr += "Could not find the decay.\n";
return -1;
Expand Down Expand Up @@ -1441,11 +1439,9 @@ static int __AP_width(const vector<double>& t, const vector<double>& v,
if (strict_stiminterval){
int start_index = distance(
t.begin(),
find_if(t.begin(), t.end(), bind2nd(greater_equal<double>(), stimstart)));
int end_index =
distance(t.begin(),
find_if(t.begin(), t.end(),
std::bind2nd(std::greater_equal<double>(), stimend)));
find_if(t.begin(), t.end(), [stimstart](double x){ return x >= stimstart; }));
int end_index = distance(t.begin(), find_if(t.begin(), t.end(),
[stimend](double x){ return x >= stimend; }));
indices.push_back(start_index);
for (size_t i = 0; i < minahpindices.size(); i++) {
if (start_index < minahpindices[i] && minahpindices[i] < end_index) {
Expand All @@ -1470,14 +1466,14 @@ static int __AP_width(const vector<double>& t, const vector<double>& v,
v.begin() + indices[i + 1], bind2nd(less_equal<double>(), v_hm)));
apwidth.push_back(t[hm_index2] - t[hm_index1]);
*/
int onset_index = distance(
v.begin(), find_if(v.begin() + indices[i], v.begin() + indices[i + 1],
bind2nd(greater_equal<double>(), threshold)));
auto onset_index = distance(
v.begin(), find_if(v.begin() + indices[i], v.begin() + indices[i + 1],
[threshold](double x){ return x >= threshold; }));
// int end_index = distance(v.begin(), find_if(v.begin() + peakindices[i],
// v.begin() + indices[i + 1], bind2nd(less_equal<double>(), threshold)));
int end_index = distance(
v.begin(), find_if(v.begin() + onset_index, v.begin() + indices[i + 1],
bind2nd(less_equal<double>(), threshold)));
auto end_index = distance(
v.begin(), find_if(v.begin() + onset_index, v.begin() + indices[i + 1],
[threshold](double x){ return x <= threshold; }));
apwidth.push_back(t[end_index] - t[onset_index]);
}
return apwidth.size();
Expand Down
21 changes: 9 additions & 12 deletions efel/cppcore/LibV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#include <iostream>
#include <math.h>

using std::bind2nd;
using std::find_if;
using std::greater_equal;
using std::min_element;
using std::max_element;
using std::transform;
Expand All @@ -48,9 +46,7 @@ static int __AP_rise_indices(const vector<double>& v, const vector<int>& apbi,
}
vpeak.resize(pi[i] - apbi[i]);
transform(v.begin() + apbi[i], v.begin() + pi[i], vpeak.begin(),
bind2nd(std::minus<double>(), halfheight));
transform(vpeak.begin(), vpeak.end(), vpeak.begin(),
static_cast<double(*)(double)>(fabs));
[halfheight](double val) { return fabs(val - halfheight); });
apri[i] = distance(vpeak.begin(), min_element(vpeak.begin(), vpeak.end())) +
apbi[i];
}
Expand Down Expand Up @@ -87,9 +83,7 @@ static int __AP_fall_indices(const vector<double>& v, const vector<int>& apbi,
double halfheight = (v[pi[i]] + v[apbi[i]]) / 2.;
vector<double> vpeak(&v[pi[i]], &v[apei[i]]);
transform(vpeak.begin(), vpeak.end(), vpeak.begin(),
bind2nd(std::minus<double>(), halfheight));
transform(vpeak.begin(), vpeak.end(), vpeak.begin(),
static_cast<double(*)(double)>(fabs));
[halfheight](double val) { return fabs(val - halfheight); });
apfi[i] = distance(vpeak.begin(), min_element(vpeak.begin(), vpeak.end())) +
pi[i];
}
Expand Down Expand Up @@ -1264,10 +1258,13 @@ int LibV2::E27(mapStr2intVec& IntFeatureData,
static int __steady_state_hyper(const vector<double>& v,
const vector<double>& t, double stimend,
vector<double>& steady_state_hyper) {
int i_end =
distance(t.begin(), find_if(t.begin(), t.end(),
bind2nd(greater_equal<double>(), stimend))) -
5;
// Find the iterator pointing to the first time value greater than or equal to stimend
auto it_stimend = find_if(t.begin(), t.end(),
[stimend](double t_val) { return t_val >= stimend; });

// Calculate the index, ensuring you account for the offset of -5
int i_end = distance(t.begin(), it_stimend) - 5;


const int offset = 30;
if (i_end < 0 || i_end < offset) {
Expand Down
3 changes: 0 additions & 3 deletions efel/cppcore/LibV3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
#include <list>
#include <math.h>

using std::bind2nd;
using std::find_if;
using std::greater_equal;
using std::less_equal;
using std::list;
using std::min_element;

Expand Down
Loading

0 comments on commit 3ae9246

Please sign in to comment.