Repository navigation
Remove use of np.matrix in coordinates, version 2 - #5104
Conversation
|
p.s. If we go this route, |
| mat3 = rotation_matrix(Galactic._ngp_J2000.ra.degree, 'z') | ||
|
|
||
| return mat1 * mat2 * mat3 * pmat | ||
| return matmul(matmul(matmul(mat1, mat2), mat3), pmat) |
There was a problem hiding this comment.
I wonder if we should have a standard way of indicating 'review this when we only support python 3.5 and higher', or 'review this when we only support numpy 1.11 or higher', etc.?
There was a problem hiding this comment.
What about having a very distinct color and naming for a label? Something like "revise after: np 1.11"?
There was a problem hiding this comment.
I think this should be something in the code though, not just labels. But yes, a syntax like:
# REVISE PY35: ...
could work
There was a problem hiding this comment.
It indeed needs to be something within a comment, since one cannot have @ as part of the code, even if protected by an if statement.
I do think, though, that the code will look clean enough if I define matrix_product (which repeatedly multiplies matrices together) and perhaps also a matrix_transpose.
There was a problem hiding this comment.
You could wrap it in an if py35: eval("a @ b") but granted that's not exactly good style.
But the @ operator is really bad for backwards-compatibility because implementing it means that older python are not just not supported anymore but it will be impossible to use them with astropy because of the SyntaxErrors. So maybe using eval() until 2020 (?) would be the best way if astropy doesn't want to exclude any older python version.
|
Since the move to p.s. The only place where I did not yet remove |
b8ace7d to
36e0ad2
Compare
|
@mhvk - have you done any kind of performance benchmarking to see how things change with this PR? |
36e0ad2 to
c733163
Compare
|
Not beyond checking that |
|
@eteq, @StuartLittlefair - would you be able to review this PR to remove the use of |
| Either ``'x'``, ``'y'``, ``'z'``, or a (x,y,z) specifying the axis to | ||
| rotate about. If ``'x'``, ``'y'``, or ``'z'``, the rotation sense is | ||
| counterclockwise looking down the + axis (e.g. positive rotations obey | ||
| left-hand-rule). If given as an array, the last dimension should be 3. |
There was a problem hiding this comment.
Is it a good idea to also allow an array of strs? For example ['x', 'y', 'z']?
There was a problem hiding this comment.
'x', 'y', and 'z' are mostly meant as short-cuts to speed up those common cases; the speed-up would certainly be lost for multiple values, and since this is used mostly internally anyway, I'd tend to leave it alone.
|
@mhvk this is a 👍 from me. |
c3404fd to
1068c0c
Compare
|
@eteq - do you want to review this, or are you happy with @StuartLittlefair's review? @astrofrog - on possible speed regressions: I think this should only lead to improvements, but still haven't figured out how to easily run asv. However, a quick test seems promising: |
|
@eteq - with @StuartLittlefair's review, I'm confident enough to merge this removal of the use of |
|
I definitely plan to have a look at this, @mhvk. It might take me a few more days but I'll try to bump it up in the queue seeing as how you think it's pretty much there. One possible logistical complication: I think I've worked out a fix to #5133 that would make be made easier by use of this machinery. But ideally we would fix that in 1.2.x and this PR is certainly 1.3.x. I might just try for a "quick-and-dirty" fix that would work in 1.2.x, and then a better version to merge after this, but in that case we'd want to get the #5133 fix in before this. |
|
I've just discovered the Given the changes here, is this PR a sensible place to update that method to use the code contained within this PR? |
and use it in latter.
99e16d1 to
27d3930
Compare
|
This looks good to me -- thanks @mhvk ! |
|
Looks good to me too except for one super minor thing: I think this should go in the "other" section of the changelog, as it isn't really a bug fix (but isn't exactly an API change due to it not explicitly being public API). Will just do that in a manual merge though so as not to delay things further. Thanks for all the work on this, @mhvk! |
Remove use of np.matrix in coordinates, version 2
|
@mhvk - didn't think this needed delaying the merge, but I see you modified the Sgr example to use the new matrices but left in this: That could be changed to right? |
|
Yes, sorry I missed that... Will look at #5210 tomorrow. |
This is the second of two possible ways to remove the use of np.matrix in coordinates (see #5088).
In this PR, the matrices are replaced with normal arrays, and a new
matmulfunction is defined that either just uses the numpy function of that name, or, for numpy <= 1.10, the equivalenteinsum. With this implementation, in all the transformations, multiplication has to be replaced withmatmul, so this affects a lot more files. To get general broadcasting to work, it will be necessary to also replace any.Ton the rotation matrices with.swapaxes(-2, -1).