JorritMontijn / zetapy

Python code implementing the ZETA-test
GNU General Public License v3.0
20 stars 7 forks source link

correct typing after np.round in plotting dependencies #11

Closed wulfdewolf closed 7 months ago

wulfdewolf commented 7 months ago

In plotzeta2, np.round is used to round to integers. However, np.round does not intrinsically return integers, if any of its arguments is a float, a float is returned.

On lines 227 & 228 in plot_dependencies.py, this results in a type mismatch:

227        intPlotSpikeNum1 = np.round(dblReduceSpikesBy * vecSpikeTimes1.size)
228        intPlotSpikeNum2 = np.round(dblReduceSpikesBy * vecSpikeTimes2.size)

and on lines 233 & 234 in plot_dependencies.py, the result of np.linspace has to be rounded to integers as well:

233        vecSpikeT1_reduced = vecSpikeTimes1[np.round(np.linspace(0, vecSpikeTimes1.size-1, intPlotSpikeNum1))]
234        vecSpikeT2_reduced = vecSpikeTimes1[np.round(np.linspace(0, vecSpikeTimes2.size-1, intPlotSpikeNum2))]

The same issue occurs in plotzeta, but only for the np.linspace case.

On line 388 in plot_dependencies.py:

378        vecSpikeT_reduced = vecSpikeTimes[np.round(np.linspace(0, vecSpikeTimes.size-1, intPlotSpikeNum))]

All of these can be fixed by adding .astype(int).

I am using Ubuntu 22.04.3 LTS, with the latest commit of the repository 1bd4862, and numpy version 1.24.4.

guidomeijer commented 7 months ago

Thank you for your fix! I've merged the pull request and updated the pip package, zetapy 3.0.5 contains this fix.