DSE-MSU / DeepRobust

A pytorch adversarial library for attack and defense methods on images and graphs
MIT License
994 stars 192 forks source link

Update utils.py to fix PyTorch __floordiv__ warning #97

Closed aravind-gk closed 2 years ago

aravind-gk commented 2 years ago

I encounter the following warning when I run the test example testmettack.py, because of a deprecated __floordiv_\ in PyTorch:

deeprobust-0.2.3-py3.7.egg/deeprobust/graph/utils.py:544: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').

This one-line change to utils.py fixes the above issue.

ChandlerBang commented 2 years ago

Hi, thanks for the pull. I agree that might cause "incorrect rounding for negative values". But the index value should be always positive so I assume there should no problem for the floor operation?

aravind-gk commented 2 years ago

Yes, the final values resulting from the operations are the same. I just thought that deprecated warning should be fixed. Thanks for the quick reply!

ChandlerBang commented 2 years ago

I see. Will merge it. Thanks!