ufunc delegation to object method
In the following code, numpy.sin() calls the object's sin() function: In [2]: class Foo(object): ...: def sin(self): ...: return "spam" ...: In [3]: f = Foo() In [4]: np.sin(f) Out[4]: 'spam' Is this, in fact, guaranteed behavior for a ufunc? It does not appear to be documented. This question came up in the discussion of SciPy pull request 138 ( https://github.com/scipy/scipy/pull/138), where the idea is to add numpy unary ufunc support to SciPy's sparse arrays. (Sorry if this email shows up twice. I sent it the first time while the Enthought servers were down, and eventually got an email back saying it had not been sent.) Warren
Bump... On Mon, Jan 30, 2012 at 1:17 AM, Warren Weckesser < warren.weckesser@enthought.com> wrote:
In the following code, numpy.sin() calls the object's sin() function:
In [2]: class Foo(object): ...: def sin(self): ...: return "spam" ...:
In [3]: f = Foo()
In [4]: np.sin(f) Out[4]: 'spam'
Is this, in fact, guaranteed behavior for a ufunc? It does not appear to be documented.
This question came up in the discussion of SciPy pull request 138 ( https://github.com/scipy/scipy/pull/138), where the idea is to add numpy unary ufunc support to SciPy's sparse arrays.
(Sorry if this email shows up twice. I sent it the first time while the Enthought servers were down, and eventually got an email back saying it had not been sent.)
Warren
Yes. This is the behavior. It was part of the original Numeric implementation. In the code generator file: numpy/core/code_generators/generate_umath.py ufuncs with a registered type of 'P' have this behavior. There is a long list of them. Travis On Feb 2, 2012, at 12:04 AM, Warren Weckesser wrote:
Bump...
On Mon, Jan 30, 2012 at 1:17 AM, Warren Weckesser <warren.weckesser@enthought.com> wrote: In the following code, numpy.sin() calls the object's sin() function:
In [2]: class Foo(object): ...: def sin(self): ...: return "spam" ...:
In [3]: f = Foo()
In [4]: np.sin(f) Out[4]: 'spam'
Is this, in fact, guaranteed behavior for a ufunc? It does not appear to be documented.
This question came up in the discussion of SciPy pull request 138 (https://github.com/scipy/scipy/pull/138), where the idea is to add numpy unary ufunc support to SciPy's sparse arrays.
(Sorry if this email shows up twice. I sent it the first time while the Enthought servers were down, and eventually got an email back saying it had not been sent.)
Warren
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
On Thu, Feb 2, 2012 at 12:21 AM, Travis Oliphant <travis@continuum.io>wrote:
Yes. This is the behavior. It was part of the original Numeric implementation. In the code generator file:
numpy/core/code_generators/generate_umath.py
ufuncs with a registered type of 'P' have this behavior. There is a long list of them.
Travis
Great, thanks. Warren
On Feb 2, 2012, at 12:04 AM, Warren Weckesser wrote:
Bump...
On Mon, Jan 30, 2012 at 1:17 AM, Warren Weckesser < warren.weckesser@enthought.com> wrote:
In the following code, numpy.sin() calls the object's sin() function:
In [2]: class Foo(object): ...: def sin(self): ...: return "spam" ...:
In [3]: f = Foo()
In [4]: np.sin(f) Out[4]: 'spam'
Is this, in fact, guaranteed behavior for a ufunc? It does not appear to be documented.
This question came up in the discussion of SciPy pull request 138 ( https://github.com/scipy/scipy/pull/138), where the idea is to add numpy unary ufunc support to SciPy's sparse arrays.
(Sorry if this email shows up twice. I sent it the first time while the Enthought servers were down, and eventually got an email back saying it had not been sent.)
Warren
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
participants (2)

Travis Oliphant

Warren Weckesser