lizhihao6 / Forward-Warp

An optical flow forward warp's lib with backpropagation using pytorch.
MIT License
109 stars 17 forks source link

unexpected result of "assert ... or 1" #5

Closed tkkcc closed 3 years ago

tkkcc commented 3 years ago

This assert's result is unexpected. https://github.com/lizhihao6/Forward-Warp/blob/master/Forward_Warp/forward_warp.py#L19

In [7]: a=2

In [8]: assert a is 0 or 1

In [9]: assert (a is 0 or 1)

In [10]: assert a is 0
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-10-84d2b10b4afa> in <module>
----> 1 assert a is 0

AssertionError:

In [11]: assert a == 0
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-11-4321e3980dbd> in <module>
----> 1 assert a == 0

AssertionError:

In [12]: assert a == 0 or 1

In [13]: assert(a == 0 or 1)

In [15]: assert a in (0 , 1)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-15-51fbe2680d83> in <module>
----> 1 assert a in (0 , 1)

AssertionError:

In [16]: assert a in (0, 1, 2)

So I will stick to use "assert x in (...)"

lizhihao6 commented 3 years ago

Thx for your attention. Possible python syntax feature change, forward_warp.py has been changed and commited.