NumCpp  2.9.0
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 #include <numeric>
31 
32 #if defined(__cpp_lib_gcd_lcm) || !defined(NUMCPP_NO_USE_BOOST)
33 
36 #include "NumCpp/NdArray.hpp"
37 
38 #ifndef NUMCPP_NO_USE_BOOST
39 #include "boost/integer/common_factor_rt.hpp"
40 #endif
41 
42 namespace nc
43 {
44  //============================================================================
45  // Method Description:
56  template<typename dtype>
57  dtype gcd(dtype inValue1, dtype inValue2) noexcept
58  {
59  STATIC_ASSERT_INTEGER(dtype);
60 
61 #ifdef __cpp_lib_gcd_lcm
62  return std::gcd(inValue1, inValue2);
63 #else
64  return boost::integer::gcd(inValue1, inValue2);
65 #endif // #ifdef __cpp_lib_gcd_lcm
66  }
67 
68 #ifndef NUMCPP_NO_USE_BOOST
69  //============================================================================
70  // Method Description:
80  template<typename dtype>
81  dtype gcd(const NdArray<dtype>& inArray)
82  {
83  STATIC_ASSERT_INTEGER(dtype);
84  return boost::integer::gcd_range(inArray.cbegin(), inArray.cend()).first;
85  }
86 #endif // #ifndef NUMCPP_NO_USE_BOOST
87 } // namespace nc
88 
89 #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:1221
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1529
Definition: Coordinate.hpp:45
dtype gcd(dtype inValue1, dtype inValue2) noexcept
Definition: gcd.hpp:57
dtype gcd(const NdArray< dtype > &inArray)
Definition: gcd.hpp:81