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