NumCpp  2.9.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 
30 #include <algorithm>
31 
34 #include "NumCpp/NdArray.hpp"
35 
36 namespace nc
37 {
38  //============================================================================
39  // Method Description:
49  template<typename dtype>
50  dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
51  {
53 
54 #ifdef __cpp_lib_clamp
55  const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool { return lhs < rhs; };
56 
57  return std::clamp(inValue, inMinValue, inMaxValue, comparitor);
58 #else
59  if (inValue < inMinValue)
60  {
61  return inMinValue;
62  }
63  else if (inValue > inMaxValue)
64  {
65  return inMaxValue;
66  }
67 
68  return inValue;
69 #endif
70  }
71 
72  //============================================================================
73  // Method Description:
83  template<typename dtype>
84  NdArray<dtype> clip(const NdArray<dtype>& inArray, dtype inMinValue, dtype inMaxValue)
85  {
86  return inArray.clip(inMinValue, inMaxValue);
87  }
88 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:49
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:2224
Definition: Coordinate.hpp:45
dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
Definition: clip.hpp:50