[Numpy-discussion] Style for pad implementation in 'pad' namespace or functions under np.lib

Nathaniel Smith njs at pobox.com
Fri Mar 30 07:41:50 EDT 2012


On Thu, Mar 29, 2012 at 6:53 PM, Tim Cera <tim at cerazone.net> wrote:
> If instead you passed in a function:
>
>     def padwithzeros(vector, pad_width, iaxis, **kwargs):
>         bvector = np.zeros(pad_width[0])
>         avector = np.zeros(pad_width[1])
>         return bvector, avector
>
>     b = pad(padwithzeros, a, 2)
>
> Would that have some goodness?

I like the idea, but this interface feels undercooked to me. What is
iaxis? (I couldn't figure that out from the docstrings in the pull
request either.) If padding a matrix, do we need a way to do padding
of all rows simultaneously? (Certainly that'd be just as easy for
something like padwithzeros, and would let us avoid a python-level for
loop.) Why is this function allocating new arrays that will just be
copied into the big array and then discarded, instead of filling in
the big array directly? (Again, this is a speed issue.) If it's
working with single rows at a time, then how will padwithconstant know
which constant to pull out of kwargs["constant_value"] when it's an
array?

That's why I thought you might want to submit this as a second pull
request, rather than letting it hold up the whole thing.

-- Nathaniel



More information about the NumPy-Discussion mailing list