Repository navigation
Allow base with dimensionless quantity as base for np.power. - #4770
Conversation
|
|
||
| # But identical unit fractions are considered dimensionless and are | ||
| # allowed as base for np.power: #4764 | ||
| res = np.power([2., 4.] * u.m / u.m, [2., 4.]) |
There was a problem hiding this comment.
A bit confused by the test here. In the original issue, the power itself is also a dimensionless Quantity, but that is not reflected here.
There was a problem hiding this comment.
@pllim I totally forgot to include it but that wasn't part of the problem and with the change both of these will work:
np.power(np.array([2, 2, 2, 2]) * u.Unit('cm/cm'), np.array([1, 2, 3, 4]) * u.Unit(''))
np.power(np.array([2, 2, 2, 2]) * u.Unit('cm/cm'), np.array([1, 2, 3, 4]) * u.Unit('m/m'))
Of course I can include them if you want. :)
|
Also, needs a change log, but I'll let @mhvk decide whether to backport or not, which affects where the change log entry goes. |
|
I think this is a bug, so, yes, this should be backported. Set milestone accordingly. But think we need some test cases |
|
The I've tested it with the additional change: and it works, sort of. Just when the exponent is a list it yields strange results: but the specified cases seem to work: I have to look into that before I push the change. |
|
@MSeifert04 - looks promising! But should get the units right also in corner cases -- there must be something wrong with what I suggested. Also, is the change of I'll try to look in a bit more detail tomorrow. |
|
I've investigated a bit and if the exponent is a I couldn't locate where it goes wrong but I think the unit get's lost somewhere in @mhvk - The |
|
@MSeifert04 - OK, I tested myself now, and saw what I should have seen before, that Now on the solution itself: yours obviously works, but I wondered if it wouldn't be better to ensure that a composite unit that has no elements left and has scale of unit, is simply set to |
|
@mhvk If the explicit test case was inside I think the converting a dimensionless-composite-unit to a dimensionless-unit is a bit too much work for me at the moment. |
|
Yes, that was it. I do have something that works correctly, and removes a bug in the process. Let me do a PR to yours so you can have a look. |
…y powers. Also fixes a problem with lists as input to ufuncs.
|
@mhvk I had a look and it works very well. I have a few minor comments (especially about catching explicit |
|
@MSeifert04 - I think now it is easiest for you to merge my commit into your branch, which makes it visible here too, and then we can have an additional commit. I think on your computer's end, you'd do: and after that you can edit on your machine and push up as usual. |
Ensure that scaled dimensionless quantities can be raised to arbitrary powers.
|
@mhvk Thank you! With your help this was easier then expected. |
|
@MSeifert04 - OK, now reviewed the additional changes you made -- good! So, merging... |
|
Thanks @mhvk and @MSeifert04 for working on that! |
|
Re-milestoned, as discussed in #4395 - I'll need to move the changelog entry, will do that as part of my consistency checks. |
Fixes #4764
The rationale for this change is explained in #4764 (comment).