Skip to content

Commit 3733f42

Browse files
committed
remove warnings
1 parent 18f6524 commit 3733f42

22 files changed

+213
-135
lines changed

include/xtensor/core/xmath.hpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ namespace xt
3838
template <class T = double>
3939
struct numeric_constants
4040
{
41-
static constexpr T PI = 3.141592653589793238463;
42-
static constexpr T PI_2 = 1.57079632679489661923;
43-
static constexpr T PI_4 = 0.785398163397448309616;
44-
static constexpr T D_1_PI = 0.318309886183790671538;
45-
static constexpr T D_2_PI = 0.636619772367581343076;
46-
static constexpr T D_2_SQRTPI = 1.12837916709551257390;
47-
static constexpr T SQRT2 = 1.41421356237309504880;
48-
static constexpr T SQRT1_2 = 0.707106781186547524401;
49-
static constexpr T E = 2.71828182845904523536;
50-
static constexpr T LOG2E = 1.44269504088896340736;
51-
static constexpr T LOG10E = 0.434294481903251827651;
52-
static constexpr T LN2 = 0.693147180559945309417;
41+
static constexpr T PI = static_cast<T>(3.141592653589793238463);
42+
static constexpr T PI_2 = static_cast<T>(1.57079632679489661923);
43+
static constexpr T PI_4 = static_cast<T>(0.785398163397448309616);
44+
static constexpr T D_1_PI = static_cast<T>(0.318309886183790671538);
45+
static constexpr T D_2_PI = static_cast<T>(0.636619772367581343076);
46+
static constexpr T D_2_SQRTPI = static_cast<T>(1.12837916709551257390);
47+
static constexpr T SQRT2 = static_cast<T>(1.41421356237309504880);
48+
static constexpr T SQRT1_2 = static_cast<T>(0.707106781186547524401);
49+
static constexpr T E = static_cast<T>(2.71828182845904523536);
50+
static constexpr T LOG2E = static_cast<T>(1.44269504088896340736);
51+
static constexpr T LOG10E = static_cast<T>(0.434294481903251827651);
52+
static constexpr T LN2 = static_cast<T>(0.693147180559945309417);
5353
};
5454

