NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
setdiff1d.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>
52 NdArray<dtype> setdiff1d(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
53 {
55
56 const auto comp = [](const dtype lhs, const dtype rhs) noexcept -> bool { return lhs < rhs; };
57
58 const auto set1 = unique(inArray1);
59 const auto set2 = unique(inArray2);
60
61 std::vector<dtype> res(set1.size());
62 const auto last =
63 stl_algorithms::set_difference(set1.begin(), set1.end(), set2.begin(), set2.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:135
OutputIt set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination)
Definition StlAlgorithms.hpp:531
Definition Cartesian.hpp:39
NdArray< dtype > unique(const NdArray< dtype > &inArray)
Definition unique.hpp:52
NdArray< dtype > setdiff1d(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition setdiff1d.hpp:52