Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ce3640

Browse files
committed
Merge pull request #4336 from Sankarshan-Mudkavi/fix-issue-3504
Fixed issue 3504
2 parents 87a9d5c + ba1e4df commit 8ce3640

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

numpy/core/function_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):
7979
"""
8080
num = int(num)
8181

82+
# Convert float/complex array scalars to float, gh-3504
83+
start = start + 0.
84+
stop = stop + 0.
85+
8286
if dtype is None:
8387
dtype = result_type(start, stop, float(num))
8488

numpy/core/tests/test_function_base.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from __future__ import division, absolute_import, print_function
22

33
from numpy.testing import *
4-
from numpy import logspace, linspace, dtype
5-
4+
from numpy import logspace, linspace, dtype, array
65

76
class TestLogspace(TestCase):
87

@@ -55,3 +54,25 @@ def test_dtype(self):
5554
assert_equal(y.dtype, dtype('float64'))
5655
y = linspace(0, 6, dtype='int32')
5756
assert_equal(y.dtype, dtype('int32'))
57+
58+
def test_array_scalar(self):
59+
lim1 = array([-120, 100], dtype="int8")
60+
lim2 = array([120, -100], dtype="int8")
61+
lim3 = array([1200, 1000], dtype="uint16")
62+
t1 = linspace(lim1[0], lim1[1], 5)
63+
t2 = linspace(lim2[0], lim2[1], 5)
64+
t3 = linspace(lim3[0], lim3[1], 5)
65+
t4 = linspace(-120.0, 100.0, 5)
66+
t5 = linspace(120.0, -100.0, 5)
67+
t6 = linspace(1200.0, 1000.0, 5)
68+
assert_equal(t1, t4)
69+
assert_equal(t2, t5)
70+
assert_equal(t3, t6)
71+
72+
def test_complex(self):
73+
lim1 = linspace(1 + 2j, 3 + 4j, 5)
74+
t1 = array([ 1.0+2.j , 1.5+2.5j, 2.0+3.j , 2.5+3.5j, 3.0+4.j])
75+
lim2 = linspace(1j, 10, 5)
76+
t2 = array([ 0.0+1.j , 2.5+0.75j, 5.0+0.5j , 7.5+0.25j, 10.0+0.j])
77+
assert_equal(lim1, t1)
78+
assert_equal(lim2, t2)

0 commit comments

Comments
 (0)