Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ht.random.randint size type requirement inconsistent with NumPy API #913

Closed
ClaudiaComito opened this issue Feb 8, 2022 · 0 comments · Fixed by #916
Closed

ht.random.randint size type requirement inconsistent with NumPy API #913

ClaudiaComito opened this issue Feb 8, 2022 · 0 comments · Fixed by #916
Assignees
Labels
API Anything relating the API

Comments

@ClaudiaComito
Copy link
Contributor

ClaudiaComito commented Feb 8, 2022

Description
int type should be allowed for size argument of ht.random.randint()

>>> import numpy as np
>>> import heat as ht
# numpy
>>> a = np.random.randint(0, 50, 20)
>>> a
array([34, 30, 43, 37, 39, 15,  9, 19, 38, 19, 12, 14, 41, 32, 44,  2,  5,
        0,  6, 45])
>>> a = np.random.randint(0, 50, size=20)
>>> a
array([10,  6, 38, 19, 10, 44,  9, 40, 23, 40, 23, 46, 41, 40,  7,  3, 15,
       25, 39, 46])

#heat
>>> b = ht.random.randint(0, 50, 20)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/c.comito/HAF/heat/heat/core/random.py", line 531, in randint
    shape = tuple(int(ele) for ele in size)
TypeError: 'int' object is not iterable

>>> b = ht.random.randint(0, 50, size=20)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/c.comito/HAF/heat/heat/core/random.py", line 531, in randint
    shape = tuple(int(ele) for ele in size)
TypeError: 'int' object is not iterable

 b = ht.random.randint(0, 50, size=(20,))
>>> b
DNDarray([13, 33,  0, 41,  6, 40, 39,  5, 34, 44,  3, 39,  1, 44, 25, 14, 25, 39, 41,  8], dtype=ht.int32, device=cpu:0, split=None)
>>> 

To Reproduce
Steps to reproduce the behavior:

see examples above

Expected behavior
it should be possible to pass an int as size argument, also in accordance with the function's type hints: size: 'Optional[Union[int, Tuple[int]]]' = None

Version Info
main branch

@ClaudiaComito ClaudiaComito added the API Anything relating the API label Feb 8, 2022
@mtar mtar mentioned this issue Feb 8, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Anything relating the API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants