handle dst_bin_width==0 case properly (#18240)
authorJongsoo Park <jongsoo@fb.com>
Thu, 21 Mar 2019 00:02:38 +0000 (17:02 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 21 Mar 2019 00:11:25 +0000 (17:11 -0700)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18240

For rare cases when dst_bin_width == 0 we should just put all numbers to an arbitrary bin.

Reviewed By: csummersea

Differential Revision: D14544685

fbshipit-source-id: 02d04ff8bd1555d6cf7e7eeb1196a4ab3325a9e5

caffe2/quantization/server/dynamic_histogram.cc

index d86cb25..8b86e55 100644 (file)
@@ -212,8 +212,8 @@ const Histogram* DynamicHistogram::Finalize() {
       // The remainder should go to dst_bin2
       // rint is the fastest way to round
       // (https://stackoverflow.com/questions/485525/round-for-float-in-c/5849630)
-      uint64_t dst_bin_cnt = src_bin_width == 0
-          ? 0
+      uint64_t dst_bin_cnt = (src_bin_width == 0 || dst_bin_width == 0)
+          ? bins[i]
           : std::min(
                 static_cast<uint64_t>(rint(
                     (dst_bin_end - src_bin_begin) / src_bin_width * bins[i])),