Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 13 additions & 9 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
15 changes: 9 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,17 @@ 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 +164,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
12 changes: 6 additions & 6 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
43 changes: 26 additions & 17 deletions include/xtensor/misc/xsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace xt
const std::ptrdiff_t secondary_stride = get_secondary_stride(ev);

const auto begin = ev.data();
const auto end = begin + n_iters * secondary_stride;
const auto end = begin + static_cast<std::ptrdiff_t>(n_iters) * secondary_stride;
for (auto iter = begin; iter != end; iter += secondary_stride)
{
fct(iter, iter + secondary_stride);
Expand All @@ -100,9 +100,9 @@ namespace xt
XTENSOR_ASSERT(secondary_stride1 == secondary_stride2);

const auto begin1 = e1.data();
const auto end1 = begin1 + n_iters * secondary_stride1;
const auto end1 = begin1 + static_cast<std::ptrdiff_t>(n_iters) * secondary_stride1;
const auto begin2 = e2.data();
const auto end2 = begin2 + n_iters * secondary_stride2;
const auto end2 = begin2 + static_cast<std::ptrdiff_t>(n_iters) * secondary_stride2;
auto iter1 = begin1;
auto iter2 = begin2;
for (; (iter1 != end1) && (iter2 != end2); iter1 += secondary_stride1, iter2 += secondary_stride2)
Expand Down Expand Up @@ -304,6 +304,7 @@ namespace xt
XTENSOR_ASSERT(std::distance(data_begin, data_end) >= 0);
XTENSOR_ASSERT(std::distance(idx_begin, idx_end) == std::distance(data_begin, data_end));
(void) idx_end; // TODO(C++17) [[maybe_unused]] only used in assertion.
(void) data_end;

std::iota(idx_begin, idx_end, 0);
switch (method)
Expand All @@ -315,7 +316,10 @@ namespace xt
idx_end,
[&](const auto i, const auto j)
{
return comp(*(data_begin + i), *(data_begin + j));
return comp(
*(data_begin + static_cast<std::ptrdiff_t>(i)),
*(data_begin + static_cast<std::ptrdiff_t>(j))
);
}
);
}
Expand All @@ -326,7 +330,10 @@ namespace xt
idx_end,
[&](const auto i, const auto j)
{
return comp(*(data_begin + i), *(data_begin + j));
return comp(
*(data_begin + static_cast<std::ptrdiff_t>(i)),
*(data_begin + static_cast<std::ptrdiff_t>(j))
);
}
);
}
Expand Down Expand Up @@ -722,7 +729,7 @@ namespace xt
res_end,
kth_container.rbegin(),
kth_container.rend(),
[&ev_begin](auto const& i, auto const& j)
[&ev_begin](const auto& i, const auto& j)
{
return *(ev_begin + i) < *(ev_begin + j);
}
Expand Down Expand Up @@ -784,7 +791,7 @@ namespace xt
for (auto i : indices)
{
auto idx = current_index;
idx[current_dim] = i;
idx[current_dim] = static_cast<id_t>(i);
select_indices_impl(shape, indices, axis, current_dim + 1, idx, out);
}
}
Expand All @@ -793,7 +800,7 @@ namespace xt
for (id_t i = 0; xtl::cmp_less(i, shape[current_dim]); ++i)
{
auto idx = current_index;
idx[current_dim] = i;
idx[current_dim] = static_cast<id_t>(i);
select_indices_impl(shape, indices, axis, current_dim + 1, idx, out);
}
}
Expand All @@ -802,7 +809,7 @@ namespace xt
for (auto i : indices)
{
auto idx = current_index;
idx[current_dim] = i;
idx[current_dim] = static_cast<id_t>(i);
out.push_back(std::move(idx));
}
}
Expand All @@ -811,7 +818,7 @@ namespace xt
for (id_t i = 0; xtl::cmp_less(i, shape[current_dim]); ++i)
{
auto idx = current_index;
idx[current_dim] = i;
idx[current_dim] = static_cast<id_t>(i);
out.push_back(std::move(idx));
}
}
Expand All @@ -834,7 +841,7 @@ namespace xt
const std::size_t ax = normalize_axis(e.dimension(), axis);
using shape_t = get_strides_t<typename std::decay_t<E>::shape_type>;
auto shape = xtl::forward_sequence<shape_t, decltype(e.shape())>(e.shape());
shape[ax] = indices.size();
shape[ax] = static_cast<typename shape_t::value_type>(indices.size());
return reshape_view(
index_view(std::forward<E>(e), select_indices(e.shape(), indices, ax)),
std::move(shape)
Expand Down Expand Up @@ -915,12 +922,16 @@ namespace xt
auto kth_gamma = detail::quantile_kth_gamma<T, id_t, P>(n, probas, alpha, beta);

// Select relevant values for computing interpolating quantiles
auto e_partition = xt::partition(std::forward<E>(e), kth_gamma.first, ax);
auto e_kth = detail::fancy_indexing(std::move(e_partition), std::move(kth_gamma.first), ax);
auto e_partition = xt::partition(std::forward<E>(e), kth_gamma.first, static_cast<std::ptrdiff_t>(ax));
auto e_kth = detail::fancy_indexing(
std::move(e_partition),
std::move(kth_gamma.first),
static_cast<std::ptrdiff_t>(ax)
);

// Reshape interpolation coefficients
auto gm1_g_shape = xtl::make_sequence<tmp_shape_t>(e.dimension(), 1);
gm1_g_shape[ax] = kth_gamma.second.size();
gm1_g_shape[ax] = static_cast<id_t>(kth_gamma.second.size());
auto gm1_g_reshaped = reshape_view(std::move(kth_gamma.second), std::move(gm1_g_shape));

// Compute interpolation
Expand All @@ -932,7 +943,7 @@ namespace xt
e_kth_g_shape[ax + 1] /= 2;
auto quantiles = xt::sum(reshape_view(std::move(e_kth_g), std::move(e_kth_g_shape)), ax);
// Cannot do a transpose on a non-strided expression so we have to eval
return moveaxis(eval(std::move(quantiles)), ax, 0);
return moveaxis(eval(std::move(quantiles)), static_cast<std::ptrdiff_t>(ax), 0);
}

// Static proba array overload
Expand Down Expand Up @@ -1237,7 +1248,6 @@ namespace xt
template <layout_type L = XTENSOR_DEFAULT_TRAVERSAL, class E>
inline auto argmin(const xexpression<E>& e)
{
using value_type = typename E::value_type;
auto&& ed = eval(e.derived_cast());
auto begin = ed.template begin<L>();
auto end = ed.template end<L>();
Expand Down Expand Up @@ -1267,7 +1277,6 @@ namespace xt
template <layout_type L = XTENSOR_DEFAULT_TRAVERSAL, class E>
inline auto argmax(const xexpression<E>& e)
{
using value_type = typename E::value_type;
auto&& ed = eval(e.derived_cast());
auto begin = ed.template begin<L>();
auto end = ed.template end<L>();
Expand Down
Loading
Loading