NumCpp  1.0
A C++ implementation of the Python Numpy library
intersect1d.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
34 
35 #include <set>
36 #include <vector>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
54  template<typename dtype>
55  NdArray<dtype> intersect1d(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
56  {
58 
59  std::vector<dtype> res(inArray1.size() + inArray2.size());
60  const std::set<dtype> in1(inArray1.cbegin(), inArray1.cend());
61  const std::set<dtype> in2(inArray2.cbegin(), inArray2.cend());
62 
63  const auto iter = stl_algorithms::set_intersection(in1.begin(), in1.end(),
64  in2.begin(), in2.end(), res.begin());
65  res.resize(iter - res.begin());
66  return NdArray<dtype>(res);
67  }
68 }
StaticAsserts.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::intersect1d
NdArray< dtype > intersect1d(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: intersect1d.hpp:55
nc::NdArray< dtype >
NdArray.hpp
nc::NdArray::size
size_type size() const noexcept
Definition: NdArrayCore.hpp:4310
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
nc::stl_algorithms::set_intersection
OutputIt set_intersection(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:540