Created
July 17, 2018 16:36
-
-
Save alexbw/da3c29a78cada53aadc0cc2e944def30 to your computer and use it in GitHub Desktop.
Collatz with AutoGraph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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