NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
intersect1d.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <set>
31 #include <vector>
32 
35 #include "NumCpp/NdArray.hpp"
36 
37 namespace nc
38 {
39  //============================================================================
40  // Method Description:
52  template<typename dtype>
53  NdArray<dtype> intersect1d(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
54  {
56 
57  std::vector<dtype> res(inArray1.size() + inArray2.size());
58  const std::set<dtype> in1(inArray1.cbegin(), inArray1.cend());
59  const std::set<dtype> in2(inArray2.cbegin(), inArray2.cend());
60 
61  const auto iter = stl_algorithms::set_intersection(in1.begin(), in1.end(), in2.begin(), in2.end(), res.begin());
62  res.resize(iter - res.begin());
63  return NdArray<dtype>(res);
64  }
65 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:138
size_type size() const noexcept
Definition: NdArrayCore.hpp:4477
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1318
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1626
OutputIt set_intersection(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:587
Definition: Cartesian.hpp:40
NdArray< dtype > intersect1d(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: intersect1d.hpp:53