Using tf.matmul vs ed.dot

Quick question

In the tutorials, for instance, in the bayesian linear regression, the model is defined as

y = Normal(loc=ed.dot(X, w) + b, scale=1.0)

however for a multiple output case, w is a matrix and one no longer multiplies a matrix by a vector.

My question is is there any reason not to use tf.matmul instead of ed.dot. Looking at the source it seems like it is more of a convenience function wrapping tf.matmul if the input isn’t formatted as a matrix and has NaNs or Infs with

verify_tensor_all_finite

x = control_flow_ops.with_dependencies(dependencies, x)

Is there any reason, assuming you already know your input data is going to be valid, to simply use tf.matmul.
For instance, if your data has NaNs or Infs then the dot product won’t work in the first place and something will break anyway. So it appears to be primarily for logging purposes.
I might be missing something subtle however

So instead is it perfectly fine to use something like

y = Normal(loc=tf.matmul(X, w) + b, scale=1.0)

cheers!

You are correct. ed.dot is a convenience function for matrix-vector products. tf.matmul works only on matrices and returns a matrix. If w and y are indeed both matrices as in your setting, then tf.matmul is more appropriate.

2 Likes

awesome, thanks dustin