NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
gcd.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <numeric>
31
32#if defined(__cpp_lib_gcd_lcm) || !defined(NUMCPP_NO_USE_BOOST)
33
35#include "NumCpp/NdArray.hpp"
36
37#ifndef NUMCPP_NO_USE_BOOST
38#include "boost/integer/common_factor_rt.hpp"
39#endif
40
41namespace nc
42{
43 //============================================================================
44 // Method Description:
55 template<typename dtype>
56 dtype gcd(dtype inValue1, dtype inValue2) noexcept
57 {
59
60#ifdef __cpp_lib_gcd_lcm
61 return std::gcd(inValue1, inValue2);
62#else
63 return boost::integer::gcd(inValue1, inValue2);
64#endif // #ifdef __cpp_lib_gcd_lcm
65 }
66
67#ifndef NUMCPP_NO_USE_BOOST
68 //============================================================================
69 // Method Description:
79 template<typename dtype>
80 dtype gcd(const NdArray<dtype>& inArray)
81 {
83 return boost::integer::gcd_range(inArray.cbegin(), inArray.cend()).first;
84 }
85#endif // #ifndef NUMCPP_NO_USE_BOOST
86} // namespace nc
87
88#endif // defined(__cpp_lib_gcd_lcm) || !defined(NUMCPP_NO_USE_BOOST)
#define STATIC_ASSERT_INTEGER(dtype)
Definition StaticAsserts.hpp:43
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
const_iterator cbegin() const noexcept
Definition NdArrayCore.hpp:1361
const_iterator cend() const noexcept
Definition NdArrayCore.hpp:1669
Definition Cartesian.hpp:39
dtype gcd(dtype inValue1, dtype inValue2) noexcept
Definition gcd.hpp:56