Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring efel to c++17 standard #326

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions efel/cppcore/LibV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
#include <sstream>
#include <iomanip>

using std::bind2nd;
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 +374,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 +979,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,13 +1003,13 @@ 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) {
if (dvdt.begin() + i_start + 5 == dvdt.end()) {
GErrorStr += "Could not find the decay.\n";
return -1;
}
i_start++;
[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;
}
i_start++;
}
// find the flat
// bool foundflat = false;
Expand Down Expand Up @@ -1441,11 +1438,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 +1465,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 = std::distance(
v.begin(), std::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 = std::distance(
v.begin(), std::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
Loading