Skip to content

Commit 83f9e3b

Browse files
authored
Merge pull request #2253 from adriendelsalle/fix-binary-complex-op
Fix binary operators on complex
2 parents 0de70bc + 13600ce commit 83f9e3b

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

.azure-pipelines/azure-pipelines-win.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
conda install cmake==3.14.0 ^
3838
ninja ^
3939
nlohmann_json ^
40-
xtl==0.6.21 ^
40+
xtl==0.6.22 ^
4141
xsimd==7.4.8 ^
4242
python=3.6
4343
conda list

environment-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ channels:
33
- conda-forge
44
dependencies:
55
- cmake
6-
- xtl=0.6.21
6+
- xtl=0.6.22
77
- xsimd=7.4.8
88
- nlohmann_json

include/xtensor/xoperation.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,21 @@ namespace xt
4343
} \
4444
}
4545

46+
#define DEFINE_COMPLEX_OVERLOAD(OP) \
47+
template <class T1, class T2, XTL_REQUIRES(xtl::negation<std::is_same<T1, T2>>)> \
48+
constexpr auto operator OP(const std::complex<T1>& arg1, const std::complex<T2>& arg2) \
49+
{ \
50+
using result_type = typename xtl::promote_type_t<std::complex<T1>, std::complex<T2>>; \
51+
return (result_type(arg1) OP result_type(arg2)); \
52+
}
53+
4654
#define BINARY_OPERATOR_FUNCTOR(NAME, OP) \
4755
struct NAME \
4856
{ \
4957
template <class T1, class T2> \
5058
constexpr auto operator()(T1&& arg1, T2&& arg2) const \
5159
{ \
60+
using xt::detail::operator OP; \
5261
return (std::forward<T1>(arg1) OP std::forward<T2>(arg2)); \
5362
} \
5463
template <class B> \
@@ -60,6 +69,24 @@ namespace xt
6069

6170
namespace detail
6271
{
72+
DEFINE_COMPLEX_OVERLOAD(+);
73+
DEFINE_COMPLEX_OVERLOAD(-);
74+
DEFINE_COMPLEX_OVERLOAD(*);
75+
DEFINE_COMPLEX_OVERLOAD(/);
76+
DEFINE_COMPLEX_OVERLOAD(%);
77+
DEFINE_COMPLEX_OVERLOAD(||);
78+
DEFINE_COMPLEX_OVERLOAD(&&);
79+
DEFINE_COMPLEX_OVERLOAD(|);
80+
DEFINE_COMPLEX_OVERLOAD(&);
81+
DEFINE_COMPLEX_OVERLOAD(^);
82+
DEFINE_COMPLEX_OVERLOAD(<<);
83+
DEFINE_COMPLEX_OVERLOAD(>>);
84+
DEFINE_COMPLEX_OVERLOAD(<);
85+
DEFINE_COMPLEX_OVERLOAD(<=);
86+
DEFINE_COMPLEX_OVERLOAD(>);
87+
DEFINE_COMPLEX_OVERLOAD(>=);
88+
DEFINE_COMPLEX_OVERLOAD(==);
89+
DEFINE_COMPLEX_OVERLOAD(!=);
6390

6491
UNARY_OPERATOR_FUNCTOR(identity, +);
6592
UNARY_OPERATOR_FUNCTOR(negate, -);

test/test_xmath_result_type.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ namespace xt
241241
CHECK_RESULT_TYPE(adouble + aint, double);
242242
CHECK_RESULT_TYPE(adouble + adcomplex, std::complex<double>);
243243
CHECK_RESULT_TYPE(aulong + adouble, double);
244+
CHECK_RESULT_TYPE(afcomplex + adcomplex, std::complex<double>);
244245
}
245-
246-
247246
}
248-

0 commit comments

Comments
 (0)