Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

mhvk
Copy link
Contributor

@mhvk mhvk commented Aug 29, 2025

This pull request is a quick follow up to #18562, where I noticed that a routine raveled and reshaped an array to work correctly with np.dot, when this is no longer necessary with matmul and the newer matvec. Note that the routine will become even simpler once our minimal numpy version is 2.2, since then we can count on np.matvec being available.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@mhvk mhvk added this to the v7.2.0 milestone Aug 29, 2025
@mhvk mhvk requested a review from a team as a code owner August 29, 2025 20:11
Copy link
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@mhvk mhvk requested review from nden and WilliamJamieson August 29, 2025 20:12
Copy link
Contributor

@nden nden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@nden
Copy link
Contributor

nden commented Sep 3, 2025

While the code looks good, locally I see a degraded performance, which I didn't expect. I'll need to run some more tests before merging.

@nden nden self-requested a review September 3, 2025 13:00
@nden
Copy link
Contributor

nden commented Sep 3, 2025

Timings for two arrays of shape (2000, 2000):
main: 243 ms ± 533 μs
pr: 357 ms ± 947 μs

Timings for two arrays of shape (4000, 4000):
main: 900 ms ± 1.85 ms
pr: 1.33 s ± 2.56 ms

The old code here does not look like it is subject to the future "shape" deprecations. It already uses reshape and shape is only used to retrieve the shape of the inputs.
If this is correct and given the differences in the timings I suggest we don't merge this PR. The reason is we constantly strive to improve performance of GWCS and this will degrade performanec of all imaging transformations.

@mhvk
Copy link
Contributor Author

mhvk commented Sep 3, 2025

@nden - wow, I would have thought my PR would have sped up, not slown down. I'd like to investigate, since perhaps this means that on the numpy side this could be improved a lot too. Just so I'm sure that I'm doing the right thing, could you give the full example you tested? In the meantime, I'll convert this to draft so it won't get merged accidentally.

@pllim pllim added the benchmark Run benchmarks for a PR label Sep 3, 2025
@pllim pllim marked this pull request as draft September 3, 2025 14:08
@mhvk
Copy link
Contributor Author

mhvk commented Sep 3, 2025

The old code here does not look like it is subject to the future "shape" deprecations

That is because it was already adjusted in #18562 - when reviewing that PR, I thought I could make a further improvement...

@pllim
Copy link
Member

pllim commented Sep 3, 2025

FWIW

Change Before [1ba18e8] After [8c02e67] Ratio Benchmark (Parameter)
+ 352±30μs 482±10μs 1.37 units.TimeQuantityOpLargeArraySameUnit.time_quantity_mul
+ 832±4ms 1.09±0s 1.3 modeling.compound.EvaluateCompoundModelNoUnits.time_big

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE DECREASED.

@nden
Copy link
Contributor

nden commented Sep 3, 2025

@mhvk Thanks for following up! The test example is

from astropy.modeling import rotations
import numpy as np

x, y = np.mgrid[:4038, :4051]
n2c = rotations.RotateNative2Celestial(5.6, -72, 180)

timeit n2c(x, y)

@mhvk
Copy link
Contributor Author

mhvk commented Sep 3, 2025

Great, thanks both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants