Skip to content

Commit 07ebd6c

Browse files
committed
fixed an affinity_propagation.h cran warning
1 parent 4779bd0 commit 07ebd6c

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
^pkgdown$
88
^.*\.Rproj$
99
^\.Rproj\.user$
10+
^\.vscode$

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ docs/
22
.Rhistory
33
docs
44
.Rproj.user
5+
.vscode/

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## ClusterR 1.3.6
33

44
* The `Optimal_Clusters_GMM` function was updated (https://github.com/mlampros/ClusterR/pull/70)
5+
* Fixed an `affinity_propagation` warning (`/inst/include/affinity_propagation.h: warning: overflow in conversion from 'double' to 'long long unsigned int' changes value from '+QNaN' to '0' [-Woverflow]`) in lines 360 and 448 of the `affinity_propagation.h` file
56

67

78
## ClusterR 1.3.5

inst/include/affinity_propagation.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Rcpp::List Affinity_Propagation::affinity_propagation(arma::mat &s, std::vector<
268268

269269
int tmpdpsim = 0; // initialize 'tmpdpsim' to 0 . By setting this to 'arma::datum::nan' it gives "runtime error: nan is outside the range of representable values of type 'int'" ( clang-UBSAN )
270270
int tmpnetsim,tmpexpref;
271-
arma::uvec tmpidx;
271+
arma::vec tmpidx;
272272
bool unconverged = true; // unconverged set initially to 'true' [ see line 478 ]
273273

274274
while (!dn) {
@@ -357,7 +357,7 @@ Rcpp::List Affinity_Propagation::affinity_propagation(arma::mat &s, std::vector<
357357
tmpdpsim = 0; // same as line 352
358358
tmpexpref = 0; // same as line 352
359359
tmpidx.set_size(N);
360-
tmpidx.fill(arma::datum::nan); // 'tmpidx' can take 'arma::datum::nan' because it is initialized as 'arma::uvec' ( of type double )
360+
tmpidx.fill(arma::datum::nan); // 'tmpidx' can take 'arma::datum::nan' because it is a vector of type double
361361
}
362362
else {
363363
arma::uvec I = arma::find(E == 1); // 'I' can be empty or having 1 or more items
@@ -369,9 +369,10 @@ Rcpp::List Affinity_Propagation::affinity_propagation(arma::mat &s, std::vector<
369369
arma::uvec tmp_c = arma::unique(c);
370370
arma::uvec tmp_Ic = I(c);
371371
c(I) = arma::regspace<arma::uvec>( 0, 1, K-1 );
372-
tmpidx = I(c);
372+
tmpidx = arma::conv_to<arma::vec>::from(I(c));
373373
arma::umat tmp_um(2, notI.n_elem);
374-
arma::uvec tmp_v_um = tmpidx(notI);
374+
arma::uvec tmpidx_uvec = arma::conv_to<arma::uvec>::from(tmpidx);
375+
arma::uvec tmp_v_um = tmpidx_uvec(notI);
375376
for (unsigned int f = 0; f < notI.n_elem; f++) {
376377
tmp_um(0,f) = notI(f);
377378
tmp_um(1,f) = tmp_v_um(f);
@@ -397,8 +398,7 @@ Rcpp::List Affinity_Propagation::affinity_propagation(arma::mat &s, std::vector<
397398
dpsim.col(i-1) = tmpdpsim;
398399
expref.col(i-1) = tmpexpref;
399400

400-
arma::uvec tmp_unq = arma::unique(tmpidx);
401-
idx.col(i-1) = arma::conv_to<arma::colvec>::from(tmpidx);
401+
idx.col(i-1) = tmpidx;
402402
}
403403
} // end of while loop
404404

@@ -423,9 +423,10 @@ Rcpp::List Affinity_Propagation::affinity_propagation(arma::mat &s, std::vector<
423423
arma::uvec notI = matlab_setdiff(arma::regspace<arma::uvec>( 0, 1, N-1 ), I); // converted 'N' to 'N-1' due to dif in indexing compared to matlab && I didn't use reshape() compared to initial code
424424
c = arma::index_max(S.cols(I), 1);
425425
c(I) = arma::regspace<arma::uvec>( 0, 1, K-1 ); // Identify clusters [ converted 'K' to 'K-1' due to dif in indexing compared to matlab ]
426-
tmpidx = I(c);
426+
tmpidx = arma::conv_to<arma::vec>::from(I(c));
427427
arma::umat tmp_um(2, notI.n_elem);
428-
arma::uvec tmp_v_um = tmpidx(notI);
428+
arma::uvec tmpidx_uvec = arma::conv_to<arma::uvec>::from(tmpidx);
429+
arma::uvec tmp_v_um = tmpidx_uvec(notI);
429430
for (unsigned int f = 0; f < notI.n_elem; f++) {
430431
tmp_um(0,f) = notI(f);
431432
tmp_um(1,f) = tmp_v_um(f);
@@ -445,7 +446,7 @@ Rcpp::List Affinity_Propagation::affinity_propagation(arma::mat &s, std::vector<
445446
}
446447
else {
447448
tmpidx.set_size(N);
448-
tmpidx.fill(arma::datum::nan); // 'tmpidx' can take 'arma::datum::nan' because it is initialized as 'arma::uvec' ( of type double )
449+
tmpidx.fill(arma::datum::nan); // 'tmpidx' can take 'arma::datum::nan' because it is a vector of type double
449450
tmpnetsim = 0; // initialize this to 0. By setting it to 'arma::datum::nan' it gives "runtime error: nan is outside the range of representable values of type 'int'" ( clang-UBSAN )
450451
tmpexpref = 0; // same as line 445
451452
}
@@ -457,14 +458,14 @@ Rcpp::List Affinity_Propagation::affinity_propagation(arma::mat &s, std::vector<
457458
dpsim = dpsim.submat(0, 0, 0, i);
458459
expref(i) = tmpexpref;
459460
expref=expref.submat(0, 0, 0, i);
460-
idx.col(i) = arma::conv_to<arma::colvec>::from(tmpidx);
461+
idx.col(i) = tmpidx;
461462
idx = idx.submat(0, 0, N-1, i);
462463
}
463464
else {
464465
netsim=tmpnetsim;
465466
dpsim=tmpdpsim;
466467
expref=tmpexpref;
467-
idx = arma::conv_to<arma::mat>::from(tmpidx);
468+
idx = tmpidx;
468469
}
469470

470471
double n_time = timer.toc();

0 commit comments

Comments
 (0)