NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
union1d.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/NdArray.hpp"
33 
34 namespace nc
35 {
36  //============================================================================
37  // Method Description:
51  template<typename dtype>
52  NdArray<dtype> union1d(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
53  {
55 
56  const auto comp = [](const dtype lhs, const dtype rhs) noexcept -> bool
57  {
58  return lhs < rhs;
59  };
60 
61  const auto set1 = unique(inArray1);
62  const auto set2 = unique(inArray2);
63 
64  std::vector<dtype> res(set1.size() + set2.size());
65  const auto last = stl_algorithms::set_union(set1.begin(), set1.end(),
66  set2.begin(), set2.end(), res.begin(), comp);
67 
68  return NdArray<dtype>(res.begin(), last);
69  }
70 } // namespace nc
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
nc::NdArray< dtype >
NdArray.hpp
nc::union1d
NdArray< dtype > union1d(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: union1d.hpp:52
nc::unique
NdArray< dtype > unique(const NdArray< dtype > &inArray)
Definition: unique.hpp:56
nc
Definition: Coordinate.hpp:44
nc::stl_algorithms::set_union
OutputIt set_union(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:586