NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
fmax.hpp
Go to the documentation of this file.
1 #pragma once
29 
33 #include "NumCpp/NdArray.hpp"
34 
35 #include <cmath>
36 #include <complex>
37 #include <string>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
54  template<typename dtype>
55  dtype fmax(dtype inValue1, dtype inValue2) noexcept
56  {
58 
59  return std::max(inValue1, inValue2,
60  [](const dtype value1, const dtype value2) noexcept -> bool
61  {
62  return value1 < value2;
63  });
64  }
65 
66  //============================================================================
67  // Method Description:
79  template<typename dtype>
80  NdArray<dtype> fmax(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
81  {
82  if (inArray1.shape() != inArray2.shape())
83  {
84  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
85  }
86 
87  NdArray<dtype> returnArray(inArray1.shape());
88 
89  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
90  [](dtype inValue1, dtype inValue2) noexcept -> dtype
91  {
92  return fmax(inValue1, inValue2);
93  });
94 
95  return returnArray;
96  }
97 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
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
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:44
dtype fmax(dtype inValue1, dtype inValue2) noexcept
Definition: fmax.hpp:55