-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Change functions in common.h into template functions (#969) #973
Conversation
Function names must be in the "Pascal Case" style. * check_elements_interval_closed to CheckElementsIntervalClosed * obtain_min_max_sum to ObtainMinMaxSum
* CheckElementsIntervalClosed * ObtainMinMaxSum These two functions were changed into template functions.
include/LightGBM/utils/common.h
Outdated
@@ -604,6 +610,11 @@ inline void ObtainMinMaxSum(const float *w, int nw, float *mi, float *ma, double | |||
if (su != nullptr) *su = sumw; | |||
} | |||
|
|||
template <typename T> | |||
inline void ObtainMinMaxSum(const T *w, int nw, T *mi, std::nullptr_t, double *su) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
su
could be T2
type.
I prefer to remove this function, and using ObtainMinMaxSum<float, double>(w, nw, mi, (float*)nullptr, su)
to call the function.
* remove an overload of the function ObtainMinMaxSum
include/LightGBM/utils/common.h
Outdated
for (int i = 0; i < ny; ++i) { | ||
if (y[i] < ymin || y[i] > ymax) { | ||
Log::Fatal("[%s]: does not tolerate element [#%i = %f] outside [%f, %f]", callername, i, y[i], ymin, ymax); | ||
if (typeid(T) == typeid(float) || typeid(T) == typeid(double)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this ? for the format output ?
you can use the stringstream to format T
type.
* Fix coding style (#969) Function names must be in the "Pascal Case" style. * check_elements_interval_closed to CheckElementsIntervalClosed * obtain_min_max_sum to ObtainMinMaxSum * Change functions in common.h into template functions (#969) * CheckElementsIntervalClosed * ObtainMinMaxSum These two functions were changed into template functions. * Remove an unpreferable overload * remove an overload of the function ObtainMinMaxSum * Use stringstream to format T type
CheckElementsIntervalClosed
ObtainMinMaxSum
These two functions were changed into template functions.