Skip to content

Commit

Permalink
Fix compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lamyj committed Oct 1, 2023
1 parent ea38275 commit a5f1130
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/sycomore/Quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Quantity operator*(Quantity l, Quantity const & r);

/// @brief Multiplication
template<typename T, typename std::enable_if<std::is_arithmetic<T>::value, int>::type=0>
Quantity operator*(Quantity q, T s) { q *= s; return q; }
Quantity operator*(Quantity q, T s) { q *= static_cast<double>(s); return q; }

/// @brief Multiplication
template<typename T, typename std::enable_if<std::is_arithmetic<T>::value, int>::type=0>
Expand Down
4 changes: 2 additions & 2 deletions src/sycomore/epg/Discrete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/sycomore/epg/operators.txx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ std::tuple<T, T, T> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/sycomore/epg/simd_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ diffusion_3d_b_d<unsupported>(
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<Real>(
k_m, k_n, delta_k_m, delta_k_n, delta_k_product_term, tau, D_mn,
Expand All @@ -131,7 +131,7 @@ template<>
void
diffusion_3d_d<unsupported>(
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<Real, Complex>(
b_L_D, b_T_plus_D, b_T_minus_D, F, F_star, Z, 0, states_count, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/sycomore/epg/simd_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename RealType, typename ComplexType>
void diffusion_3d_w(
Expand All @@ -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 *
Expand Down
4 changes: 2 additions & 2 deletions src/sycomore/epg/simd_api.txx
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ template<INSTRUCTION_SET_TYPE InstructionSet>
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<Real, InstructionSet>;
using ComplexBatch = simd::Batch<Complex, InstructionSet>;
Expand Down Expand Up @@ -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<Real, InstructionSet>;
auto const simd_end = states_count - states_count % Batch::size;
Expand Down
4 changes: 2 additions & 2 deletions src/sycomore/epg/simd_api_avx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ void diffusion_3d_b_d<XSIMD_X86_AVX_VERSION>(
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<XSIMD_X86_AVX_VERSION>(
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
Expand Down
4 changes: 2 additions & 2 deletions src/sycomore/epg/simd_api_avx512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ void diffusion_3d_b_d<XSIMD_X86_AVX512_VERSION>(
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<XSIMD_X86_AVX512_VERSION>(
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
Expand Down
4 changes: 2 additions & 2 deletions src/sycomore/epg/simd_api_sse2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ void diffusion_3d_b_d<XSIMD_X86_SSE2_VERSION>(
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<XSIMD_X86_SSE2_VERSION>(
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
Expand Down
19 changes: 11 additions & 8 deletions src/sycomore/isochromat/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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};
}
Expand Down Expand Up @@ -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>
Expand Down
8 changes: 4 additions & 4 deletions src/sycomore/isochromat/Operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<end; ++item)
{
auto destination = xt::view(temp, item);
Expand All @@ -65,7 +65,7 @@ ::operator*=(Operator const & right)
}
else if(this->_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<end; ++item)
{
auto l = xt::view(this->_array, item);
Expand Down Expand Up @@ -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<end; ++item)
{
auto r = xt::view(this->_array, item);
Expand All @@ -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<end; ++item)
{
auto destination = xt::view(temp, item);
Expand Down
3 changes: 3 additions & 0 deletions src/sycomore/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ template<typename T>
typename std::enable_if<is_batch<T>::value, T>::type
exp(T const & arg)
{
#pragma warning(push)
#pragma warning(disable: 4244)
return xsimd::exp(arg);
#pragma warning(pop)
}

template<typename T>
Expand Down

0 comments on commit a5f1130

Please sign in to comment.