NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
unique.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <complex>
31 #include <vector>
32 
36 #include "NumCpp/NdArray.hpp"
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
52  template<typename dtype>
54  {
56 
57  const auto comp = [](const dtype lhs, const dtype rhs) noexcept -> bool
58  { return utils::essentiallyEqual(lhs, rhs); };
59 
60  const auto sorted = sort(inArray);
61 
62  std::vector<dtype> res(sorted.size());
63  const auto last = stl_algorithms::unique_copy(sorted.begin(), sorted.end(), res.begin(), comp);
64 
65  return NdArray<dtype>(res.begin(), last);
66  }
67 } // 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:138
constexpr OutputIt unique_copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:823
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:48
Definition: Cartesian.hpp:40
NdArray< dtype > sort(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: sort.hpp:46
NdArray< dtype > unique(const NdArray< dtype > &inArray)
Definition: unique.hpp:53