NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
setdiff1d.hpp
Go to the documentation of this file.
1 #pragma once
29 
34 #include "NumCpp/NdArray.hpp"
35 
36 #include <complex>
37 #include <vector>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
53  template<typename dtype>
54  NdArray<dtype> setdiff1d(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
55  {
57 
58  const auto comp = [](const dtype lhs, const dtype rhs) noexcept -> bool
59  {
60  return lhs < rhs;
61  };
62 
63  const auto set1 = unique(inArray1);
64  const auto set2 = unique(inArray2);
65 
66  std::vector<dtype> res(set1.size());
67  const auto last = stl_algorithms::set_difference(set1.begin(), set1.end(),
68  set2.begin(), set2.end(), res.begin(), comp);
69 
70  return NdArray<dtype>(res.begin(), last);
71  }
72 } // 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
OutputIt set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination)
Definition: StlAlgorithms.hpp:492
Definition: Coordinate.hpp:45
NdArray< dtype > unique(const NdArray< dtype > &inArray)
Definition: unique.hpp:54
NdArray< dtype > setdiff1d(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: setdiff1d.hpp:54