NumCpp
2.1.0
A C++ implementation of the Python Numpy library
unique.hpp
Go to the documentation of this file.
1
#pragma once
30
31
#include "
NumCpp/Core/Internal/StaticAsserts.hpp
"
32
#include "
NumCpp/Core/Internal/StlAlgorithms.hpp
"
33
#include "
NumCpp/Functions/sort.hpp
"
34
#include "
NumCpp/NdArray.hpp
"
35
#include "
NumCpp/Utils/essentiallyEqual.hpp
"
36
37
#include <complex>
38
#include <vector>
39
40
namespace
nc
41
{
42
//============================================================================
43
// Method Description:
56
template
<
typename
dtype>
57
NdArray<dtype>
unique
(
const
NdArray<dtype>
& inArray)
58
{
59
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
(dtype);
60
61
const
auto
comp = [](
const
dtype lhs,
const
dtype rhs) noexcept ->
bool
62
{
63
return
utils::essentiallyEqual
(lhs, rhs);
64
};
65
66
const
auto
sorted =
sort
(inArray);
67
68
std::vector<dtype> res(sorted.size());
69
const
auto
last =
stl_algorithms::unique_copy
(sorted.begin(), sorted.end(), res.begin(), comp);
70
71
return
NdArray<dtype>
(res.begin(), last);
72
}
73
}
// namespace nc
StaticAsserts.hpp
nc::utils::essentiallyEqual
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition:
essentiallyEqual.hpp:53
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition:
StaticAsserts.hpp:51
nc::NdArray< dtype >
NdArray.hpp
nc::unique
NdArray< dtype > unique(const NdArray< dtype > &inArray)
Definition:
unique.hpp:57
nc
Definition:
Coordinate.hpp:45
essentiallyEqual.hpp
nc::stl_algorithms::unique_copy
constexpr OutputIt unique_copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition:
StlAlgorithms.hpp:745
StlAlgorithms.hpp
sort.hpp
nc::sort
NdArray< dtype > sort(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition:
sort.hpp:48
include
NumCpp
Functions
unique.hpp
Generated by
1.8.17