NumCpp  2.4.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:
52  template<typename dtype>
53  dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
54  {
56 
57 #ifdef __cpp_lib_clamp
58  const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
59  {
60  return lhs < rhs;
61  };
62 
63  return std::clamp(inValue, inMinValue, inMaxValue, comparitor);
64 #else
65  if (inValue < inMinValue)
66  {
67  return inMinValue;
68  }
69  else if (inValue > inMaxValue)
70  {
71  return inMaxValue;
72  }
73 
74  return inValue;
75 #endif
76  }
77 
78  //============================================================================
79  // Method Description:
90  template<typename dtype>
91  NdArray<dtype> clip(const NdArray<dtype>& inArray, dtype inMinValue, dtype inMaxValue)
92  {
93  return inArray.clip(inMinValue, inMaxValue);
94  }
95 } // namespace nc
StaticAsserts.hpp
StdComplexOperators.hpp
nc::clip
dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
Definition: clip.hpp:53
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
nc::NdArray< dtype >
nc::NdArray::clip
NdArray< dtype > clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2311
NdArray.hpp
nc
Definition: Coordinate.hpp:44