New issue 1013: Consider using __numpy_ufunc__ from numpy 1.10 for YTArray https://bitbucket.org/yt_analysis/yt/issue/1013/consider-using-__numpy_ufunc...
This new hook in ndarray's subclassing machinery may help us avoid a significant amount of boilerplate in the definition of YTArray. In addition, it may also allow us to fix currently un-resolveable issues with subclassing ndarray, e.g. this example:
#! >>> import numpy as np >>> from yt.units import g >>> a = np.array([1,2,3]) >>> print a*g [ 1. 2. 3.] g a*g returns a YTArray, an ndarray subclass that knows about units. "plain" ndarrays are treated as unitless arrays. >>> print g 1.0 g >>> a *= g >>> print a array([1, 2, 3]) I don't seem to have a way to override this behavior, since this invokes __imul__ in the ndarray class rather than __rmul__ in my subclass >>> a = [1,2,3] >>> print a*g [ 1. 2. 3.] g >>> a *= g >>> a YTArray([ 1., 2., 3.]) g Things behave correctly when I use lists rather than ndarray.
Unfortunately this is blocked until numpy 1.10 is released. We will also need to be careful to not break compatibility with older versions of numpy, and be sure to not make the code paths followed in different numpy versions different.
yt-dev mailing list firstname.lastname@example.org http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org