You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We do this to add methods that we wanted for basic finite-difference operations and boundary conditions for our code.
Is there an easy way to subclass unyt_array just like one would for np.ndarray? We'd like to be able to add units to our type.
It maybe that what we are doing is not the best approach anyway, so if there is better way to add methods to the unyt_array, we're happy to hear that as well.
The text was updated successfully, but these errors were encountered:
It looks like your subclass just attaches metadata to the array, I think it should work without too much hassle. I'd do this by overriding __new__ and __array_finalize__ in your subclass but make sure to call those methods on the superclass explicitly.
For inspiration you can look at ImageArray in yt, which is a subclass of YTArray and will be a subclass of unyt_array in yt 4.0. We also explicitly test that subclassing works correctly (at least in a limited sense):
We currently have a data type
ArrayIndexer
that is built from subclassingnp.ndarray
:https://github.com/zingale/pyro2/blob/master/mesh/array_indexer.py
We do this to add methods that we wanted for basic finite-difference operations and boundary conditions for our code.
Is there an easy way to subclass
unyt_array
just like one would fornp.ndarray
? We'd like to be able to add units to our type.It maybe that what we are doing is not the best approach anyway, so if there is better way to add methods to the
unyt_array
, we're happy to hear that as well.The text was updated successfully, but these errors were encountered: