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