NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
lcm.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:
58  template<typename dtype>
59  dtype lcm(dtype inValue1, dtype inValue2) noexcept
60  {
61  STATIC_ASSERT_INTEGER(dtype);
62 
63 #ifdef __cpp_lib_gcd_lcm
64  return std::lcm(inValue1, inValue2);
65 #else
66  return boost::integer::lcm(inValue1, inValue2);
67 #endif
68  }
69 
70 #ifndef NUMCPP_NO_USE_BOOST
71  //============================================================================
72  // Method Description:
81  template<typename dtype>
82  dtype lcm(const NdArray<dtype>& inArray)
83  {
84  STATIC_ASSERT_INTEGER(dtype);
85 
86  return boost::integer::lcm_range(inArray.cbegin(), inArray.cend()).first;
87  }
88 #endif // #ifndef NUMCPP_NO_USE_BOOST
89 } // namespace nc
90 
91 #endif // #if 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:1216
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1524
Definition: Coordinate.hpp:45
dtype lcm(dtype inValue1, dtype inValue2) noexcept
Definition: lcm.hpp:59
dtype lcm(const NdArray< dtype > &inArray)
Definition: lcm.hpp:82