[Numpy-discussion] Keyword argument support for vectorize.

Michael McNeil Forbes michael.forbes@gmail....
Mon Apr 9 04:53:46 CDT 2012


On 8 Apr 2012, at 12:09 PM, Ralf Gommers wrote:
> That looks like a useful enhancement. Integrating in the existing  
> vectorize class should be the way to go.

Okay.  I will push forward.  I would also like to add support for  
"freezing" (or "excluding") certain arguments from the vectorization.   
Any ideas for a good argument name?  (I am just using "exclude=['p']"  
for now).

The use case I have is vectorizing polynomial evaluation `polyval(p,  
x)`.  The coefficient array `p` should not be vectorized over, only  
the variable `x`, so something like:

@vectorize(exclude=set(['p']))
def mypolyval(p, x):
    return np.polyval(p, x)

would work like np.polyval currently behaves:

 >>> mypolyval([1.0,2.0],[0.0,3.0])
array([ 2., 5.])

(Of course, numpy already has polyval: I am actually trying to wrap  
similar functions that use Theano for automatic differentiation, but  
the idea is the same).

It seems like functools.partial is the appropriate tool to use here  
which means I will have to deal with the
This will require overcoming the issues with how vectorize deduces the  
number of parameters, but if I integrate this with the vectorize  
class, then this should be easy to patch as well.

http://mail.scipy.org/pipermail/numpy-discussion/2010-September/052642.html

Michael.

> On Sat, Apr 7, 2012 at 12:18 AM, Michael McNeil Forbes <michael.forbes@gmail.com 
> > wrote:
> Hi,
>
>> I added a simple enhancement patch to provide vectorize with simple
>> keyword argument support.  (I added a new kwvectorize decorator, but
>> suspect this could/should easily be rolled into the existing  
>> vectorize.)
>>
>> http://projects.scipy.org/numpy/ticket/2100
...



More information about the NumPy-Discussion mailing list