NumCpp  2.1.0
A C++ implementation of the Python Numpy library
setdiff1d.hpp
Go to the documentation of this file.
1 #pragma once
30 
35 #include "NumCpp/NdArray.hpp"
36 
37 #include <complex>
38 #include <vector>
39 
40 namespace nc
41 {
42  //============================================================================
43  // Method Description:
55  template<typename dtype>
56  NdArray<dtype> setdiff1d(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
57  {
59 
60  const auto comp = [](const dtype lhs, const dtype rhs) noexcept -> bool
61  {
62  return lhs < rhs;
63  };
64 
65  const auto set1 = unique(inArray1);
66  const auto set2 = unique(inArray2);
67 
68  std::vector<dtype> res(set1.size());
69  const auto last = stl_algorithms::set_difference(set1.begin(), set1.end(),
70  set2.begin(), set2.end(), res.begin(), comp);
71 
72  return NdArray<dtype>(res.begin(), last);
73  }
74 } // namespace nc
StaticAsserts.hpp
nc::setdiff1d
NdArray< dtype > setdiff1d(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: setdiff1d.hpp:56
unique.hpp
StdComplexOperators.hpp
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
nc::stl_algorithms::set_difference
OutputIt set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination)
Definition: StlAlgorithms.hpp:493
StlAlgorithms.hpp