NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
union1d.hpp
Go to the documentation of this file.
1
28#pragma once
29
31#include "NumCpp/NdArray.hpp"
32
33namespace nc
34{
35 //============================================================================
36 // Method Description:
49 template<typename dtype>
50 NdArray<dtype> union1d(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
51 {
53
54 const auto comp = [](const dtype lhs, const dtype rhs) noexcept -> bool { return lhs < rhs; };
55
56 const auto set1 = unique(inArray1);
57 const auto set2 = unique(inArray2);
58
59 std::vector<dtype> res(set1.size() + set2.size());
60 const auto last =
61 stl_algorithms::set_union(set1.begin(), set1.end(), set2.begin(), set2.end(), res.begin(), comp);
62
63 return NdArray<dtype>(res.begin(), last);
64 }
65} // 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:135
OutputIt set_union(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:646
Definition Cartesian.hpp:39
NdArray< dtype > unique(const NdArray< dtype > &inArray)
Definition unique.hpp:52
NdArray< dtype > union1d(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition union1d.hpp:50