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