tensorflow 中的 `*` 在哪里记录? [英] Where is `*` documented in tensorflow?

查看:114
本文介绍了tensorflow 中的 `*` 在哪里记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有找到记录 * 的地方.似乎它可以等同于 tf.multiplytf.scalar_mul.是吗?

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?

推荐答案

最可靠的文档是 源代码:

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 如果张量是稀疏的.

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.

顺便说一下,tf.scalar_mul 只是对 scalar * x 的封装(源代码),所以基本上是一样的,但依赖是相反的.

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.

这篇关于tensorflow 中的 `*` 在哪里记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