Skip to content

Instantly share code, notes, and snippets.

@chaserileyroberts
Created May 7, 2019 18:56
Show Gist options
  • Save chaserileyroberts/4935b6ac2f804694bbb7e7b084d71e35 to your computer and use it in GitHub Desktop.
Save chaserileyroberts/4935b6ac2f804694bbb7e7b084d71e35 to your computer and use it in GitHub Desktop.
import tensorflow as tf
tf.enable_v2_behavior()
def outer_product(x):
return tf.tensordot(x, x, 0)
val = tf.ones((1000, 32, 32))
%timeit tf.map_fn(outer_product, val)
# >>> 1 loops, best of 3: 849 ms per loop
%timeit tf.vectorized_map(outer_product, val)
# >>> 10 loops, best of 3: 37.8 ms per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment