mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Handle the corner case when min == max in L2 search (#70207)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/70207 In corner case when min == max, adjust_hist_to_include_zero() function used in L2 search will cause additional_nbins = -2147483648 and initialize bins_f with negative size. Test Plan: Before fix: f315187213 After fix: f315471862 Reviewed By: jspark1105 Differential Revision: D33227717 fbshipit-source-id: 7e8a455e51a0703a3a9c5eb7595d9b4d43966001
This commit is contained in:
parent
f17e76b0f2
commit
6623c4838e
|
|
@ -309,6 +309,7 @@ adjust_hist_to_include_zero(const Histogram& hist, float* min, float* max) {
|
|||
// Pad histogram to include zero
|
||||
int additional_nbins = 0;
|
||||
int offset = 0;
|
||||
if (bin_width > 0) {
|
||||
if (*min > 0) {
|
||||
// additional nbins to include 0
|
||||
additional_nbins = ceil(*min / bin_width);
|
||||
|
|
@ -322,6 +323,7 @@ adjust_hist_to_include_zero(const Histogram& hist, float* min, float* max) {
|
|||
*max += additional_nbins * bin_width;
|
||||
assert(*max >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
vector<float> bins_f(nbins + additional_nbins);
|
||||
for (int i = 0; i < nbins; ++i) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user