Change linspace creation to match numpy when num equal to 0#8676
Change linspace creation to match numpy when num equal to 0#8676
Conversation
|
Can one of the admins verify this patch? |
|
Thanks for the fix @peterpandelidis. There's another case that would be worth fixing too: if >>> import numpy as np
>>> np.linspace(0, 0, 1)
array([0.])
>>> import dask.array as da
>>> da.linspace(0, 0, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/tom/projects-workspace/dask/dask/array/creation.py", line 303, in linspace
step = float(range_) / div
ZeroDivisionError: float division by zero |
|
Made a change for the above. Not the most elegant solution, but it works. |
|
@tomwhite do you have thoughts on the change above? |
dask/array/creation.py
Outdated
| range_ = stop - start | ||
|
|
||
| div = (num - 1) if endpoint else num | ||
| div = (num - 1) if (endpoint and num != 1) or num == 0 else num |
There was a problem hiding this comment.
It seems a bit odd that if num is zero then div is negative - even if the tests all pass. Would this be better?
div = (num - 1) if endpoint else num
if div == 0:
div = 1There was a problem hiding this comment.
I find that first statement hard to read, so yeah I like your suggestion.
There was a problem hiding this comment.
@peterpandelidis What do you think about this suggestion?
There was a problem hiding this comment.
Yeah, I agree with the suggestion.
I've been away for a bit so haven't updated the PR.
Will update tonight.
|
ok to test |
tomwhite
left a comment
There was a problem hiding this comment.
LGTM. Thanks for updating this @peterpandelidis.
|
Thanks for working on this @peterpandelidis and thanks @tomwhite for reviewing! |
|
Thanks all! 😄 |
linspacedivision by zero error #8670pre-commit run --all-files