NumCpp  2.8.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 
30 #include <complex>
31 #include <vector>
32 
37 #include "NumCpp/NdArray.hpp"
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 { return lhs < rhs; };
59 
60  const auto set1 = unique(inArray1);
61  const auto set2 = unique(inArray2);
62 
63  std::vector<dtype> res(set1.size());
64  const auto last =
65  stl_algorithms::set_difference(set1.begin(), set1.end(), set2.begin(), set2.end(), res.begin(), comp);
66 
67  return NdArray<dtype>(res.begin(), last);
68  }
69 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:49
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:533
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