Skip to content

Conversation

@forfudan
Copy link
Collaborator

The random module was created at quite an early stage. A lot of things should be re-considered. This PR aims to refactor the random module by:

  1. Aligning the functional behaviors as much as possible with numpy while keeping internal consistency of style: The shape always comes as the first argument.
  2. For all functions, accept shape as an NDArrayShape. Meanwhile, we still provide overloads for *shape: Int. (shape: List[Int] is also possible but not recommened).
  3. rand now generates uniformed distributed values and does not accept integral types.
  4. randint is added to generate random integral values based on low and high. add tests for it.
  5. random_exponential is renamed as exponential (same as numpy)[https://numpy.org/doc/stable/reference/random/generated/numpy.random.exponential.html#numpy.random.exponential].

@forfudan forfudan changed the title [routine][random] Refactor the random module to unify behaviors + add randint [routine][random] Update the random module + unify behaviors + add randint Jan 27, 2025
@MadAlex1997 MadAlex1997 merged commit 539af95 into Mojo-Numerics-and-Algorithms-group:pre-0.6 Jan 28, 2025
2 checks passed
@forfudan forfudan deleted the random branch January 28, 2025 21:46
forfudan added a commit to forfudan/NuMojo that referenced this pull request Jan 28, 2025
commit 539af95
Author: ZHU Yuhao 朱宇浩 <[email protected]>
Date:   Tue Jan 28 22:14:28 2025 +0100

    [routine][random] Update the random module + unify behaviors + add `randint` (Mojo-Numerics-and-Algorithms-group#199)

    The `random` module was created at quite an early stage. A lot of things
    should be re-considered. This PR aims to refactor the random module by:

    1. Aligning the functional behaviors as much as possible with `numpy`
    while keeping internal consistency of style: The `shape` always comes as
    the first argument.
    2. For all functions, accept `shape` as an `NDArrayShape`. Meanwhile, we
    still provide overloads for `*shape: Int`. (`shape: List[Int]` is also
    possible but not recommened).
    3. `rand` now generates uniformed distributed values and does not accept
    integral types.
    4. `randint` is added to generate random integral values based on `low`
    and `high`. add tests for it.
    5. `random_exponential` is renamed as `exponential` (same as
    numpy)[https://numpy.org/doc/stable/reference/random/generated/numpy.random.exponential.html#numpy.random.exponential].
forfudan added a commit to forfudan/NuMojo that referenced this pull request Jan 30, 2025
…andint` (Mojo-Numerics-and-Algorithms-group#199)

The `random` module was created at quite an early stage. A lot of things
should be re-considered. This PR aims to refactor the random module by:

1. Aligning the functional behaviors as much as possible with `numpy`
while keeping internal consistency of style: The `shape` always comes as
the first argument.
2. For all functions, accept `shape` as an `NDArrayShape`. Meanwhile, we
still provide overloads for `*shape: Int`. (`shape: List[Int]` is also
possible but not recommened).
3. `rand` now generates uniformed distributed values and does not accept
integral types.
4. `randint` is added to generate random integral values based on `low`
and `high`. add tests for it.
5. `random_exponential` is renamed as `exponential` (same as
numpy)[https://numpy.org/doc/stable/reference/random/generated/numpy.random.exponential.html#numpy.random.exponential].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants