apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.75k stars 6.8k forks source link

Bug in nd.random.uniform() #20651

Open bandito90 opened 2 years ago

bandito90 commented 2 years ago

Description

According to the documentation of nd.random.uniform():

"Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high).

low (float or NDArray, optional) – Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.

high (float or NDArray, optional) – Upper boundary of the output interval. All values generated will be less than high. The default value is 1.0."

However, when sampling a random uniform with bi-dimensional shape for instance, we can have some entries equal to 1. See example below to reproduce the error.

To Reproduce

import mxnet as mx
from mxnet import nd

mx.random.seed(0)
shape = (233, 45)

u = nd.max(nd.random.uniform(shape=shape))
count = 0
while u != 1.:
    u = nd.max(nd.random.uniform(shape=shape))
    count += 1
print(f"Got {u} after {count} iterations")
github-actions[bot] commented 2 years ago

Welcome to Apache MXNet (incubating)! We are on a mission to democratize AI, and we are glad that you are contributing to it by opening this issue. Please make sure to include all the relevant context, and one of the @apache/mxnet-committers will be here shortly. If you are interested in contributing to our project, let us know! Also, be sure to check out our guide on contributing to MXNet and our development guides wiki.