This is an automated email from the ASF dual-hosted git repository.

zhreshold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b8b939  Avoid Division by Zero (#11397)
0b8b939 is described below

commit 0b8b93995e253f362399de1e2e8c63d112933289
Author: Todd Sundsted <[email protected]>
AuthorDate: Wed Jul 25 13:52:15 2018 -0400

    Avoid Division by Zero (#11397)
    
    * Return if iteration counter `N` is less than or equal to zero.
    
    * Fix spelling.
---
 src/operator/random/sampler.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/operator/random/sampler.h b/src/operator/random/sampler.h
index e211e75..44f80ab 100644
--- a/src/operator/random/sampler.h
+++ b/src/operator/random/sampler.h
@@ -38,12 +38,17 @@ namespace op {
  * \brief Launch a generic kernel with parallel random generator.
  * \tparam gen random generator
  * \tparam N Number of iterations
- * \tparam Args Varargs type to eventually pass to the OP::Map() functoion
+ * \tparam Args Varargs type to eventually pass to the OP::Map() function
  */
 template<typename OP, typename xpu, typename GType, typename ...Args>
 inline static void LaunchRNG(mshadow::Stream<xpu> *s,
                              common::random::RandGenerator<xpu, GType> *gen,
                              const int N, Args... args) {
+  // minimal check to avoid division by zero, below.
+  // if `N` is zero the map operation is a no-op in any case.
+  if (N <= 0) {
+    return;
+  }
   const int nloop = (N + RandGenerator<xpu>::kMinNumRandomPerThread - 1) /
                     RandGenerator<xpu>::kMinNumRandomPerThread;
   const int nthread = std::min(nloop, RandGenerator<xpu>::kNumRandomStates);

Reply via email to