Skip to content

Instantly share code, notes, and snippets.

@alexbw
Created July 17, 2018 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbw/da3c29a78cada53aadc0cc2e944def30 to your computer and use it in GitHub Desktop.
Save alexbw/da3c29a78cada53aadc0cc2e944def30 to your computer and use it in GitHub Desktop.
Collatz with AutoGraph
def collatz(a):
counter = 0
while a != 1:
if a % 2 == 0:
a = a // 2
else:
a = 3 * a + 1
counter = counter + 1
return counter
graph_mode_collatz = autograph.to_graph(collatz)
# The code is human-readable, too
print(autograph.to_code(collatz))
collatz_tensor = graph_mode_collatz(tf.constant(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment