张量流中记录了`*`在哪里?

use*_*739 5 python multiplying python-3.x tensorflow

我没有找到记录在哪里*.似乎它可以等同于tf.multiplytf.scalar_mul.是这样吗?

Max*_*xim 5

最可靠的文档是源代码

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")
Run Code Online (Sandbox Code Playgroud)

这意味着__mul__运算符重载,即_mul_dispatch. 如您所见,它调用gen_math_ops._mul(这是 的底层核心函数tf.multiply)或sparse_dense_cwise_mul张量是否稀疏。

顺便说一下,tf.scalar_mul它只是scalar * x源代码)的一个包装器,所以它基本上是一样的,但依赖是相反的。