google / tangent

Source-to-Source Debuggable Derivatives in Pure Python
Apache License 2.0
2.32k stars 434 forks source link

fail to import tangent #99

Closed JiafengYang closed 4 years ago

JiafengYang commented 4 years ago

I have inatalled the tangent, but there is a problem when I import it Here is a simple example: import tangent

The error shows that : File "/anaconda3/lib/python3.7/site-packages/tangent/utils.py", line 229, in register_shape_function assert t not in shape_functions AssertionError

Thanks in advance !

mdanatg commented 4 years ago

This is probably due to some change in one of the underlying platforms. Tangent is not being actively maintained any more, but it should be fairly straightforward to fix this by changing shape_functions from a dict of type to callable to a dict of type to tuple of callables. It should only be used in a small number of places like unreduce_like.

Sijie-L commented 4 years ago

This is probably due to some change in one of the underlying platforms. Tangent is not being actively maintained any more, but it should be fairly straightforward to fix this by changing shape_funcrtions from a dict of type to callable to a dict of type to tuple of callables. It should only be used in a small number of places like unreduce_like.

Could you please specify the exact code to add? I encounter this same problem while importing tangent after using the code in #95 .

mdanatg commented 4 years ago

Sorry, it's been a while, and I don't remember why I suggested that. Have a look at https://github.com/google/tangent/blob/master/tangent/utils.py - the assertion failure suggests register_shape_function is called repeatedly with the same type, and it shouldn't. It would be useful to understand why it gets called repeatedly, and if doing that is fine, just remove the assertion.