# [Numpy-svn] r8619 - in trunk/numpy/polynomial: . tests

numpy-svn@scip... numpy-svn@scip...
Tue Aug 10 20:18:21 CDT 2010

```Author: charris
Date: 2010-08-10 20:18:21 -0500 (Tue, 10 Aug 2010)
New Revision: 8619

Modified:
trunk/numpy/polynomial/polyutils.py
trunk/numpy/polynomial/tests/test_polyutils.py
Log:
BUG: Make mapdomain work for multidimensional arrays as advertized in
the documentation. Fixes ticket #1554.

Modified: trunk/numpy/polynomial/polyutils.py
===================================================================
--- trunk/numpy/polynomial/polyutils.py	2010-08-10 17:32:02 UTC (rev 8618)
+++ trunk/numpy/polynomial/polyutils.py	2010-08-11 01:18:21 UTC (rev 8619)
@@ -289,8 +289,8 @@
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
-------
@@ -330,13 +330,14 @@
"""
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.
@@ -388,6 +389,6 @@
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

Modified: trunk/numpy/polynomial/tests/test_polyutils.py
===================================================================
--- trunk/numpy/polynomial/tests/test_polyutils.py	2010-08-10 17:32:02 UTC (rev 8618)
+++ trunk/numpy/polynomial/tests/test_polyutils.py	2010-08-11 01:18:21 UTC (rev 8619)
@@ -67,9 +67,25 @@
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]

```