paulbrodersen / netgraph

Publication-quality network visualisations in python
GNU General Public License v3.0
660 stars 39 forks source link

(Suggestion) Handling div-by-zero #81

Open rtbs-dev opened 5 months ago

rtbs-dev commented 5 months ago

Hi there! Running into a number of division warnings throughout the layout algorithm code, and thought I might offer up a few solutions for consideration

For reference, here's an example just now when using the edge_layout='curved' option:

python3.11/site-packages/netgraph/_utils.py:360: RuntimeWarning: invalid value encountered in divide
  v = v / np.linalg.norm(v, axis=-1)[:, None] # unit vector

Some additive-smoothing code I was writing ran into stuff like this all the time before I switched to either a pre-allocated np.zeros_like or an np.mask.

paulbrodersen commented 5 months ago

Thanks, I am actually in the process of hunting down all warnings as part of the next major release, so this is very helpful. If you let me know your github associated email address, then I can credit you in the commit (once I get to it).