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