Open xshaokun opened 6 days ago
Thanks for reporting this, it's clearly a defect !
It might sufficient to replace p == 0.0
with np.all(p == 0.0)
and add a couple test cases. We should also make sure that a TypeError is raised if p is another (non dimensionless) unyt array. Are you interested in giving it a try ? Otherwise I should have time to do it myself later this week.
Thank you for the response. From the perspective of dimensions, p
as an exponent here should not be a quantity with dimensions, so I don't think we need to worry about p
being non-dimensionless. Since I will be quite busy for a while and may not be able to fix this bug, I appreciate you would make it :)
Hum, maybe I was a bit quick in my previous answer: the only cases where it makes sense to support raising a unyt_array
a
to an array power p
is when p
is a 1-element array or has a broadcastable shape with a
and a unique value. The reason is that the resulting array can only have a uniform unit, which is only possible if all elements are raised to the same power... so, even though the specific example you illustrated the issue with doesn't make sense to me (but the error should be clearer), I'll add support for the few cases that do make sense.
Oh, in some cases, when the base is a dimensionless number, the example I gave should make sense. For instance, I’m currently trying to calculate synchrotron radiation, where the spectral indices vary across different regions. The following formula shows that the base in the final part is a dimensionless quantity, where the p
is the power-law index of non-thermal electrons.
(from Rybicki and Lightman 1986)
Yes, if the power itself is dimensionless, it should work. See #524 and please let me know if this helps !
Description
In the
power
operation of unyt arrays, when the exponent is also an array, it leads to an error.While for numpy arrays, it behaviors like
I now use
to_ndarray()
to make it work but lose the units.