-
Notifications
You must be signed in to change notification settings - Fork 1
SP-2017: Performance optimizations #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,28 @@ | |
| from astrometry.util.ttime import Time | ||
| from tractor.engine import logverb, OptResult, logmsg | ||
|
|
||
|
|
||
| import numba | ||
|
|
||
| @numba.njit(fastmath=True, nogil=True) | ||
| def fast_add_to(mod_img, patch_data, counts, x0, y0): | ||
| img_h, img_w = mod_img.shape | ||
| patch_h, patch_w = patch_data.shape | ||
|
|
||
| # 1. Equivalent to get_overlapping_region for Y | ||
| y_start = max(0, -y0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a docstring clarifying what the input parameters represent. I understand it is trying to find the overlap between mod_img and patch_data, but it's unclear which is the "reference" vs "desired" size. |
||
| y_end = min(patch_h, img_h - y0) | ||
|
|
||
| # 2. Equivalent to get_overlapping_region for X | ||
| x_start = max(0, -x0) | ||
| x_end = min(patch_w, img_w - x0) | ||
|
|
||
| # 3. Add to image (avoids empty list checks, if start >= end, loop just doesn't run) | ||
| for y in range(y_start, y_end): | ||
| for x in range(x_start, x_end): | ||
| # mod_img[y0 + y, x0 + x] is the 'out' coordinate | ||
| # patch_data[y, x] is the 'in' coordinate | ||
| mod_img[y0 + y, x0 + x] += patch_data[y, x] * counts | ||
|
|
||
| class Optimizer(object): | ||
| def optimize(self, tractor, alphas=None, damp=0, priors=True, | ||
| scale_columns=True, shared_params=True, variance=False, | ||
|
|
@@ -221,6 +242,7 @@ def _get_umodels(self, tractor, srcs, imgs, minsb, rois, **kwargs): | |
| umodels.append(umods) | ||
| return umodels, umodtosource, umodsforsource | ||
|
|
||
|
|
||
| def _optimize_forcedphot_core( | ||
| self, tractor, | ||
| result, umodels, imlist, mod0, scales, skyderivs, minFlux, | ||
|
|
@@ -531,7 +553,8 @@ def _getims(self, fluxes, imgs, umodels, mod0, scales, sky, minFlux, rois): | |
| assert(np.isfinite(counts)) | ||
| assert(np.all(np.isfinite(um.patch))) | ||
| # print 'Adding umod', um, 'with counts', counts, 'to mod', mod.shape | ||
| (um * counts).addTo(mod) | ||
| # (um * counts).addTo(mod) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can either remove this (since it's commented out), or keep it in as reference for which original function we have substituted/replaced. Which do you think makes more sense? |
||
| fast_add_to(mod, um.patch, counts, um.x0, um.y0) | ||
|
|
||
| ie = img.getInvError() | ||
| im = img.getImage() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add an inline comment here reminding that
deriv_scaleis unity so thevalscalculation just multiplies by a constant