diff --git a/src/operator/mshadow_op.h b/src/operator/mshadow_op.h index eee928452f50..9705a72f67bf 100644 --- a/src/operator/mshadow_op.h +++ b/src/operator/mshadow_op.h @@ -38,6 +38,17 @@ #include #endif +#define MXNET_HAS_GCD_LCM() 0 +#if __cplusplus >= 201703L +#ifdef __has_gcd_lcm +#if __has_gcd_lcm() +#include +#undef MXNET_HAS_GCD_LCM +#define MXNET_HAS_GCD_LCM() 1 +#endif +#endif +#endif + namespace mxnet { namespace op { namespace mshadow_op { @@ -1809,6 +1820,9 @@ struct gcd : public mxnet_op::tunable { template MSHADOW_XINLINE static typename enable_if::value, DType>::type Map(DType a, DType b) { +#if MXNET_HAS_GCD_LCM() + return std::gcd(a, b); +#else // minus cases. if (a < 0) { a = -a; @@ -1840,6 +1854,7 @@ struct gcd : public mxnet_op::tunable { c = b; } return c; +#endif } template @@ -1854,6 +1869,9 @@ struct lcm : public mxnet_op::tunable { template MSHADOW_XINLINE static typename enable_if::value, DType>::type Map(DType a, DType b) { +#if MXNET_HAS_GCD_LCM() + return std::lcm(a, b); +#else // minus cases. if (a < 0) { a = -a; @@ -1883,6 +1901,7 @@ struct lcm : public mxnet_op::tunable { c = tmp_a / b * tmp_b; } return c; +#endif } template MSHADOW_XINLINE static typename enable_if::value, DType>::type Map(DType a,