NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
clip.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31
33#include "NumCpp/NdArray.hpp"
34
35namespace nc
36{
37 //============================================================================
38 // Method Description:
48 template<typename dtype>
49 dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
50 {
52
53#ifdef __cpp_lib_clamp
54 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool { return lhs < rhs; };
55
56 return std::clamp(inValue, inMinValue, inMaxValue, comparitor);
57#else
58 if (inValue < inMinValue)
59 {
60 return inMinValue;
61 }
62 else if (inValue > inMaxValue)
63 {
64 return inMaxValue;
65 }
66
67 return inValue;
68#endif
69 }
70
71 //============================================================================
72 // Method Description:
82 template<typename dtype>
83 NdArray<dtype> clip(const NdArray<dtype>& inArray, dtype inMinValue, dtype inMaxValue)
84 {
85 return inArray.clip(inMinValue, inMaxValue);
86 }
87} // namespace nc
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition StaticAsserts.hpp:56
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
self_type clip(value_type inMin, value_type inMax) const
Definition NdArrayCore.hpp:2445
Definition Cartesian.hpp:39
dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
Definition clip.hpp:49