Skip to content

Commit

Permalink
removing C++20 Attributes that were flagged as warnings on Debian.
Browse files Browse the repository at this point in the history
  • Loading branch information
halpo committed Oct 29, 2024
1 parent a026f93 commit c8c28ea
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 39 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Makefile
roadmap.md
^LICENSE\.md$
^cran-comments\.md$
^CRAN-SUBMISSION$
10 changes: 5 additions & 5 deletions src/NW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
denom += Kxb(k,j);
}

if ( denom == 0.0 ) [[unlikely]]
if ( denom == 0.0 ) // [[unlikely]]
{
for ( int i=0; i<fyxb.ncol(); ++i )
{
Expand Down Expand Up @@ -152,7 +152,7 @@ NumericMatrix _pcoriaccel_NW(
for ( int i=0; i<Xb.length(); ++i ) denom+=KxbT_row[i];

//(Row of answer is zeros if denominator is zero)
if ( denom == 0 ) [[unlikely]]
if ( denom == 0 ) // [[unlikely]]
{
for ( int i=0; i<fyxb.ncol(); ++i )
{
Expand Down Expand Up @@ -203,7 +203,7 @@ NumericMatrix _pcoriaccel_NW(
double h, //scalar bandwidth
String kernel = "K2_Biweight"
) {
if ( Xb.length() != Y.length() ) [[unlikely]]
if ( Xb.length() != Y.length() ) // [[unlikely]]
{
stop("Lengths of arguments `Xb` and `Y` must match!");
}
Expand All @@ -213,15 +213,15 @@ NumericMatrix _pcoriaccel_NW(
{
return _pcoriaccel_NW< Tfloat, 1 >( Xb,Y, xb, y_seq, (Tfloat)h );
}
else if ( kernel == "K2_Biweight" ) [[likely]]
else if ( kernel == "K2_Biweight" ) // [[likely]]
{
return _pcoriaccel_NW< Tfloat, 2 >( Xb,Y, xb, y_seq, (Tfloat)h );
}
// else if ( kernel == "K4_Biweight" )
// {
// return _pcoriaccel_NW< Tfloat, 3 >( Xb,Y, xb, y_seq, (Tfloat)h );
// }
else [[unlikely]]
else // [[unlikely]]
{
stop("Invalid value for `kernel`: choices are { \"dnorm\", \"K2_Biweight\" }.");
}
Expand Down
8 changes: 4 additions & 4 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void negate_slot( List list, char const* slot_name ) noexcept

[[nodiscard]] NumericMatrix mmul( NumericMatrix matrA , NumericMatrix matrB )
{
if ( matrA.ncol() != matrB.nrow() ) [[unlikely]]
if ( matrA.ncol() != matrB.nrow() ) // [[unlikely]]
{
stop(
"Matrix dimension mismatch " +
Expand All @@ -46,7 +46,7 @@ void negate_slot( List list, char const* slot_name ) noexcept
}
[[nodiscard]] NumericVector mmul( NumericVector row_vec, NumericMatrix matr )
{
if ( row_vec.length() != matr.nrow() ) [[unlikely]]
if ( row_vec.length() != matr.nrow() ) // [[unlikely]]
{
stop(
"Matrix dimension mismatch 1x" + std::to_string(row_vec.length()) + " by " +
Expand All @@ -68,7 +68,7 @@ void negate_slot( List list, char const* slot_name ) noexcept
}
[[nodiscard]] NumericVector mmul( NumericMatrix matr , NumericVector col_vec )
{
if ( matr.ncol() != col_vec.length() ) [[unlikely]]
if ( matr.ncol() != col_vec.length() ) // [[unlikely]]
{
stop(
"Matrix dimension mismatch " +
Expand Down Expand Up @@ -111,7 +111,7 @@ void negate_slot( List list, char const* slot_name ) noexcept

[[nodiscard]] double pcoriaccel_inner_prod( NumericVector vecA, NumericVector vecB )
{
if ( vecA.length() != vecB.length() ) [[unlikely]]
if ( vecA.length() != vecB.length() ) // [[unlikely]]
{
stop(
"Matrix dimension mismatch 1x" + std::to_string(vecA.length()) +
Expand Down
8 changes: 4 additions & 4 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ inline NumericVector& operator/=( NumericVector& vec, double val ) noexcept
}
inline NumericMatrix& operator-=( NumericMatrix& matrA, NumericMatrix const& matrB )
{
if ( matrA.nrow()!=matrB.nrow() || matrA.ncol()!=matrB.ncol() ) [[unlikely]]
if ( matrA.nrow()!=matrB.nrow() || matrA.ncol()!=matrB.ncol() ) // [[unlikely]]
stop("Matrix dimension mismatch in subtract (" +
std::to_string(matrA.nrow()) + "x" + std::to_string(matrA.ncol()) +
" vs. " +
Expand All @@ -130,7 +130,7 @@ inline NumericMatrix& operator-=( NumericMatrix& matrA, NumericMatrix const& mat
}
inline NumericMatrix& operator+=( NumericMatrix& matrA, NumericMatrix const& matrB )
{
if (matrA.nrow() != matrB.nrow() || matrA.ncol() != matrB.ncol()) [[unlikely]]
if (matrA.nrow() != matrB.nrow() || matrA.ncol() != matrB.ncol()) // [[unlikely]]
stop("Matrix dimension mismatch in add (" +
std::to_string(matrA.nrow()) + "x" + std::to_string(matrA.ncol()) +
" vs. " +
Expand All @@ -141,7 +141,7 @@ inline NumericMatrix& operator+=( NumericMatrix& matrA, NumericMatrix const& mat
}
inline NumericVector& operator-=( NumericVector& vecA, NumericVector const& vecB )
{
if ( vecA.length() != vecB.length() ) [[unlikely]]
if ( vecA.length() != vecB.length() ) // [[unlikely]]
stop("Vector dimension mismatch in subtract (" +
std::to_string(vecA.length()) + " vs. " +
std::to_string(vecB.length()) + ")!"
Expand All @@ -151,7 +151,7 @@ inline NumericVector& operator-=( NumericVector& vecA, NumericVector const& vecB
}
inline NumericVector& operator+=( NumericVector& vecA, NumericVector const& vecB )
{
if ( vecA.length() != vecB.length() ) [[unlikely]]
if ( vecA.length() != vecB.length() ) // [[unlikely]]
stop("Vector dimension mismatch in add (" +
std::to_string(vecA.length()) + " vs. " +
std::to_string(vecB.length()) + ")!"
Expand Down
12 changes: 8 additions & 4 deletions src/compute_influence_term_2_quadv_sim_via_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,24 @@
String kernel = "K2_Biweight"
) {
#if 1
if ( X.ncol()!=beta.length() || X.ncol()!=individual_X.ncol() ) [[unlikely]] stop(
if ( X.ncol()!=beta.length() || X.ncol()!=individual_X.ncol() ) // [[unlikely]]
stop(
"Width of matrix `X` (" + std::to_string(X.ncol()) + "), " +
"width of matrix `individual_X` (" + std::to_string(individual_X.ncol()) + "), " +
"and length of vector `beta` (" + std::to_string(beta.length()) + ") must match!"
);
if ( X.nrow() != Y.length() ) [[unlikely]] stop(
if ( X.nrow() != Y.length() ) // [[unlikely]]
stop(
"Height of matrix `X` (" + std::to_string(X.nrow()) + ") and " +
"length of vector `Y` (" + std::to_string(Y.length()) + ") must match!"
);
if ( individual_X.ncol() != x_slope.length() ) [[unlikely]] stop(
if ( individual_X.ncol() != x_slope.length() ) // [[unlikely]]
stop(
"Width of matrix `individual_X` (" + std::to_string(individual_X.ncol()) + ") and " +
"length of vector `x_slope` (" + std::to_string(x_slope.length()) + ") must match!"
);
if ( individual_X.nrow() != times.length() ) [[unlikely]] stop(
if ( individual_X.nrow() != times.length() ) // [[unlikely]]
stop(
"Height of matrix `individual_X` (" + std::to_string(individual_X.nrow()) + ") and " +
"length of vector `times` (" + std::to_string(times.length()) + ") must match!"
);
Expand Down
11 changes: 7 additions & 4 deletions src/estimate_pmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ template< class Tfloat, KernelType kernel > [[nodiscard]] inline static
denom += Kxb_j;
}

if ( denom == 0.0 ) [[unlikely]] pmf_est.fill(0.0);
if ( denom == 0.0 ) // [[unlikely]]
{
pmf_est.fill(0.0);
}
else
{
for ( double& elem : pmf_est ) elem/=denom;
Expand All @@ -72,7 +75,7 @@ template< class Tfloat, KernelType kernel > [[nodiscard]] inline static
double h,
String kernel = "K2_Biweight"
) {
if ( Xb.length() != Y.length() ) [[unlikely]]
if ( Xb.length() != Y.length() ) // [[unlikely]]
{
stop("Lengths of arguments `Xb` and `Y` must match!");
}
Expand All @@ -82,15 +85,15 @@ template< class Tfloat, KernelType kernel > [[nodiscard]] inline static
{
return _pcoriaccel_estimate_pmf< Tfloat, Kt_normal >( Xb,Y, xi, y_seq, (Tfloat)h );
}
else if ( kernel == "K2_Biweight" ) [[likely]]
else if ( kernel == "K2_Biweight" ) // [[likely]]
{
return _pcoriaccel_estimate_pmf< Tfloat, Kt_biweight2 >( Xb,Y, xi, y_seq, (Tfloat)h );
}
// else if ( kernel == "K4_Biweight" )
// {
// return _pcoriaccel_estimate_pmf< Tfloat, Kt_biweight4 >( Xb,Y, xi, y_seq, (Tfloat)h );
// }
else [[unlikely]]
else // [[unlikely]]
{
stop("Invalid value for `kernel`: choices are { \"dnorm\", \"K2_Biweight\" }.");
}
Expand Down
14 changes: 9 additions & 5 deletions src/integrate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ template<class Fn>
unsigned N = 1000
) {
List ret(3);
if ( lo < hi ) [[likely]] {} //continue below
if ( lo < hi ) // [[likely]]
{} //continue below
else if ( lo == hi ) return List::create(
Named("Q" ) = 0.0,
Named("fcnt" ) = 0,
Expand Down Expand Up @@ -67,7 +68,7 @@ template<class Fn>
using Tval = decltype(integrand(0.0));

List ret(3);
if ( lo < hi ) [[likely]] {} //continue below
if ( lo < hi ) {} //continue below
else if ( lo == hi ) return List::create(
Named("Q" ) = 0.0,
Named("fcnt" ) = 0,
Expand Down Expand Up @@ -115,12 +116,14 @@ template<class Fn>
auto& helper_ref, double a,double c,double e, Tval const& fa,Tval const& fc,Tval const& fe
) {
constexpr unsigned fcnt_max = 10000;
if ( fcnt+2 > fcnt_max ) [[unlikely]] stop("Too many integrand evaluations; singularity likely.");
if ( fcnt+2 > fcnt_max ) // [[unlikely]]
stop("Too many integrand evaluations; singularity likely.");
//if ( depth > 5 ) stop("abort");

//Calculate subintervals
double h = e - a;
if ( h<hmin || a==c || c==e ) [[unlikely]] stop("Minimum step size; singularity possible.");
if ( h<hmin || a==c || c==e ) // [[unlikely]]
stop("Minimum step size; singularity possible.");
double b = 0.5*( a + c );
double d = 0.5*( c + e );

Expand All @@ -135,7 +138,8 @@ template<class Fn>
Tval Q2=clone(fb); Q2+=fd; Q2*=2.0; Q2+=fc; Q2*=2.0; Q2+=fa; Q2+=fe; Q2*=h*(1.0/12.0);
//One step of Romberg extrapolation: Q = Q2 + (Q2-Q1)/15
Tval Q=clone(Q2); Q-=Q1; Q*=1.0/15.0; Q+=Q2;
if ( !all_finite(Q) ) [[unlikely]] stop("Improper integrand: ∞ or NaN");
if ( !all_finite(Q) ) // [[unlikely]]
stop("Improper integrand: ∞ or NaN");

//If accurate enough, return. Original was just max(Q2-Q)<tol; doesn't sound correct to me.
// TODO: can optimize with prev.
Expand Down
30 changes: 17 additions & 13 deletions src/spline_basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ SplineBasis::SplineBasis( S4 backing )
{
//Unpack the object slots once, here, so we don't have to do that for each access

if ( !backing.hasSlot("knots" ) ) [[unlikely]] stop(
"Spline basis expected to have slot `knots`!"
);
if ( !backing.hasSlot("knots" ) ) // [[unlikely]]
stop(
"Spline basis expected to have slot `knots`!"
);
_knots = (NumericVector)backing.slot("knots" );

if ( !backing.hasSlot("order" ) ) [[unlikely]] stop(
"Spline basis expected to have slot `order`!"
);
if ( !backing.hasSlot("order" ) ) // [[unlikely]]
stop(
"Spline basis expected to have slot `order`!"
);
_order = (int )backing.slot("order" );

if ( !backing.hasSlot("Matrices") ) [[unlikely]] stop(
"Spline basis expected to have slot `Matrices`!"
);
if ( !backing.hasSlot("Matrices") ) // [[unlikely]]
stop(
"Spline basis expected to have slot `Matrices`!"
);
_matrs = (NumericVector)backing.slot("Matrices");

if ( !_matrs.hasAttribute("dim") ) [[unlikely]] stop(
"Spline basis `Matrix` expected to have attribute `dim`!"
);
if ( !_matrs.hasAttribute("dim") ) // [[unlikely]]
stop(
"Spline basis `Matrix` expected to have attribute `dim`!"
);
_mdims = (IntegerVector)_matrs.attr("dim");

//!backing.hasSlot("class") -> "SplineBasis" (apparently optional)
Expand All @@ -41,7 +45,7 @@ SplineBasis::SplineBasis( S4 backing )
NumericVector ret( _mdims[1] );

//Out-of-range `x`; note test written so as to also catch NaN
if (!( x>=lo && x<=hi )) [[unlikely]]
if (!( x>=lo && x<=hi )) // [[unlikely]]
{
//print(" -> out of range\n");
ret.fill(NA_REAL);
Expand Down

0 comments on commit c8c28ea

Please sign in to comment.