diff options
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/function_base.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_function_base.py | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index 3396adf3d..6c0947cbf 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -79,6 +79,10 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None): """ num = int(num) + # Convert float/complex array scalars to float, gh-3504 + start = start + 0. + stop = stop + 0. + if dtype is None: dtype = result_type(start, stop, float(num)) diff --git a/numpy/core/tests/test_function_base.py b/numpy/core/tests/test_function_base.py index b43452e1c..7a746b601 100644 --- a/numpy/core/tests/test_function_base.py +++ b/numpy/core/tests/test_function_base.py @@ -1,8 +1,7 @@ from __future__ import division, absolute_import, print_function from numpy.testing import * -from numpy import logspace, linspace, dtype - +from numpy import logspace, linspace, dtype, array class TestLogspace(TestCase): @@ -55,3 +54,25 @@ class TestLinspace(TestCase): assert_equal(y.dtype, dtype('float64')) y = linspace(0, 6, dtype='int32') assert_equal(y.dtype, dtype('int32')) + + def test_array_scalar(self): + lim1 = array([-120, 100], dtype="int8") + lim2 = array([120, -100], dtype="int8") + lim3 = array([1200, 1000], dtype="uint16") + t1 = linspace(lim1[0], lim1[1], 5) + t2 = linspace(lim2[0], lim2[1], 5) + t3 = linspace(lim3[0], lim3[1], 5) + t4 = linspace(-120.0, 100.0, 5) + t5 = linspace(120.0, -100.0, 5) + t6 = linspace(1200.0, 1000.0, 5) + assert_equal(t1, t4) + assert_equal(t2, t5) + assert_equal(t3, t6) + + def test_complex(self): + lim1 = linspace(1 + 2j, 3 + 4j, 5) + t1 = array([ 1.0+2.j , 1.5+2.5j, 2.0+3.j , 2.5+3.5j, 3.0+4.j]) + lim2 = linspace(1j, 10, 5) + t2 = array([ 0.0+1.j , 2.5+0.75j, 5.0+0.5j , 7.5+0.25j, 10.0+0.j]) + assert_equal(lim1, t1) + assert_equal(lim2, t2)
\ No newline at end of file |