Upgrade to 1.6.x: frompyfunc() ufunc casting issue

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?
import numpy as np def add(a,b): ... return (a+b) uadd = np.frompyfunc(add,2,1) uadd <ufunc 'add (vectorized)'> uadd.accumulate([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not find a matching type for add (vectorized).accumulate, requested type has type code 'l'
Thanks, Aditya

Hi, On Mon, Sep 19, 2011 at 2:38 PM, Aditya Sethi <ady.sethi@gmail.com> wrote:
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?
import numpy as np def add(a,b): ... return (a+b) uadd = np.frompyfunc(add,2,1) uadd <ufunc 'add (vectorized)'> uadd.accumulate([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not find a matching type for add (vectorized).accumulate, requested type has type code 'l'
Seems to work ok on the latest version: In [12]: uadd([1,2,3],[1,2,3]) Out[12]: array([2, 4, 6], dtype=object) In [13]: np.__version__ Out[13]: '2.0.0.dev-af22fc4' Cheers Stéfan

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>
Hi,
On Mon, Sep 19, 2011 at 2:38 PM, Aditya Sethi <ady.sethi@gmail.com> wrote:
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?
import numpy as np def add(a,b): ... return (a+b) uadd = np.frompyfunc(add,2,1) uadd <ufunc 'add (vectorized)'> uadd.accumulate([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not find a matching type for add (vectorized).accumulate, requested type has type code 'l'
Seems to work ok on the latest version:
In [12]: uadd([1,2,3],[1,2,3]) Out[12]: array([2, 4, 6], dtype=object)
In [13]: np.__version__ Out[13]: '2.0.0.dev-af22fc4'
Cheers Stéfan _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

On Mon, Sep 19, 2011 at 4:18 PM, Aditya Sethi <ady.sethi@gmail.com> wrote:
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.
In the development version: In [4]: uadd.accumulate([1,2,3]) Out[4]: array([1, 3, 6], dtype=object) In [5]: uadd.reduce([1,2,3]) Out[5]: 6 Regards Stéfan

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.
import numpy as np def add(a,b): ... return (a+b) ... uadd = np.frompyfunc(add,2,1) uadd <ufunc 'add (vectorized)'> uadd([1,2,3],[1,2,3]) array([2, 4, 6], dtype=object)
uadd.accumulate([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not find a matching type for add (vectorized).accumulate, requested type has type code 'l'
Aditya 2011/9/19 Stéfan van der Walt <stefan@sun.ac.za>
On Mon, Sep 19, 2011 at 4:18 PM, Aditya Sethi <ady.sethi@gmail.com> wrote:
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.
In the development version:
In [4]: uadd.accumulate([1,2,3]) Out[4]: array([1, 3, 6], dtype=object)
In [5]: uadd.reduce([1,2,3]) Out[5]: 6
Regards Stéfan _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

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>
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.
import numpy as np def add(a,b): ... return (a+b) ... uadd = np.frompyfunc(add,2,1) uadd <ufunc 'add (vectorized)'> uadd([1,2,3],[1,2,3]) array([2, 4, 6], dtype=object)
uadd.accumulate([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not find a matching type for add (vectorized).accumulate, requested type has type code 'l'
Aditya
2011/9/19 Stéfan van der Walt <stefan@sun.ac.za>
On Mon, Sep 19, 2011 at 4:18 PM, Aditya Sethi <ady.sethi@gmail.com> wrote:
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.
In the development version:
In [4]: uadd.accumulate([1,2,3]) Out[4]: array([1, 3, 6], dtype=object)
In [5]: uadd.reduce([1,2,3]) Out[5]: 6
Regards Stéfan _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Understood. Thanks Olivier, Stefan. On Tue, Sep 20, 2011 at 9:18 AM, Olivier Delalleau <shish@keba.be> wrote:
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>
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.
import numpy as np def add(a,b): ... return (a+b) ... uadd = np.frompyfunc(add,2,1) uadd <ufunc 'add (vectorized)'> uadd([1,2,3],[1,2,3]) array([2, 4, 6], dtype=object)
uadd.accumulate([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not find a matching type for add (vectorized).accumulate, requested type has type code 'l'
Aditya
2011/9/19 Stéfan van der Walt <stefan@sun.ac.za>
On Mon, Sep 19, 2011 at 4:18 PM, Aditya Sethi <ady.sethi@gmail.com> wrote:
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.
In the development version:
In [4]: uadd.accumulate([1,2,3]) Out[4]: array([1, 3, 6], dtype=object)
In [5]: uadd.reduce([1,2,3]) Out[5]: 6
Regards Stéfan _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Hi everyone, A long time ago, Aditya Sethi <ady.sethi@gmail... wrote:
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?
import numpy as np def add(a,b): ... return (a+b) uadd = np.frompyfunc(add,2,1) uadd <ufunc 'add (vectorized)'> uadd.accumulate([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not find a matching type for add (vectorized).accumulate, requested type has type code 'l'
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