The tensor flow functions tf.einsum, tf.matmuland tf.tensordotcan be used for the same tasks. (I understand that tf.einsumthey tf.tensordothave more general definitions, I also understand that it tf.matmulhas batch functionality.) In a situation where any of the three can be used, does one function tend to be the fastest? Are there other guidelines for recommendations?
For example, suppose you Aare a rank-2 tensor, but ba rank-1 tensor, and you want to calculate the product c_j = A_ij b_j. Of the three options:
c = tf.einsum('ij,j->i', A, b)
c = tf.matmul(A, tf.expand_dims(b,1))
c = tf.tensordot(A, b, 1)
is generally preferable to others?
source
share