rjhogan / Adept-2

Combined array and automatic differentiation library in C++
http://www.met.reading.ac.uk/clouds/adept/
Apache License 2.0
163 stars 29 forks source link

maxval() reduction for values < 0 not working. #15

Closed fhirschberger closed 4 years ago

fhirschberger commented 4 years ago

Finding the maximum value of an array with maxval(), e.g.,

adept::Vector v{-2, -1};

std::cout << "v         : " << v                << "\n";
std::cout << "maxval(v) : " << adept::maxval(v) << "\n";

returns

v         : {-2, -1}
maxval(v) : 2.22507e-308

instead of -1. In reduce.h in line 217

T first_value() { return std::numeric_limits<T>::min(); }

returns a value > 0 for double, whereas lowest() returns -1.79769e+308. Also consider the output for inf

v         : {inf, inf}
minval(v) : 1.79769e+308
rjhogan commented 4 years ago

Thanks for reporting this bug - the latest commit should fix it.