inducer/pycuda — pull request #44 by untom (2014-03-05 19:35:46+00:00)
Title: Add 'out' parameter to unary math functions.

Hi!

This PR adds an optional 'out' parameter to the unary math functions (`log`, `fabs`, `cos`, ...) in `pycuda.cumath`. This parameter can be used to store the output, thus avoiding new allocations in those functions. This also increases compatibility with numpy, which also offers such an optional 'out' parameter in many functions.

However, there is a potential drawback here: traditionally in all of `pycuda` the `stream` parameter is the last parameter to the function, which is why I added `out` between the `array` and the `stream` argument. However, this breaks compatibility with old code that has assumed that `stream` comes right after `array`, e.g. in calls such as `cumath.exp(x, mystream)`.

An alternative would be to pass `out` as 3rd argument, but that would break the "`stream` is the last parameter" convention. If this is a more desirable solution (or if you know of an even better one) let me know and I'll add the changes.