NumCpp  2.5.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
gcd.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #if defined(__cpp_lib_gcd_lcm) || !defined(NUMCPP_NO_USE_BOOST)
31 
34 #include "NumCpp/NdArray.hpp"
35 
36 #ifndef NUMCPP_NO_USE_BOOST
37 #include "boost/integer/common_factor_rt.hpp"
38 #endif
39 
40 #ifdef __cpp_lib_gcd_lcm
41 #include <numeric>
42 #endif
43 
44 namespace nc
45 {
46  //============================================================================
47  // Method Description:
59  template<typename dtype>
60  dtype gcd(dtype inValue1, dtype inValue2) noexcept
61  {
62  STATIC_ASSERT_INTEGER(dtype);
63 
64 #ifdef __cpp_lib_gcd_lcm
65  return std::gcd(inValue1, inValue2);
66 #else
67  return boost::integer::gcd(inValue1, inValue2);
68 #endif // #ifdef __cpp_lib_gcd_lcm
69  }
70 
71 #ifndef NUMCPP_NO_USE_BOOST
72  //============================================================================
73  // Method Description:
84  template<typename dtype>
85  dtype gcd(const NdArray<dtype>& inArray)
86  {
87  STATIC_ASSERT_INTEGER(dtype);
88  return boost::integer::gcd_range(inArray.cbegin(), inArray.cend()).first;
89  }
90 #endif // #ifndef NUMCPP_NO_USE_BOOST
91 } // namespace nc
92 
93 #endif // defined(__cpp_lib_gcd_lcm) || !defined(NUMCPP_NO_USE_BOOST)
#define STATIC_ASSERT_INTEGER(dtype)
Definition: StaticAsserts.hpp:40
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1270
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1614
Definition: Coordinate.hpp:45
dtype gcd(dtype inValue1, dtype inValue2) noexcept
Definition: gcd.hpp:60
dtype gcd(const NdArray< dtype > &inArray)
Definition: gcd.hpp:85