Upgrade to 1.6.x: frompyfunc() ufunc casting issue
![](https://secure.gravatar.com/avatar/c3e2d2fc63a0016d3a4ffa493daf9655.jpg?s=120&d=mm&r=g)
Hi all, I am facing an issue upgrading numpy from 1.5.1 to 1.6.1. In numPy 1.6, the casting behaviour for ufunc has changed and has become stricter. Can someone advise how to implement the below simple example which worked in 1.5.1 but fails in 1.6.1?
Thanks, Aditya
![](https://secure.gravatar.com/avatar/c3e2d2fc63a0016d3a4ffa493daf9655.jpg?s=120&d=mm&r=g)
Hi Stefan, The problem arises when you try to use methods of the ufunc. So for the custom universal function previously defined, uadd: uadd([1,2,3],[1,2,3]) works fine. But uadd.accumulate(..) or uadd.reduce(..) fail with error: ValueError: could not find a matching type for add (vectorized).accumulate ( or (vectorized).reduce ) Apologies, I should have been more clear before. Thanks, Aditya 2011/9/19 Stéfan van der Walt <stefan@sun.ac.za>
![](https://secure.gravatar.com/avatar/c3e2d2fc63a0016d3a4ffa493daf9655.jpg?s=120&d=mm&r=g)
Hi, Stefan, which version of Python and NumPy are you using? I am upgrading Python and NumPy, and would like to get it working on the official releases of Python 2.7.2 + NumPy 1.6.1 In Python 2.6 + NumPy 1.5.1 on win32, it works. In Python 2.7.2 + NumPy 1.6.1 on win32, np.frompyfunc(add,2,1).accumulate definitely gives an error. Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
Aditya 2011/9/19 Stéfan van der Walt <stefan@sun.ac.za>
![](https://secure.gravatar.com/avatar/a5cbd07efd53a3e16124de3829abec0e.jpg?s=120&d=mm&r=g)
He is using the development version of Numpy, which is probably the main difference (I tried it too with Numpy 1.6.1 on an x86_64 Linux architecture and got the same bug). If you want to use an official Numpy release you'll probably need to downgrade to 1.5.x and wait until the next Numpy release. -=- Olivier 2011/9/20 Aditya Sethi <ady.sethi@gmail.com>
![](https://secure.gravatar.com/avatar/f4480fb86ce05c4e2ee38e796715e64e.jpg?s=120&d=mm&r=g)
Hi everyone, A long time ago, Aditya Sethi <ady.sethi@gmail... wrote:
Here's the workaround I found to that problem:
uadd.accumulate([1,2,3], dtype='object') array([1, 3, 6], dtype=object)
It seems like "accumulate" infers that 'l' is the required output dtype, but does not have the appropriate implementation:
uadd.types ['OO->O']
Forcing the output dtype to be 'object' (the only supported dtype) seems to do the trick. Hope this helps, -- Pascal
![](https://secure.gravatar.com/avatar/c3e2d2fc63a0016d3a4ffa493daf9655.jpg?s=120&d=mm&r=g)
Hi Stefan, The problem arises when you try to use methods of the ufunc. So for the custom universal function previously defined, uadd: uadd([1,2,3],[1,2,3]) works fine. But uadd.accumulate(..) or uadd.reduce(..) fail with error: ValueError: could not find a matching type for add (vectorized).accumulate ( or (vectorized).reduce ) Apologies, I should have been more clear before. Thanks, Aditya 2011/9/19 Stéfan van der Walt <stefan@sun.ac.za>
![](https://secure.gravatar.com/avatar/c3e2d2fc63a0016d3a4ffa493daf9655.jpg?s=120&d=mm&r=g)
Hi, Stefan, which version of Python and NumPy are you using? I am upgrading Python and NumPy, and would like to get it working on the official releases of Python 2.7.2 + NumPy 1.6.1 In Python 2.6 + NumPy 1.5.1 on win32, it works. In Python 2.7.2 + NumPy 1.6.1 on win32, np.frompyfunc(add,2,1).accumulate definitely gives an error. Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
Aditya 2011/9/19 Stéfan van der Walt <stefan@sun.ac.za>
![](https://secure.gravatar.com/avatar/a5cbd07efd53a3e16124de3829abec0e.jpg?s=120&d=mm&r=g)
He is using the development version of Numpy, which is probably the main difference (I tried it too with Numpy 1.6.1 on an x86_64 Linux architecture and got the same bug). If you want to use an official Numpy release you'll probably need to downgrade to 1.5.x and wait until the next Numpy release. -=- Olivier 2011/9/20 Aditya Sethi <ady.sethi@gmail.com>
![](https://secure.gravatar.com/avatar/f4480fb86ce05c4e2ee38e796715e64e.jpg?s=120&d=mm&r=g)
Hi everyone, A long time ago, Aditya Sethi <ady.sethi@gmail... wrote:
Here's the workaround I found to that problem:
uadd.accumulate([1,2,3], dtype='object') array([1, 3, 6], dtype=object)
It seems like "accumulate" infers that 'l' is the required output dtype, but does not have the appropriate implementation:
uadd.types ['OO->O']
Forcing the output dtype to be 'object' (the only supported dtype) seems to do the trick. Hope this helps, -- Pascal
participants (4)
-
Aditya Sethi
-
Olivier Delalleau
-
Pascal Lamblin
-
Stéfan van der Walt