xtensor-blas
xtensor-blas copied to clipboard
xt::linalg::trace does not support complex arrays
The xt::linalg::trace
cannot deal with complex arrays, which is reflected in this source code (line 1315):
template <class T>
auto trace(const xexpression<T>& M, int offset = 0, int axis1 = 0, int axis2 = 1)
{
const auto& dM = M.derived_cast();
auto d = xt::diagonal(dM, offset, std::size_t(axis1), std::size_t(axis2));
std::size_t dim = d.dimension();
if (dim == 1)
{
return xt::xarray<double>(xt::sum(d)());
}
else
{
return xt::xarray<double>(xt::sum(d, {dim - 1}));
}
}
I tried to modify this part directly by changing xarray<double>
to xarray<std::complex<double>>
. But after I do this, I get another error from xutils.hpp
of xtensor
(line 628):
template <class T>
struct conditional_cast_functor<true, T>
{
template <class U>
inline auto operator()(U&& u) const
{
return static_cast<T>(std::forward<U>(u));
}
};
Error:
Cannot convert 'const std::__1::complex<double>' to 'double' without a conversion operator
Although there is a workaround (tracing the real and the complex parts separately), this is not convenient. Could you please look into this problem and fix it? Thanks!