Skip to content

Commit 7d8d2ca

Browse files
JohanMabilleserge-sans-paille
authored andcommitted
Simplified implementation of basic complex functions
1 parent dcd6d55 commit 7d8d2ca

File tree

1 file changed

+13
-42
lines changed

1 file changed

+13
-42
lines changed

include/xsimd/arch/generic/xsimd_generic_complex.hpp

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,28 @@ namespace xsimd {
99

1010
using namespace types;
1111

12-
namespace detail
13-
{
14-
template <class B, bool is_complex>
15-
struct real_imag_kernel
16-
{
17-
using return_type = typename B::real_batch;
18-
19-
static return_type real(B const& z)
20-
{
21-
return z.real();
22-
}
23-
24-
static return_type imag(B const& z)
25-
{
26-
return z.imag();
27-
}
28-
};
29-
30-
template <class B>
31-
struct real_imag_kernel<B, false>
32-
{
33-
using return_type = B;
34-
35-
static return_type real(B const& z)
36-
{
37-
return z;
38-
}
39-
40-
static return_type imag(B const&)
41-
{
42-
return B(typename B::value_type(0));
43-
}
44-
};
12+
// real
13+
template <class A, class T>
14+
batch<T, A> real(batch<T, A> const& self, requires_arch<generic>) {
15+
return self;
4516
}
4617

47-
// real
4818
template <class A, class T>
49-
real_batch_type_t<batch<T, A>> real(batch<T, A> const& self, requires_arch<generic>) {
50-
using batch_type = batch<T, A>;
51-
constexpr bool is_cplx = xsimd::detail::is_complex<typename batch_type::value_type>::value;
52-
return detail::real_imag_kernel<batch_type, is_cplx>::real(self);
19+
batch<T, A> real(batch<std::complex<T>, A> const& self, requires_arch<generic>) {
20+
return self.real();
5321
}
5422

5523
// imag
5624
template <class A, class T>
57-
real_batch_type_t<batch<T, A>> imag(batch<T, A> const& self, requires_arch<generic>) {
58-
using batch_type = batch<T, A>;
59-
constexpr bool is_cplx = xsimd::detail::is_complex<typename batch_type::value_type>::value;
60-
return detail::real_imag_kernel<batch_type, is_cplx>::imag(self);
25+
batch<T, A> imag(batch<T, A> const& /*self*/, requires_arch<generic>) {
26+
return batch<T, A>(T(0));
6127
}
6228

29+
template <class A, class T>
30+
batch<T, A> imag(batch<std::complex<T>, A> const& self, requires_arch<generic>) {
31+
return self.imag();
32+
}
33+
6334
// arg
6435
template<class A, class T>
6536
real_batch_type_t<batch<T, A>> arg(batch<T, A> const& self, requires_arch<generic>) {

0 commit comments

Comments
 (0)