Reputation: 13735
I don't find where *
is documented. It seems that it can be equivalent to either tf.multiply
or tf.scalar_mul
. Is it so?
Upvotes: 5
Views: 791
Reputation: 53768
The most reliable documentation is the source code:
def _mul_dispatch(x, y, name=None):
"""Dispatches cwise mul for "Dense*Dense" and "Dense*Sparse"."""
is_tensor_y = isinstance(y, ops.Tensor)
if is_tensor_y:
return gen_math_ops._mul(x, y, name=name)
else:
assert isinstance(y, sparse_tensor.SparseTensor) # Case: Dense * Sparse.
new_vals = gen_sparse_ops.sparse_dense_cwise_mul(y.indices, y.values,
y.dense_shape, x, name)
return sparse_tensor.SparseTensor(y.indices, new_vals, y.dense_shape)
...
_OverrideBinaryOperatorHelper(_mul_dispatch, "mul")
This means __mul__
operator overload, which does _mul_dispatch
. As you can see, it calls either gen_math_ops._mul
(which is the under-the-hood core function of tf.multiply
) or sparse_dense_cwise_mul
if the tensor is sparse.
By the way, tf.scalar_mul
is just a wrapper over scalar * x
(source code), so it's basically the same thing, but the dependency is the other way around.
Upvotes: 5