NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
searchsorted.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <iterator>
32
33#include "NumCpp/Core/Enums.hpp"
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
57 template<typename dtype>
60 {
62
63 switch (side)
64 {
65 case Side::LEFT:
66 {
67 return std::distance(inArray.begin(), std::lower_bound(inArray.begin(), inArray.end(), inValue));
68 }
69 case Side::RIGHT:
70 {
71 return std::distance(inArray.begin(), std::upper_bound(inArray.begin(), inArray.end(), inValue));
72 }
73 }
74
75 // get rid of compiler warning
76 return {};
77 }
78
79 //============================================================================
80 // Method Description:
97 template<typename dtype>
100 {
102 std::transform(inValues.begin(),
103 inValues.end(),
104 indices.begin(),
105 [&inArray, side](const auto& value) { return searchsorted(inArray, value, side); });
106 return indices;
107 }
108} // 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
int32 index_type
Definition NdArrayCore.hpp:157
Definition Cartesian.hpp:40
Side
Definition Enums.hpp:129
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
NdArray< dtype >::index_type searchsorted(const NdArray< dtype > &inArray, dtype inValue, Side side=Side::LEFT)
Definition searchsorted.hpp:59