NumCpp  2.7.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 
33 #include "NumCpp/NdArray.hpp"
35 
36 #include <complex>
37 #include <vector>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
53  template<typename dtype>
55  {
57 
58  const auto comp = [](const dtype lhs, const dtype rhs) noexcept -> bool
59  {
60  return utils::essentiallyEqual(lhs, rhs);
61  };
62 
63  const auto sorted = sort(inArray);
64 
65  std::vector<dtype> res(sorted.size());
66  const auto last = stl_algorithms::unique_copy(sorted.begin(), sorted.end(), res.begin(), comp);
67 
68  return NdArray<dtype>(res.begin(), last);
69  }
70 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
constexpr OutputIt unique_copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:744
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:52
Definition: Coordinate.hpp:45
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:54