diff options
author | Kaspar Thommen <49198627+kasparthommen@users.noreply.github.com> | 2020-06-10 22:50:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 23:50:43 +0300 |
commit | 0ac02d3819157a9c64b78157428336200632cff8 (patch) | |
tree | 9a834e03fc3a1819166d499da044efc8dd69a58e /numpy/core/function_base.py | |
parent | d0928f871ccb42484c7e03c456ce489dea908313 (diff) | |
download | numpy-0ac02d3819157a9c64b78157428336200632cff8.tar.gz |
BUG: endpoints of array returned by geomspace() should match arguments (#16411)
* BUG: make sure the endpoints of the array returned by geomspace() matches the 'start' and 'stop' arguments exactly
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Diffstat (limited to 'numpy/core/function_base.py')
-rw-r--r-- | numpy/core/function_base.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index 9e46f0ea5..946e255c1 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -408,8 +408,18 @@ def geomspace(start, stop, num=50, endpoint=True, dtype=None, axis=0): log_start = _nx.log10(start) log_stop = _nx.log10(stop) - result = out_sign * logspace(log_start, log_stop, num=num, - endpoint=endpoint, base=10.0, dtype=dtype) + result = logspace(log_start, log_stop, num=num, + endpoint=endpoint, base=10.0, dtype=dtype) + + # Make sure the endpoints match the start and stop arguments. This is + # necessary because np.exp(np.log(x)) is not necessarily equal to x. + if num > 0: + result[0] = start + if num > 1 and endpoint: + result[-1] = stop + + result = out_sign * result + if axis != 0: result = _nx.moveaxis(result, 0, axis) |