diff options
author | jaimefrio <jaime.frio@gmail.com> | 2015-01-10 17:51:45 -0800 |
---|---|---|
committer | jaimefrio <jaime.frio@gmail.com> | 2015-01-10 20:43:43 -0800 |
commit | 9d9e5a143757a82f85415b17ec797ec9706ecf3a (patch) | |
tree | 85ac718798531ee2697be2c7db4fc9252e42b89b /numpy/core/function_base.py | |
parent | aaf5429e327c098ccf25ac4ab901348ff662847b (diff) | |
download | numpy-9d9e5a143757a82f85415b17ec797ec9706ecf3a.tar.gz |
BUG: linspace handling of denormals, fixes #5437
Diffstat (limited to 'numpy/core/function_base.py')
-rw-r--r-- | numpy/core/function_base.py | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index 7e52276ea..4361dc2e1 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -11,7 +11,7 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None): Return evenly spaced numbers over a specified interval. Returns `num` evenly spaced samples, calculated over the - interval [`start`, `stop` ]. + interval [`start`, `stop`]. The endpoint of the interval can optionally be excluded. @@ -83,28 +83,45 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None): """ num = int(num) - # Convert float/complex array scalars to float, gh-3504 + # Convert float/complex array scalars to float, gh-3504 start = start * 1. stop = stop * 1. + dt = result_type(start, stop, float(num)) if dtype is None: - dtype = result_type(start, stop, float(num)) + dtype = dt if num <= 0: return array([], dtype) + if num == 1: + return array([start], dtype=dtype) + y = _nx.arange(0, num, dtype=dt) + if endpoint: + num -= 1 + y /= num + y *= stop - start + y += start if endpoint: - if num == 1: - return array([start], dtype=dtype) - step = (stop-start)/float((num-1)) - y = _nx.arange(0, num, dtype=dtype) * step + start y[-1] = stop - else: - step = (stop-start)/float(num) - y = _nx.arange(0, num, dtype=dtype) * step + start + if retstep: - return y.astype(dtype), step + return y.astype(dtype, copy=False), (stop - start) / num else: - return y.astype(dtype) + return y.astype(dtype, copy=False) + + # if endpoint: + # if num == 1: + # return array([start], dtype=dtype) + # step = (stop-start)/float((num-1)) + # y = _nx.arange(0, num, dtype=dtype) * step + start + # y[-1] = stop + # else: + # step = (stop-start)/float(num) + # y = _nx.arange(0, num, dtype=dtype) * step + start + # if retstep: + # return y.astype(dtype), step + # else: + # return y.astype(dtype) def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None): |