8000 ldexp broken (Trac #866) · Issue #1464 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ldexp broken (Trac #866) #1464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 9 comments
Closed

ldexp broken (Trac #866) #1464

numpy-gitbot opened this issue Oct 19, 2012 · 9 comments

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/866 on 2008-07-29 by @huard, assigned to @cournape.

> [3]: np.ldexp(.4, 5)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/storage/huardda/10kmf90/python/<ipython console> in <module>()

TypeError: function not supported for these types, and can't coerce safely to supported types

On Fedora 9, gcc 4.3.0, NumPy 1.2.0.dev5566

@numpy-gitbot
Copy link
Author

@cournape wrote on 2008-09-01

Which platform are you using ? (64 vs 32). It works for me on ubuntu 32 bits with gcc 4.2

@numpy-gitbot
Copy link
Author

@huard wrote on 2008-09-02

Replying to [comment:1 cdavid]:

Which platform are you using ? (64 vs 32). It works for me on ubuntu 32 bits with gcc 4.2

64 bits and gcc 4.3.0

@numpy-gitbot
Copy link
Author

@huard wrote on 2008-09-04

The umathmodule defines

ldexp(double x1, int x2) 
ldexpf(float x1, int x2)
ldexpl(longdouble x1, int x2)

But since the default int on 64 bits platform is a long, we would need to define as well

ldexpfl(float x1, long x2) 
ldexpdl(double x1, long x2) 
ldexpll(longdouble x1, long x2)

Now since ldexp returns x1 * 2 ** x2, an a 32 bit integer spans [-231 + 1, 231 -1], I doubt long x2 are really useful. I suggest long x2 are simply cast to int x2. Don't really know where this should be done though.

@numpy-gitbot
Copy link
Author

@huard wrote on 2008-09-04

In umathmodule.c.src, if I change !PyArray_INT by !PyArray_Long as in the following, ldexp works. This might not be THE solution, but this is as far as I can go for now. Here is a patch for someone familiar with ufuncs to review and test on a 32 bit platform.

Index: numpy/core/src/umathmodule.c.src
===================================================================
--- numpy/core/src/umathmodule.c.src    (revision 5752)
+++ numpy/core/src/umathmodule.c.src    (working copy)
@@ -2187,9 +2187,9 @@
 #ifdef HAVE_FLOAT_FUNCS
     PyArray_FLOAT, PyArray_INT, PyArray_FLOAT,
 #endif
-    PyArray_DOUBLE, PyArray_INT, PyArray_DOUBLE
+    PyArray_DOUBLE, PyArray_LONG, PyArray_DOUBLE
 #ifdef HAVE_LONGDOUBLE_FUNCS
-    ,PyArray_LONGDOUBLE, PyArray_INT, PyArray_LONGDOUBLE
+    ,PyArray_LONGDOUBLE, PyArray_LONG, PyArray_LONGDOUBLE
 #endif
 };

Index: numpy/core/tests/test_umath.py
===================================================================
--- numpy/core/tests/test_umath.py  (revision 5752)
+++ numpy/core/tests/test_umath.py  (working copy)
@@ -47,6 +47,10 @@
         assert_almost_equal(ncu.expm1(0.2), ncu.exp(0.2)-1)
         assert_almost_equal(ncu.expm1(1e-6), ncu.exp(1e-6)-1)

+class TestLdexp(TestCase):
+    def test_ldexp(self):
+        assert_almost_equal(ncu.ldexp(2., 3),  16.)
+
 class TestMaximum(TestCase):
     def test_reduce_complex(self):
         assert_equal(ncu.maximum.reduce([1,2j]),1)

@numpy-gitbot
Copy link
Author

@charris wrote on 2010-05-25

I think we should make this fix.

@numpy-gitbot
Copy link
Author

@huard wrote on 2010-05-25

Commited in r8438. Please test on 32 bits.

@numpy-gitbot
Copy link
Author

@charris wrote on 2010-05-25

This passes on the 32 bit buildbots after r8438, so close the ticket.

@numpy-gitbot
Copy link
Author

@charris wrote on 2010-05-25

However, I think your test should cover all three floating types.

@numpy-gitbot
Copy link
Author

@huard wrote on 2010-05-25

Added tests for float96 in r8439. I don't have permissions to close tickets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant
0