【问题标题】:Where is `*` documented in tensorflow?张量流中的“*”记录在哪里?
【发布时间】:2017-12-11 04:55:01
【问题描述】:

我找不到 * 的记录位置。它似乎可以等效于tf.multiplytf.scalar_mul。是这样吗?

【问题讨论】:

    标签: python python-3.x tensorflow multiplication


    【解决方案1】:

    最可靠的文档是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")
    

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

    顺便说一句,tf.scalar_mul 只是 scalar * x (source code) 的一个包装器,所以基本上是一样的,但是依赖关系是相反的。

    【讨论】:

    • 阅读源代码以了解其工作原理可能会导致将实施误认为是合同
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    相关资源
    最近更新 更多