Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Avoid Division by Zero #11397

Merged
merged 2 commits into from
Jul 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/operator/random/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down