5555
/***********
@@ -569,6 +569,10 @@ namespace xt
569569

570570
namespace math
571571
{
572+
#if defined(__clang__)
573+
#pragma clang diagnostic push
574+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
575+
#endif
572576
template <class T = void>
573577
struct minimum
574578
{
@@ -2403,6 +2407,9 @@ namespace xt
24032407
return !math::isnan(rhs) ? lhs + rhs : lhs;
24042408
}
24052409
};
2410+
#if defined(__clang__)
2411+
#pragma clang diagnostic pop
2412+
#endif
24062413

24072414
struct nan_multiplies
24082415
{

include/xtensor/core/xoperation.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ namespace xt
8383

8484
namespace detail
8585
{
86+
#if defined(__clang__)
87+
#pragma clang diagnostic push
88+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
89+
#endif
8690
DEFINE_COMPLEX_OVERLOAD(+);
8791
DEFINE_COMPLEX_OVERLOAD(-);
8892
DEFINE_COMPLEX_OVERLOAD(*);
@@ -101,13 +105,23 @@ namespace xt
101105
DEFINE_COMPLEX_OVERLOAD(>=);
102106
DEFINE_COMPLEX_OVERLOAD(==);
103107
DEFINE_COMPLEX_OVERLOAD(!=);
108+
#if defined(__clang__)
109+
#pragma clang diagnostic pop
110+
#endif
104111

105112
UNARY_OPERATOR_FUNCTOR(identity, +);
106113
UNARY_OPERATOR_FUNCTOR(negate, -);
114+
#if defined(__clang__)
115+
#pragma clang diagnostic push
116+
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
117+
#endif
107118
BINARY_OPERATOR_FUNCTOR(plus, +);
108119
BINARY_OPERATOR_FUNCTOR(minus, -);
109120
BINARY_OPERATOR_FUNCTOR(multiplies, *);
110121
BINARY_OPERATOR_FUNCTOR(divides, /);
122+
#if defined(__clang__)
123+
#pragma clang diagnostic pop
124+
#endif
111125
BINARY_OPERATOR_FUNCTOR(modulus, %);
112126
BINARY_OPERATOR_FUNCTOR(logical_or, ||);
113127
BINARY_OPERATOR_FUNCTOR(logical_and, &&);

include/xtensor/generators/xbuilder.hpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ namespace xt
498498
inline value_type access(const tuple_type& t, size_type axis, It first, It last) const
499499
{
500500
// trim off extra indices if provided to match behavior of containers
501-
auto dim_offset = std::distance(first, last) - std::get<0>(t).dimension();
502-
size_t axis_dim = *(first + axis + dim_offset);
501+
auto dim_offset = static_cast<size_t>(std::distance(first, last)) - std::get<0>(t).dimension();
502+
size_t axis_dim = static_cast<size_t>(*(first + static_cast<std::ptrdiff_t>(axis + dim_offset)));
503503
auto match = [&](auto& arr)
504504
{
505505
if (axis_dim >= arr.shape()[axis])
@@ -520,7 +520,7 @@ namespace xt
520520
const size_t stride = std::accumulate(
521521
shape.begin() + i + 1,
522522
shape.end(),
523-
1,
523+
size_t(1),
524524
std::multiplies<size_t>()
525525
);
526526
if (i == axis)
@@ -529,11 +529,13 @@ namespace xt
529529
}
530530
else
531531
{
532-
const auto len = (*(first + i + dim_offset));
532+
const auto len = static_cast<size_t>(
533+
*(first + static_cast<std::ptrdiff_t>(i + dim_offset))
534+
);
533535
offset += len * stride;
534536
}
535537
}
536-
const auto element = arr.begin() + offset;
538+
const auto element = arr.begin() + static_cast<std::ptrdiff_t>(offset);
537539
return *element;
538540
};
539541

@@ -576,16 +578,18 @@ namespace xt
576578
const size_t stride = std::accumulate(
577579
shape.begin() + i + 1,
578580
shape.end(),
579-
1,
581+
size_t(1),
580582
std::multiplies<size_t>()
581583
);
582-
const auto len = (*(first + i + after_axis));
584+
const auto len = static_cast<size_t>(
585+
*(first + static_cast<std::ptrdiff_t>(i + after_axis))
586+
);
583587
offset += len * stride;
584588
}
585-
const auto element = arr.begin() + offset;
589+
const auto element = arr.begin() + static_cast<std::ptrdiff_t>(offset);
586590
return *element;
587591
};
588-
size_type i = *(first + axis);
592+
size_type i = static_cast<size_type>(*(first + static_cast<std::ptrdiff_t>(axis)));
589593
return apply<value_type>(i, get_item, t);
590594
}
591595
};
@@ -960,10 +964,12 @@ namespace xt
960964
detail::make_xgenerator(detail::repeat_impl<xclosure_t<E>>(std::forward<E>(e), I), shape)...
961965
);
962966
#else
963-
return std::make_tuple(detail::make_xgenerator(
964-
detail::repeat_impl<xclosure_t<E>>(std::forward<E>(e), I),
965-
{e.shape()[0]...}
966-
)...);
967+
return std::make_tuple(
968+
detail::make_xgenerator(
969+
detail::repeat_impl<xclosure_t<E>>(std::forward<E>(e), I),
970+
{e.shape()[0]...}
971+
)...
972+
);
967973
#endif
968974
}
969975
}

include/xtensor/misc/xfft.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ namespace xt
6161
auto odd = radix2(xt::view(ev, xt::range(1, _, 2)));
6262
#endif
6363

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

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

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

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

@@ -162,7 +162,8 @@ namespace xt
162162
if constexpr (xtl::is_complex<typename std::decay<E>::type::value_type>::value)
163163
{
164164
// check the length of the data on that axis
165-
const std::size_t n = e.shape(axis);
165+
const std::size_t saxis = xt::normalize_axis(e.dimension(), axis);
166+
const std::size_t n = e.shape(saxis);
166167
if (n == 0)
167168
{
168169
XTENSOR_THROW(std::runtime_error, "Cannot take the iFFT along an empty dimention");

include/xtensor/misc/xmanipulation.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ namespace xt
293293
{
294294
const std::size_t ax1 = normalize_axis(dim, axis1);
295295
const std::size_t ax2 = normalize_axis(dim, axis2);
296-
auto perm = xtl::make_sequence<S>(dim, 0);
297296
using id_t = typename S::value_type;
297+
auto perm = xtl::make_sequence<S>(dim, 0);
298298
std::iota(perm.begin(), perm.end(), id_t(0));
299-
perm[ax1] = ax2;
300-
perm[ax2] = ax1;
299+
perm[ax1] = static_cast<id_t>(ax2);
300+
perm[ax2] = static_cast<id_t>(ax1);
301301
return perm;
302302
}
303303
}
@@ -339,18 +339,18 @@ namespace xt
339339

340340
// Initializing to src_norm handles case where `dest == -1` and the loop
341341
// does not go check `perm_idx == dest_norm` a `dim+1`th time.
342-
auto perm = xtl::make_sequence<S>(dim, src_norm);
342+
auto perm = xtl::make_sequence<S>(dim, static_cast<id_t>(src_norm));
343343
id_t perm_idx = 0;
344344
for (id_t i = 0; xtl::cmp_less(i, dim); ++i)
345345
{
346346
if (xtl::cmp_equal(perm_idx, dest_norm))
347347
{
348-
perm[perm_idx] = src_norm;
348+
perm[static_cast<std::size_t>(perm_idx)] = static_cast<id_t>(src_norm);
349349
++perm_idx;
350350
}
351351
if (xtl::cmp_not_equal(i, src_norm))
352352
{
353-
perm[perm_idx] = i;
353+
perm[static_cast<std::size_t>(perm_idx)] = i;
354354
++perm_idx;
355355
}
356356
}
@@ -659,7 +659,7 @@ namespace xt
659659
template <std::size_t N, class E>
660660
inline auto atleast_Nd(E&& e)
661661
{
662-
xstrided_slice_vector sv((std::max)(e.dimension(), N), all());
662+
xstrided_slice_vector sv((std::max) (e.dimension(), N), all());
663663
if (e.dimension() < N)
664664
{
665665
std::size_t i = 0;

0 commit comments

Comments
 (0)