NumCpp
2.4.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 "
NumCpp/Core/Internal/StaticAsserts.hpp
"
31
#include "
NumCpp/Core/Internal/StlAlgorithms.hpp
"
32
#include "
NumCpp/Functions/sort.hpp
"
33
#include "
NumCpp/NdArray.hpp
"
34
#include "
NumCpp/Utils/essentiallyEqual.hpp
"
35
36
#include <complex>
37
#include <vector>
38
39
namespace
nc
40
{
41
//============================================================================
42
// Method Description:
55
template
<
typename
dtype>
56
NdArray<dtype>
unique
(
const
NdArray<dtype>
& inArray)
57
{
58
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
(dtype);
59
60
const
auto
comp = [](
const
dtype lhs,
const
dtype rhs) noexcept ->
bool
61
{
62
return
utils::essentiallyEqual
(lhs, rhs);
63
};
64
65
const
auto
sorted =
sort
(inArray);
66
67
std::vector<dtype> res(sorted.size());
68
const
auto
last =
stl_algorithms::unique_copy
(sorted.begin(), sorted.end(), res.begin(), comp);
69
70
return
NdArray<dtype>
(res.begin(), last);
71
}
72
}
// namespace nc
StaticAsserts.hpp
nc::utils::essentiallyEqual
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition:
essentiallyEqual.hpp:52
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition:
StaticAsserts.hpp:50
nc::NdArray< dtype >
NdArray.hpp
nc::unique
NdArray< dtype > unique(const NdArray< dtype > &inArray)
Definition:
unique.hpp:56
nc
Definition:
Coordinate.hpp:44
essentiallyEqual.hpp
nc::stl_algorithms::unique_copy
constexpr OutputIt unique_copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition:
StlAlgorithms.hpp:744
StlAlgorithms.hpp
sort.hpp
nc::sort
NdArray< dtype > sort(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition:
sort.hpp:47
include
NumCpp
Functions
unique.hpp
Generated by
1.8.17