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
  • Loading branch information
mozga-intel committed Sep 27, 2021
1 parent 2b1da70 commit 0fd7daa
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 @@ -38,6 +38,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 @@ -1809,6 +1820,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 @@ -1840,6 +1854,7 @@ struct gcd : public mxnet_op::tunable {
c = b;
}
return c;
#endif
}

template <typename DType>
Expand All @@ -1854,6 +1869,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 @@ -1883,6 +1901,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 0fd7daa

Please sign in to comment.