[PySide] Keeping GUI responsive
Israel Brewster
ijbrewster at alaska.edu
Fri Dec 6 21:41:43 CET 2019
> On Dec 6, 2019, at 11:34 AM, Andrew Nelson <andyfaff at gmail.com> wrote:
>
> Whilst I'm not familiar with pandas it's behaviour is probably similar to NumPy in terms of vectorisation. It looks to me that you can vectorise that loop. Removing loops will give you *enormous* speedup. I don't claim this is the most numpythonic, there may be some kind of modulo arithmetic for doing this more easily.
You are correct - in fact, my understanding is that pandas actually uses NumPy under the hood, and as such most NumPy operations/optimizations apply. And yes, that loop has been bugging me, as it looks to me as well that I should be able to vectorize it. In fact, I’ve been able to do exactly that to numerous other loops I have found in the code (I’m not the original author), with great success. I simply haven’t yet been able to wrap my head around exactly how to vectorize this one. But that’s a different question, for a different mailing list :-)
…although if I can do enough optimizations, I suppose that would make this issue a moot point :-)
---
Israel Brewster
Software Engineer
Alaska Volcano Observatory
Geophysical Institute - UAF
2156 Koyukuk Drive
Fairbanks AK 99775-7320
Work: 907-474-5172
cell: 907-328-9145
>
> ```
> dx = self.contour_df['delta_utmx_volc']
> dy = self.contour_df['delta_utmy_volc']
>
> loc = np.logical_and(dx > 0, dy > 0)
> self.contour_df['volc_azimuth'][loc] = self.contour_df['volc_theta'][loc]
>
> # the complement of loc is both dx and dy are negative, or equal to zero (you didn't deal with that case)
> self.contour_df['volc_azimuth'][~loc] = 360 - self.contour_df['volc_theta'][~loc]
>
> loc = np.logical_and(dx > 0, dy < 0)
> self.contour_df['volc_azimuth'][loc] = 180 - self.contour_df['volc_theta'][loc]
>
> loc = np.logical_and(dx < 0, dy > 0)
> self.contour_df['volc_azimuth'][loc] = 180 + self.contour_df['volc_theta'][loc]
> ```
>
>
> for i in range(self.contour_df.index[0], self.contour_df.index.max()):
> dx = self.contour_df['delta_utmx_volc'][i]
> dy = self.contour_df['delta_utmy_volc'][i]
>
> if dx > 0 and dy > 0:
> self.contour_df['volc_azimuth'][i] = self.contour_df['volc_theta'][i]
>
> elif dx > 0 > dy:
> self.contour_df['volc_azimuth'][i] = 180 - self.contour_df['volc_theta'][i]
>
> elif dx < 0 and dy < 0:
> self.contour_df['volc_azimuth'][i] = 180 + self.contour_df['volc_theta'][i]
>
> elif dx < 0 < dy:
> self.contour_df['volc_azimuth'][i] = 360 - self.contour_df['volc_theta'][i]
>
> if i % 50 == 0:
> self.yield_thread()
>
> self.contour_df['volc_dist'] = np.sqrt((self.contour_df['delta_utmy_volc']**2) + (self.contour_df['delta_utmx_volc']**2)) # distance from point to volcano
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20191206/80d23259/attachment.html>
More information about the PySide
mailing list