NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
fmod.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/NdArray.hpp"
34 
35 #include <cmath>
36 #include <string>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
51  template<typename dtype,
52  enable_if_t<is_integral_v<dtype>, int> = 0>
53  dtype fmod(dtype inValue1, dtype inValue2) noexcept
54  {
55  return inValue1 % inValue2;
56  }
57 
58  //============================================================================
59  // Method Description:
69  template<typename dtype,
70  enable_if_t<is_floating_point_v<dtype>, int> = 0>
71  dtype fmod(dtype inValue1, dtype inValue2) noexcept
72  {
73  return std::fmod(inValue1, inValue2);
74  }
75 
76  //============================================================================
77  // Method Description:
87  template<typename dtype>
88  NdArray<dtype> fmod(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
89  {
90  if (inArray1.shape() != inArray2.shape())
91  {
92  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
93  }
94 
95  NdArray<dtype> returnArray(inArray1.shape());
96 
97  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
98  [](dtype inValue1, dtype inValue2) noexcept -> dtype
99  {
100  return fmod(inValue1, inValue2);
101  });
102 
103  return returnArray;
104  }
105 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
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
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4283
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1524
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
Definition: Coordinate.hpp:45
dtype fmod(dtype inValue1, dtype inValue2) noexcept
Definition: fmod.hpp:53
NdArray< dtype > fmod(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: fmod.hpp:88