[NumPy-Tickets] [NumPy] #1156: vectorizing an Unbound Method
NumPy Trac
numpy-tickets@scipy....
Wed Jun 2 08:33:37 CDT 2010
#1156: vectorizing an Unbound Method
-----------------------+----------------------------------------------------
Reporter: barronh | Owner: somebody
Type: defect | Status: needs_review
Priority: normal | Milestone:
Component: numpy.lib | Version:
Keywords: vectorize |
-----------------------+----------------------------------------------------
Changes (by rgommers):
* keywords: => vectorize
* status: new => needs_review
* component: Other => numpy.lib
Old description:
> The current vectorize implementation cannot appropriately vectorize an
> UnboundMethodType function. The root of the problem in is
> numpy.lib.function_base._get_nargs line 1778. The number of arguments
> that a function takes is decremented if the function is a MethodType.
> MethodType is inclusive of bound and unbound methods. To make the
> unbound method useful, it must take an instance as the first argument,
> but the check against the number of arguments prevents this.
>
> reproduce with:
> >>> from numpy import vectorize, arange
> >>> class foo:
> >>> b=2
> >>> def bar(self, a):
> >>> return a**self.b
> >>>
> >>> vectorize(foo.bar)(foo(),arange(9))
> ValueError: mismatch between python function inputs and received
> arguments
>
> Changing numpy.lib.function_base line 1778 solves the problem
> < if instance(obj, types.MethodType):
> > if instance(obj, types.MethodType) and not instance(obj,
> types.UnboundMethodType):
New description:
The current vectorize implementation cannot appropriately vectorize an
UnboundMethodType function. The root of the problem in is
numpy.lib.function_base._get_nargs line 1778. The number of arguments
that a function takes is decremented if the function is a MethodType.
MethodType is inclusive of bound and unbound methods. To make the unbound
method useful, it must take an instance as the first argument, but the
check against the number of arguments prevents this.
reproduce with:
{{{
>>> from numpy import vectorize, arange
>>> class foo:
>>> b=2
>>> def bar(self, a):
>>> return a**self.b
>>>
>>> vectorize(foo.bar)(foo(),arange(9))
ValueError: mismatch between python function inputs and received arguments
}}}
Changing numpy.lib.function_base line 1778 solves the problem
{{{
< if instance(obj, types.MethodType):
> if instance(obj, types.MethodType) and not instance(obj,
types.UnboundMethodType):
}}}
--
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1156#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list