From a5f113088c013cf2268a17f15f18d9bcb5b1e141 Mon Sep 17 00:00:00 2001 From: Julien Lamy Date: Sun, 1 Oct 2023 18:07:51 +0200 Subject: [PATCH] Fix compilation warnings --- src/sycomore/Quantity.h | 2 +- src/sycomore/epg/Discrete.cpp | 4 ++-- src/sycomore/epg/operators.txx | 6 +++--- src/sycomore/epg/simd_api.cpp | 4 ++-- src/sycomore/epg/simd_api.h | 4 ++-- src/sycomore/epg/simd_api.txx | 4 ++-- src/sycomore/epg/simd_api_avx.cpp | 4 ++-- src/sycomore/epg/simd_api_avx512.cpp | 4 ++-- src/sycomore/epg/simd_api_sse2.cpp | 4 ++-- src/sycomore/isochromat/Model.cpp | 19 +++++++++++-------- src/sycomore/isochromat/Operator.cpp | 8 ++++---- src/sycomore/simd.h | 3 +++ 12 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/sycomore/Quantity.h b/src/sycomore/Quantity.h index 3d6932f..7318e6e 100644 --- a/src/sycomore/Quantity.h +++ b/src/sycomore/Quantity.h @@ -171,7 +171,7 @@ Quantity operator*(Quantity l, Quantity const & r); /// @brief Multiplication template::value, int>::type=0> -Quantity operator*(Quantity q, T s) { q *= s; return q; } +Quantity operator*(Quantity q, T s) { q *= static_cast(s); return q; } /// @brief Multiplication template::value, int>::type=0> diff --git a/src/sycomore/epg/Discrete.cpp b/src/sycomore/epg/Discrete.cpp index 39da7be..ad92d2e 100644 --- a/src/sycomore/epg/Discrete.cpp +++ b/src/sycomore/epg/Discrete.cpp @@ -78,7 +78,7 @@ ArrayC Discrete ::state(Order const & order) const { - std::size_t const k = std::round(double(order/this->_bin_width)); + std::size_t const k = std::lround(double(order/this->_bin_width)); auto const it = std::find(this->_orders.begin(), this->_orders.end(), k); if(it == this->_orders.end()) @@ -176,7 +176,7 @@ ::shift(Quantity const & duration, Quantity const & gradient) { // This assumes a constant gradient in the integral: // k(t) = γ ∫_0^t G(t') dt' = γ⋅t⋅G - long long const delta_k = std::round( + long long const delta_k = std::lround( sycomore::gamma.magnitude*gradient.magnitude*duration.magnitude / this->_bin_width.magnitude); diff --git a/src/sycomore/epg/operators.txx b/src/sycomore/epg/operators.txx index ef3ec51..1e08e32 100644 --- a/src/sycomore/epg/operators.txx +++ b/src/sycomore/epg/operators.txx @@ -26,14 +26,14 @@ std::tuple diffusion( Real D, Real duration, T const & k, Real delta_k) { auto const b_T_plus = - duration*(sycomore::simd::pow(k+delta_k/2, 2.) + std::pow(delta_k, 2.) / 12); + duration*(sycomore::simd::pow(k+delta_k/2, 2) + std::pow(delta_k, 2) / 12); auto const D_T_plus = sycomore::simd::exp(-b_T_plus*D); auto const b_T_minus = - duration*(sycomore::simd::pow(-k+delta_k/2, 2.) + std::pow(delta_k, 2.) / 12); + duration*(sycomore::simd::pow(-k+delta_k/2, 2) + std::pow(delta_k, 2) / 12); auto const D_T_minus = sycomore::simd::exp(-b_T_minus*D); - auto const b_L = sycomore::simd::pow(k, 2.) * duration; + auto const b_L = sycomore::simd::pow(k, 2) * duration; auto const D_L = sycomore::simd::exp(-b_L*D); return std::make_tuple(D_T_plus, D_T_minus, D_L); diff --git a/src/sycomore/epg/simd_api.cpp b/src/sycomore/epg/simd_api.cpp index 1aae83f..e36010e 100644 --- a/src/sycomore/epg/simd_api.cpp +++ b/src/sycomore/epg/simd_api.cpp @@ -119,7 +119,7 @@ diffusion_3d_b_d( Real const * k_m, Real const * k_n, Real delta_k_m, Real delta_k_n, Real delta_k_product_term, Real tau, Real D_mn, Real * b_L_D, Real * b_T_plus_D, Real * b_T_minus_D, - unsigned int states_count) + std::size_t states_count) { diffusion_3d_b_w( k_m, k_n, delta_k_m, delta_k_n, delta_k_product_term, tau, D_mn, @@ -131,7 +131,7 @@ template<> void diffusion_3d_d( Real const * b_L_D, Real const * b_T_plus_D, Real const * b_T_minus_D, - Complex * F, Complex * F_star, Complex * Z, unsigned int states_count) + Complex * F, Complex * F_star, Complex * Z, std::size_t states_count) { diffusion_3d_w( b_L_D, b_T_plus_D, b_T_minus_D, F, F_star, Z, 0, states_count, 1); diff --git a/src/sycomore/epg/simd_api.h b/src/sycomore/epg/simd_api.h index c0232f8..8ae60fc 100644 --- a/src/sycomore/epg/simd_api.h +++ b/src/sycomore/epg/simd_api.h @@ -136,7 +136,7 @@ SYCOMORE_DEFINE_SIMD_DISPATCHER_FUNCTION( Real const * k_m, Real const * k_n, Real delta_k_m, Real delta_k_n, Real delta_k_product_term, Real tau, Real D_mn, Real * b_L_D, Real * b_T_plus_D, Real * b_T_minus_D, - unsigned int states_count)) + std::size_t states_count)) template void diffusion_3d_w( @@ -149,7 +149,7 @@ SYCOMORE_DEFINE_SIMD_DISPATCHER_FUNCTION( ( Real const * b_L_D, Real const * b_T_plus_D, Real const * b_T_minus_D, Complex * F, Complex * F_star, Complex * Z, - unsigned int states_count)) + std::size_t states_count)) /******************************************************************************* * Off-resonance operator * diff --git a/src/sycomore/epg/simd_api.txx b/src/sycomore/epg/simd_api.txx index 8554978..20a8309 100644 --- a/src/sycomore/epg/simd_api.txx +++ b/src/sycomore/epg/simd_api.txx @@ -431,7 +431,7 @@ template void diffusion_3d_d( Real const * b_L_D, Real const * b_T_plus_D, Real const * b_T_minus_D, - Complex * F, Complex * F_star, Complex * Z, unsigned int states_count) + Complex * F, Complex * F_star, Complex * Z, std::size_t states_count) { using RealBatch = simd::Batch; using ComplexBatch = simd::Batch; @@ -485,7 +485,7 @@ diffusion_3d_b_d( Real const * k_m, Real const * k_n, Real delta_k_m, Real delta_k_n, Real delta_k_product_term, Real tau, Real D_mn, Real * b_L_D, Real * b_T_plus_D, Real * b_T_minus_D, - unsigned int states_count) + std::size_t states_count) { using Batch = simd::Batch; auto const simd_end = states_count - states_count % Batch::size; diff --git a/src/sycomore/epg/simd_api_avx.cpp b/src/sycomore/epg/simd_api_avx.cpp index 8d9a880..1e714e4 100644 --- a/src/sycomore/epg/simd_api_avx.cpp +++ b/src/sycomore/epg/simd_api_avx.cpp @@ -47,13 +47,13 @@ void diffusion_3d_b_d( Real const * k_m, Real const * k_n, Real delta_k_m, Real delta_k_n, Real delta_k_product_term, Real tau, Real D_mn, Real * b_L_D, Real * b_T_plus_D, Real * b_T_minus_D, - unsigned int states_count); + std::size_t states_count); template void diffusion_3d_d( Real const * b_L_D, Real const * b_T_plus_D, Real const * b_T_minus_D, Complex * F, Complex * F_star, Complex * Z, - unsigned int states_count); + std::size_t states_count); template void diff --git a/src/sycomore/epg/simd_api_avx512.cpp b/src/sycomore/epg/simd_api_avx512.cpp index 1fe2ed0..c5fa7de 100644 --- a/src/sycomore/epg/simd_api_avx512.cpp +++ b/src/sycomore/epg/simd_api_avx512.cpp @@ -47,13 +47,13 @@ void diffusion_3d_b_d( Real const * k_m, Real const * k_n, Real delta_k_m, Real delta_k_n, Real delta_k_product_term, Real tau, Real D_mn, Real * b_L_D, Real * b_T_plus_D, Real * b_T_minus_D, - unsigned int states_count); + std::size_t states_count); template void diffusion_3d_d( Real const * b_L_D, Real const * b_T_plus_D, Real const * b_T_minus_D, Complex * F, Complex * F_star, Complex * Z, - unsigned int states_count); + std::size_t states_count); template void diff --git a/src/sycomore/epg/simd_api_sse2.cpp b/src/sycomore/epg/simd_api_sse2.cpp index 433c9df..72399f3 100644 --- a/src/sycomore/epg/simd_api_sse2.cpp +++ b/src/sycomore/epg/simd_api_sse2.cpp @@ -47,13 +47,13 @@ void diffusion_3d_b_d( Real const * k_m, Real const * k_n, Real delta_k_m, Real delta_k_n, Real delta_k_product_term, Real tau, Real D_mn, Real * b_L_D, Real * b_T_plus_D, Real * b_T_minus_D, - unsigned int states_count); + std::size_t states_count); template void diffusion_3d_d( Real const * b_L_D, Real const * b_T_plus_D, Real const * b_T_minus_D, Complex * F, Complex * F_star, Complex * Z, - unsigned int states_count); + std::size_t states_count); template void diff --git a/src/sycomore/isochromat/Model.cpp b/src/sycomore/isochromat/Model.cpp index f1ef392..c36c4f1 100644 --- a/src/sycomore/isochromat/Model.cpp +++ b/src/sycomore/isochromat/Model.cpp @@ -21,6 +21,8 @@ namespace sycomore namespace isochromat { +#pragma warning(push) +#pragma warning(disable: 4267) Model ::Model( Quantity const & T1, Quantity const & T2, TensorR<1> const & M0, @@ -33,12 +35,13 @@ ::Model( { // Nothing else } +#pragma warning(pop) Model ::Model( TensorQ<1> const & T1, TensorQ<1> const & T2, TensorR<2> const & M0, TensorQ<2> const & positions, TensorQ<1> const & delta_omega) -: _T1(T1.shape()), _T2(T2.shape()), _M0(xt::view(M0, xt::all(), 2)), +: _T1(T1.shape()), _T2(T2.shape()), _M0(xt::view(M0, xt::all(), 2UL)), _delta_omega(delta_omega.size() == 0 ? T1.shape() : delta_omega.shape()), _magnetization(TensorR<2>::shape_type{M0.shape()[0], 4}), _positions(positions.shape()) @@ -54,7 +57,7 @@ ::Model( this->_T2 = convert_to(T2, units::s); xt::view(this->_magnetization, xt::all(), xt::range(0, 3)) = M0; - xt::view(this->_magnetization, xt::all(), 3) = 1; + xt::view(this->_magnetization, xt::all(), 3UL) = 1; this->_delta_omega = delta_omega.size() == 0 @@ -162,11 +165,11 @@ ::build_relaxation(Quantity const & duration) const auto const duration_s = duration.convert_to(units::s); auto const E1 = xt::exp(-duration_s/this->_T1); auto const E2 = xt::exp(-duration_s/this->_T2); - xt::view(op, xt::all(), 0, 0) = E2; - xt::view(op, xt::all(), 1, 1) = E2; - xt::view(op, xt::all(), 2, 2) = E1; - xt::view(op, xt::all(), 3, 3) = 1; - xt::view(op, xt::all(), 2, 3) = this->_M0*(1-E1); + xt::view(op, xt::all(), 0UL, 0UL) = E2; + xt::view(op, xt::all(), 1UL, 1UL) = E2; + xt::view(op, xt::all(), 2UL, 2UL) = E1; + xt::view(op, xt::all(), 3UL, 3UL) = 1; + xt::view(op, xt::all(), 2UL, 3UL) = this->_M0*(1-E1); return {op}; } @@ -256,7 +259,7 @@ ::magnetization() const { return xt::eval( xt::view(this->_magnetization, xt::all(), xt::range(0, 3)) - / xt::expand_dims(xt::view(this->_magnetization, xt::all(), 3), 1)); + / xt::expand_dims(xt::view(this->_magnetization, xt::all(), 3UL), 1)); } TensorQ<2> diff --git a/src/sycomore/isochromat/Operator.cpp b/src/sycomore/isochromat/Operator.cpp index 95a2e43..17dd95c 100644 --- a/src/sycomore/isochromat/Operator.cpp +++ b/src/sycomore/isochromat/Operator.cpp @@ -54,7 +54,7 @@ ::operator*=(Operator const & right) if(this->_array.shape()[0] == 1 && right._array.shape()[0] != 1) { auto temp = xt::empty_like(right._array); - auto l = xt::view(this->_array, 0); + auto l = xt::view(this->_array, 0UL); for(std::size_t item=0, end=right._array.shape()[0]; item_array.shape()[0] != 1 && right._array.shape()[0] == 1) { - auto r = xt::view(right._array, 0); + auto r = xt::view(right._array, 0UL); for(std::size_t item=0, end=this->_array.shape()[0]; item_array, item); @@ -99,7 +99,7 @@ ::pre_multiply(Operator const & left) if(left._array.shape()[0] == 1 && this->_array.shape()[0] != 1) { - auto l = xt::view(left._array, 0); + auto l = xt::view(left._array, 0UL); for(std::size_t item=0, end=this->_array.shape()[0]; item_array, item); @@ -110,7 +110,7 @@ ::pre_multiply(Operator const & left) else if(left._array.shape()[0] != 1 && this->_array.shape()[0] == 1) { auto temp = xt::empty_like(left._array); - auto r = xt::view(this->_array, 0); + auto r = xt::view(this->_array, 0UL); for(std::size_t item=0, end=left._array.shape()[0]; item typename std::enable_if::value, T>::type exp(T const & arg) { +#pragma warning(push) +#pragma warning(disable: 4244) return xsimd::exp(arg); +#pragma warning(pop) } template