Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions include/xtensor/core/xmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ namespace xt
template <class T = double>
struct numeric_constants
{
static constexpr T PI = 3.141592653589793238463;
static constexpr T PI_2 = 1.57079632679489661923;
static constexpr T PI_4 = 0.785398163397448309616;
static constexpr T D_1_PI = 0.318309886183790671538;
static constexpr T D_2_PI = 0.636619772367581343076;
static constexpr T D_2_SQRTPI = 1.12837916709551257390;
static constexpr T SQRT2 = 1.41421356237309504880;
static constexpr T SQRT1_2 = 0.707106781186547524401;
static constexpr T E = 2.71828182845904523536;
static constexpr T LOG2E = 1.44269504088896340736;
static constexpr T LOG10E = 0.434294481903251827651;
static constexpr T LN2 = 0.693147180559945309417;
static constexpr T PI = static_cast<T>(3.141592653589793238463);
static constexpr T PI_2 = static_cast<T>(1.57079632679489661923);
static constexpr T PI_4 = static_cast<T>(0.785398163397448309616);
static constexpr T D_1_PI = static_cast<T>(0.318309886183790671538);
static constexpr T D_2_PI = static_cast<T>(0.636619772367581343076);
static constexpr T D_2_SQRTPI = static_cast<T>(1.12837916709551257390);
static constexpr T SQRT2 = static_cast<T>(1.41421356237309504880);
static constexpr T SQRT1_2 = static_cast<T>(0.707106781186547524401);
static constexpr T E = static_cast<T>(2.71828182845904523536);
static constexpr T LOG2E = static_cast<T>(1.44269504088896340736);
static constexpr T LOG10E = static_cast<T>(0.434294481903251827651);
static constexpr T LN2 = static_cast<T>(0.693147180559945309417);
};

