NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
fmin.hpp
Go to the documentation of this file.
1 
28 #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:
55  template<typename dtype>
56  dtype fmin(dtype inValue1, dtype inValue2) noexcept
57  {
59 
60  return std::min(inValue1, inValue2,
61  [](const dtype value1, const dtype value2) noexcept -> bool
62  {
63  return value1 < value2;
64  });
65  }
66 
67  //============================================================================
68  // Method Description:
81  template<typename dtype>
82  NdArray<dtype> fmin(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
83  {
84  if (inArray1.shape() != inArray2.shape())
85  {
86  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
87  }
88 
89  NdArray<dtype> returnArray(inArray1.shape());
90 
91  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
92  [](dtype inValue1, dtype inValue2) noexcept -> dtype
93  {
94  return fmin(inValue1, inValue2);
95  });
96 
97  return returnArray;
98  }
99 } // 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:1270
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4483
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1614
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
Definition: Coordinate.hpp:45
dtype fmin(dtype inValue1, dtype inValue2) noexcept
Definition: fmin.hpp:56
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:45