Ticket #1156 (new defect)
Opened 7 months ago
vectorizing an Unbound Method
| Reported by: | barronh | Owned by: | somebody |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Other | Version: | |
| Keywords: | Cc: |
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?):
