Open numpy-gitbot opened 12 years ago
atmention:mforbes wrote on 2012-04-06
It seems to me that this could easily be rolled into vectorize with only a slight performance hit, but it should be reviewed first by someone familiar with the subtleties of the current vectorize implementation.
atmention:mforbes wrote on 2012-04-14
Here is a patch that is integrated into the main vectorize
class. It includes the following:
API change:
vectorize
now supports vectorization over keyword arguments.argspec
::
Allows the user to override automatic detection (for wrapped functions for example)
exclude
::
A set of variables that will be excluded from vectorization.pyfunc.original_function
is defined, then this is used for getting documentation and the argspec.Additional changes:
argspec
, so I added _get_argspec()
that calls inspect.getargspec()
and falls back to _get_nargs()
. Maybe these could be rolled together.__call__
is now in _vectorize_call
. This is called directly unless __call__
is passed keyword arguments, in which case the new code is executed which assembles the arguments into their proper positions and then calls _vectorize_call
.exclude
is implemented by creating a wrapper function with only the un-excluded positional arguments. This is explicitly passed to _vectorize_call
instead of self.thefunc
. The wrapper explicitly calls the original function with everything packed as a dictionary of keyword arguments for simplicity.Added documentation, as well as some tests. All of the vectorize code is now covered by tests.
Attachment added by atmention:mforbes on 2012-04-14: 0001-MMF-added-kwvectorize-wrapper-for-vectorize-with-kwa.patch
Attachment added by atmention:mforbes on 2012-04-14: 0002-New-kwarg-and-exclude-support-integrated-into-vector.patch
Attachment added by atmention:mforbes on 2012-04-14: 0003-Added-patch-suggested-for-ticket-1156-and-finished-c.patch
Attachment added by atmention:mforbes on 2012-04-14: 0004-Added-some-comments-pointing-out-the-issue-numbers-f.patch
atmention:rgommers wrote on 2012-04-16
Hi Michael, looks good from a quick glance at the patches. Could you send this as a pull request on github? That will make testing and code review quite a bit easier.
Noticed a few minor things so far:
assert_
from numpy.testing instead of plain assert
.:func:
vectorizeshould simply be
vectorize``atmention:mforbes wrote on 2012-04-19
Okay. I fixed these and added a pull request for the branches with changes (https://github.com/numpy/numpy/pull/256).
atmention:mforbes wrote on 2012-05-10
Completed patch now at pull request https://github.com/numpy/numpy/pull/275. This supersedes PR 256.
Original ticket http://projects.scipy.org/numpy/ticket/2100 on 2012-04-06 by atmention:mforbes, assigned to unknown.
In a few place, people have requested being able to use keyword arguments with vectorize. For example: http://thread.gmane.org/gmane.comp.python.scientific.user/29362/focus=29371
Here is a simple patch that defines a decorator kwvectorize simply wrapping vectorize to provide simple support for kwargs. It simply looks at the order of arguments defined in the original function, and then reorders any kwargs provided appropriately, calling vectorize with only positional arguments.