Skip to content

Commit

Permalink
Fix overflow issue with large matrices (fixes shogun-toolbox#4595)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed May 2, 2019
1 parent ac8873a commit 3c9c24e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/shogun/statistical_testing/internals/mmd/ComputeMMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ struct ComputeMMD
terms.diag[1]=b_y.diagonal().sum();
terms.diag[2]=b_xy.diagonal().sum();

terms.term[0]=(b_x.sum()-terms.diag[0])/2+terms.diag[0];
terms.term[1]=(b_y.sum()-terms.diag[1])/2+terms.diag[1];
terms.term[2]=b_xy.sum();
// cast to 64 bit to avoid overflows
terms.term[0]=(b_x. template cast<float64_t>().sum()-terms.diag[0])/2+terms.diag[0];
terms.term[1]=(b_y. template cast<float64_t>().sum()-terms.diag[1])/2+terms.diag[1];
terms.term[2]=b_xy. template cast<float64_t>().sum();

return compute(terms);
}
Expand Down

0 comments on commit 3c9c24e

Please sign in to comment.