mabelcalim / waipy

This guide includes a Continuous Wavelet Transform (CWT), significance tests from based on Torrence and Compo (1998) and Cross Wavelet Analysis (CWA) based on Maraun and Kurths(2004).
https://wavelet-analysis.readthedocs.org/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
81 stars 49 forks source link

Update wavetest.py #29

Open mikesha2 opened 1 year ago

mikesha2 commented 1 year ago

Replaced bottleneck with logically equivalent code. There's a section in the code which appears to be useless, and is causing significant performance issues with large time series.

In line 169: k_pos is independent of k_neg: therefore we may just replace it with its final value.

Lines 170/171 overwrite k_neg every pass. Therefore, the final value of k_neg only depends on the final value of k_pos.

I was taking a significant performance hit for time series of length > 100,000. It's obvious now from the code why: the for loop (line 168) is linear in the time series length, and unnecessarily allocates/deallocates memory repeatedly, with O(n^2) memory used, since the length of k_neg is the same as the iterator i. The exact value is something like (n / 2) (n /2 + 1) / 2 excess memory operations.

mabelcalim commented 8 months ago

Hi @mikesha2 , thanks for pointed this out. I confess that I write scripts without worrying with the best performance. Thanks for the insight. Sorry it took me so long to approved it. Mabel