NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
clip.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/NdArray.hpp"
33 
34 #ifdef __cpp_lib_clamp
35 #include <algorithm>
36 #endif
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
51  template<typename dtype>
52  dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
53  {
55 
56 #ifdef __cpp_lib_clamp
57  const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
58  {
59  return lhs < rhs;
60  };
61 
62  return std::clamp(inValue, inMinValue, inMaxValue, comparitor);
63 #else
64  if (inValue < inMinValue)
65  {
66  return inMinValue;
67  }
68  else if (inValue > inMaxValue)
69  {
70  return inMaxValue;
71  }
72 
73  return inValue;
74 #endif
75  }
76 
77  //============================================================================
78  // Method Description:
88  template<typename dtype>
89  NdArray<dtype> clip(const NdArray<dtype>& inArray, dtype inMinValue, dtype inMaxValue)
90  {
91  return inArray.clip(inMinValue, inMaxValue);
92  }
93 } // namespace nc
#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
NdArray< dtype > clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2293
Definition: Coordinate.hpp:45
dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
Definition: clip.hpp:52