/***********
Expand Down Expand Up @@ -569,6 +569,10 @@ namespace xt

namespace math
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
#endif
template <class T = void>
struct minimum
{
Expand Down Expand Up @@ -2403,6 +2407,9 @@ namespace xt
return !math::isnan(rhs) ? lhs + rhs : lhs;
}
};
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

struct nan_multiplies
{
Expand Down
14 changes: 14 additions & 0 deletions include/xtensor/core/xoperation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ namespace xt

namespace detail
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
#endif
DEFINE_COMPLEX_OVERLOAD(+);
DEFINE_COMPLEX_OVERLOAD(-);
DEFINE_COMPLEX_OVERLOAD(*);
Expand All @@ -101,13 +105,23 @@ namespace xt
DEFINE_COMPLEX_OVERLOAD(>=);
DEFINE_COMPLEX_OVERLOAD(==);
DEFINE_COMPLEX_OVERLOAD(!=);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

UNARY_OPERATOR_FUNCTOR(identity, +);
UNARY_OPERATOR_FUNCTOR(negate, -);
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
#endif
BINARY_OPERATOR_FUNCTOR(plus, +);
BINARY_OPERATOR_FUNCTOR(minus, -);
BINARY_OPERATOR_FUNCTOR(multiplies, *);
BINARY_OPERATOR_FUNCTOR(divides, /);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
BINARY_OPERATOR_FUNCTOR(modulus, %);
BINARY_OPERATOR_FUNCTOR(logical_or, ||);
BINARY_OPERATOR_FUNCTOR(logical_and, &&);
Expand Down
32 changes: 19 additions & 13 deletions include/xtensor/generators/xbuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ namespace xt
inline value_type access(const tuple_type& t, size_type axis, It first, It last) const
{
// trim off extra indices if provided to match behavior of containers
auto dim_offset = std::distance(first, last) - std::get<0>(t).dimension();
size_t axis_dim = *(first + axis + dim_offset);
auto dim_offset = static_cast<size_t>(std::distance(first, last)) - std::get<0>(t).dimension();
size_t axis_dim = static_cast<size_t>(*(first + static_cast<std::ptrdiff_t>(axis + dim_offset)));
auto match = [&](auto& arr)
{
if (axis_dim >= arr.shape()[axis])
Expand All @@ -520,7 +520,7 @@ namespace xt
const size_t stride = std::accumulate(
shape.begin() + i + 1,
shape.end(),
1,
size_t(1),
std::multiplies<size_t>()
);
if (i == axis)
Expand All @@ -529,11 +529,13 @@ namespace xt
}
else
{
const auto len = (*(first + i + dim_offset));
const auto len = static_cast<size_t>(
*(first + static_cast<std::ptrdiff_t>(i + dim_offset))
);
offset += len * stride;
}
}
const auto element = arr.begin() + offset;
const auto element = arr.begin() + static_cast<std::ptrdiff_t>(offset);
return *element;
};

Expand Down Expand Up @@ -576,16 +578,18 @@ namespace xt
const size_t stride = std::accumulate(
shape.begin() + i + 1,
shape.end(),
1,
size_t(1),
std::multiplies<size_t>()
);
const auto len = (*(first + i + after_axis));
const auto len = static_cast<size_t>(
*(first + static_cast<std::ptrdiff_t>(i + after_axis))
);
offset += len * stride;
}
const auto element = arr.begin() + offset;
const auto element = arr.begin() + static_cast<std::ptrdiff_t>(offset);
return *element;
};
size_type i = *(first + axis);
size_type i = static_cast<size_type>(*(first + static_cast<std::ptrdiff_t>(axis)));
return apply<value_type>(i, get_item, t);
}
};
Expand Down Expand Up @@ -960,10 +964,12 @@ namespace xt
detail::make_xgenerator(detail::repeat_impl<xclosure_t<E>>(std::forward<E>(e), I), shape)...
);
#else
return std::make_tuple(detail::make_xgenerator(
detail::repeat_impl<xclosure_t<E>>(std::forward<E>(e), I),
{e.shape()[0]...}
)...);
return std::make_tuple(
detail::make_xgenerator(
detail::repeat_impl<xclosure_t<E>>(std::forward<E>(e), I),
{e.shape()[0]...}
)...
);
#endif
}
}
Expand Down
13 changes: 7 additions & 6 deletions include/xtensor/misc/xfft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ namespace xt
auto odd = radix2(xt::view(ev, xt::range(1, _, 2)));
#endif

auto range = xt::arange<double>(N / 2);
auto exp = xt::exp(static_cast<value_type>(-2i) * pi * range / N);
auto range = xt::arange<double>(static_cast<double>(N / 2));
auto exp = xt::exp(static_cast<value_type>(-2i) * pi * range / static_cast<double>(N));
auto t = exp * odd;
auto first_half = even + t;
auto second_half = even - t;
Expand All @@ -82,15 +82,15 @@ namespace xt

// Find a power-of-2 convolution length m such that m >= n * 2 + 1
const std::size_t n = data.size();
size_t m = std::ceil(std::log2(n * 2 + 1));
m = std::pow(2, m);
size_t m = static_cast<size_t>(std::ceil(std::log2(n * 2 + 1)));
m = static_cast<size_t>(std::pow(2, m));

// Trignometric table
auto exp_table = xt::xtensor<std::complex<precision>, 1>::from_shape({n});
xt::xtensor<std::size_t, 1> i = xt::pow(xt::linspace<std::size_t>(0, n - 1, n), 2);
i %= (n * 2);

auto angles = xt::eval(precision{3.141592653589793238463} * i / n);
auto angles = xt::eval(static_cast<precision>(3.141592653589793238463) * i / static_cast<precision>(n));
auto j = std::complex<precision>(0, 1);
exp_table = xt::exp(-angles * j);

Expand Down Expand Up @@ -162,7 +162,8 @@ namespace xt
if constexpr (xtl::is_complex<typename std::decay<E>::type::value_type>::value)
{
// check the length of the data on that axis
const std::size_t n = e.shape(axis);
const std::size_t saxis = xt::normalize_axis(e.dimension(), axis);
const std::size_t n = e.shape(saxis);
if (n == 0)
{
XTENSOR_THROW(std::runtime_error, "Cannot take the iFFT along an empty dimention");
Expand Down
14 changes: 7 additions & 7 deletions include/xtensor/misc/xmanipulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ namespace xt
{
const std::size_t ax1 = normalize_axis(dim, axis1);
const std::size_t ax2 = normalize_axis(dim, axis2);
auto perm = xtl::make_sequence<S>(dim, 0);
using id_t = typename S::value_type;
auto perm = xtl::make_sequence<S>(dim, 0);
std::iota(perm.begin(), perm.end(), id_t(0));
perm[ax1] = ax2;
perm[ax2] = ax1;
perm[ax1] = static_cast<id_t>(ax2);
perm[ax2] = static_cast<id_t>(ax1);
return perm;
}
}
Expand Down Expand Up @@ -339,18 +339,18 @@ namespace xt

// Initializing to src_norm handles case where `dest == -1` and the loop
// does not go check `perm_idx == dest_norm` a `dim+1`th time.
auto perm = xtl::make_sequence<S>(dim, src_norm);
auto perm = xtl::make_sequence<S>(dim, static_cast<id_t>(src_norm));
id_t perm_idx = 0;
for (id_t i = 0; xtl::cmp_less(i, dim); ++i)
{
if (xtl::cmp_equal(perm_idx, dest_norm))
{
perm[perm_idx] = src_norm;
perm[static_cast<std::size_t>(perm_idx)] = static_cast<id_t>(src_norm);
++perm_idx;
}
if (xtl::cmp_not_equal(i, src_norm))
{
perm[perm_idx] = i;
perm[static_cast<std::size_t>(perm_idx)] = i;
++perm_idx;
}
}
Expand Down Expand Up @@ -659,7 +659,7 @@ namespace xt
template <std::size_t N, class E>
inline auto atleast_Nd(E&& e)
{
xstrided_slice_vector sv((std::max)(e.dimension(), N), all());
xstrided_slice_vector sv((std::max) (e.dimension(), N), all());
if (e.dimension() < N)
{
std::size_t i = 0;
Expand Down
Loading
Loading