<div class="gmail_quote">On Sun, Mar 8, 2009 at 12:31 PM, Darren Dale <span dir="ltr"><<a href="mailto:dsdale24@gmail.com">dsdale24@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="gmail_quote"><div class="im">On Wed, Jan 21, 2009 at 12:43 PM, Pierre GM <span dir="ltr"><<a href="mailto:pgmdevlist@gmail.com" target="_blank">pgmdevlist@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br>
On Jan 21, 2009, at 11:34 AM, Darren Dale wrote:<br>
<br>
> I have a simple test script here that multiplies an ndarray subclass<br>
> with another number. Can anyone help me understand why each of these<br>
> combinations returns a new instance of MyArray:<br>
><br>
> mine = MyArray()<br>
> print type(np.float32(1)*mine)<br>
> print type(mine*np.float32(1))<br>
> print type(mine*np.float64(1))<br>
> print type(1*mine)<br>
> print type(mine*1)<br>
><br>
> but this one returns a np.float64 instance?<br>
<br>
</div>FYI, that's the same behavior as observed in ticket #826. A first<br>
thread addressed that issue<br>
<a href="http://www.mail-archive.com/numpy-discussion@scipy.org/msg13235.html" target="_blank">http://www.mail-archive.com/numpy-discussion@scipy.org/msg13235.html</a><br>
But so far, no answer has been suggested.<br>
Any help welcome.</blockquote></div><div><br>I believe ticket #826 can be solved with the application of this patch:<br><br> <br></div></div>$ svn diff scalarmathmodule.c.src<br>Index: scalarmathmodule.c.src<br>===================================================================<br>

--- scalarmathmodule.c.src      (revision 6566)<br>+++ scalarmathmodule.c.src      (working copy)<br>@@ -566,6 +566,10 @@<br>         Py_DECREF(descr1);<br>         return ret;<br>     }<br>+    else if (PyArray_GetPriority(a, PyArray_SUBTYPE_PRIORITY) > \<br>

+            PyArray_SUBTYPE_PRIORITY) {<br>+        return -2;<br>+    }<br>     else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {<br>         int retval;<br>         retval = _@name@_convert_to_ctype(temp, arg1);<br>

<br><br>I've run the unit tests and get the same results with and without the patch applied, but it solves the problem in my script and also the problem with masked arrays.<font color="#888888"></font></blockquote><div>
<br>Here is a test for this patch, maybe issue #826 can be closed.<br><br>Index: numpy/core/tests/test_umath.py<br>===================================================================<br>--- numpy/core/tests/test_umath.py      (revision 6575)<br>
+++ numpy/core/tests/test_umath.py      (working copy)<br>@@ -253,6 +253,17 @@<br>         self.failUnless(isinstance(x, with_wrap))<br>         assert_array_equal(x, np.array((1, 2, 3)))<br><br>+    def test_priority_with_scalar(self):<br>
+        # test fix for bug #826:<br>+        class A(np.ndarray):<br>+            __array_priority__ = 10<br>+            def __new__(cls):<br>+                return np.asarray(1.0, 'float64').view(cls).copy()<br>
+        a = A()<br>+        x = np.float64(1)*a<br>+        self.failUnless(isinstance(x, A))<br>+        assert_array_equal(x, np.array(1))<br>+<br>     def test_old_wrap(self):<br>         class with_wrap(object):<br>             def __array__(self): <br>
</div></div>