NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
clip.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31
34#include "NumCpp/NdArray.hpp"
35
36namespace 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:56
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
self_type clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2373
Definition: Cartesian.hpp:40
dtype clip(dtype inValue, dtype inMinValue, dtype inMaxValue)
Definition: clip.hpp:50