Skip to content

Commit

Permalink
BUG: Backport r8619 to fix ticked #1554.
Browse files Browse the repository at this point in the history
  • Loading branch information
charris committed Aug 11, 2010
1 parent 3367031 commit 2befa5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
13 changes: 7 additions & 6 deletions numpy/polynomial/polyutils.py
Expand Up @@ -289,8 +289,8 @@ def mapparms(old, new) :
Parameters
----------
old, new : array_like
Each domain must (successfully) convert to a 1-d array containing
precisely two values.
Domains. Each domain must (successfully) convert to a 1-d array
containing precisely two values.
Returns
-------
Expand Down Expand Up @@ -330,13 +330,14 @@ def mapdomain(x, old, new) :
"""
Apply linear map to input points.
The linear map ``offset + scale*x`` that maps `old` to `new` is applied
to the points `x`.
The linear map ``offset + scale*x`` that maps the domain `old` to
the domain `new` is applied to the points `x`.
Parameters
----------
x : array_like
Points to be mapped.
Points to be mapped. If `x` is a subtype of ndarray the subtype
will be preserved.
old, new : array_like
The two domains that determine the map. Each must (successfully)
convert to 1-d arrays containing precisely two values.
Expand Down Expand Up @@ -388,6 +389,6 @@ def mapdomain(x, old, new) :
array([-1.0+1.j , -0.6+0.6j, -0.2+0.2j, 0.2-0.2j, 0.6-0.6j, 1.0-1.j ])
"""
[x] = as_series([x], trim=False)
x = np.asanyarray(x)
off, scl = mapparms(old, new)
return off + scl*x
18 changes: 17 additions & 1 deletion numpy/polynomial/tests/test_polyutils.py
Expand Up @@ -67,9 +67,25 @@ def test_mapdomain(self) :
dom1 = [0 - 1j, 2 + 1j]
dom2 = [-2, 2]
tgt = dom2
res = pu.mapdomain(dom1, dom1, dom2)
x = dom1
res = pu.mapdomain(x, dom1, dom2)
assert_almost_equal(res, tgt)

# test for multidimensional arrays
dom1 = [0,4]
dom2 = [1,3]
tgt = np.array([dom2, dom2])
x = np.array([dom1, dom1])
res = pu.mapdomain(x, dom1, dom2)
assert_almost_equal(res, tgt)

# test that subtypes are preserved.
dom1 = [0,4]
dom2 = [1,3]
x = np.matrix([dom1, dom1])
res = pu.mapdomain(x, dom1, dom2)
assert_(isinstance(res, np.matrix))

def test_mapparms(self) :
# test for real values
dom1 = [0,4]
Expand Down

0 comments on commit 2befa5f

Please sign in to comment.