Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Added ::GCD and ::LCM: <numeric> [c++17] contains gcd and lcm impleme…
Browse files Browse the repository at this point in the history
…ntation (#20583)
  • Loading branch information
mozga-intel authored Oct 15, 2021
1 parent f1f9669 commit fda48e0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/operator/mshadow_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
#include <cuda_fp16.h>
#endif

#define MXNET_HAS_GCD_LCM() 0
#if __cplusplus >= 201703L
#ifdef __has_gcd_lcm
#if __has_gcd_lcm(<numeric>)
#include <numeric>
#undef MXNET_HAS_GCD_LCM
#define MXNET_HAS_GCD_LCM() 1
#endif
#endif
#endif

namespace mxnet {
namespace op {
namespace mshadow_op {
Expand Down Expand Up @@ -1808,6 +1819,9 @@ struct gcd : public mxnet_op::tunable {
template <typename DType>
MSHADOW_XINLINE static typename enable_if<is_integral<DType>::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;
Expand Down Expand Up @@ -1839,6 +1853,7 @@ struct gcd : public mxnet_op::tunable {
c = b;
}
return c;
#endif
}

template <typename DType>
Expand All @@ -1853,6 +1868,9 @@ struct lcm : public mxnet_op::tunable {
template <typename DType>
MSHADOW_XINLINE static typename enable_if<is_integral<DType>::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;
Expand Down Expand Up @@ -1882,6 +1900,7 @@ struct lcm : public mxnet_op::tunable {
c = tmp_a / b * tmp_b;
}
return c;
#endif
}
template <typename DType>
MSHADOW_XINLINE static typename enable_if<!is_integral<DType>::value, DType>::type Map(DType a,
Expand Down

0 comments on commit fda48e0

Please sign in to comment.