summaryrefslogtreecommitdiff
path: root/numpy/core/function_base.py
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2016-01-30 15:56:11 -0500
committerMarten van Kerkwijk <mhvk@astro.utoronto.ca>2016-01-31 16:24:42 -0500
commit0aa03bef711e57220ad5286f68363e6aca7cdfad (patch)
tree93dc6f24f01d68f1503b554491a0b4687ccdfb7d /numpy/core/function_base.py
parent0bba66540744223b3a10b76ef212780448bef874 (diff)
downloadnumpy-0aa03bef711e57220ad5286f68363e6aca7cdfad.tar.gz
Reascertain that linspace respects ndarray subclasses in start, stop.
Diffstat (limited to 'numpy/core/function_base.py')
-rw-r--r--numpy/core/function_base.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py
index c82c9bb6b..21ca1af01 100644
--- a/numpy/core/function_base.py
+++ b/numpy/core/function_base.py
@@ -96,18 +96,23 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):
y = _nx.arange(0, num, dtype=dt)
+ delta = stop - start
if num > 1:
- delta = stop - start
step = delta / div
if step == 0:
# Special handling for denormal numbers, gh-5437
y /= div
- y *= delta
+ y = y * delta
else:
- y *= step
+ # One might be tempted to use faster, in-place multiplication here,
+ # but this prevents step from overriding what class is produced,
+ # and thus prevents, e.g., use of Quantities; see gh-7142.
+ y = y * step
else:
# 0 and 1 item long sequences have an undefined step
step = NaN
+ # Multiply with delta to allow possible override of output class.
+ y = y * delta
y += start