【问题标题】:How do deep learning libraries implicity find operations on variables that don't call library functions?深度学习库如何隐式查找不调用库函数的变量的操作?
【发布时间】:2017-11-27 19:19:52
【问题描述】:

例如,在 TensorFlow 中, tf.matmul(x, y) 等价于 python3.5+ 中的x @ y。 如果没有函数告诉它,Tensorflow 如何隐式知道将x @ y 操作添加到图中?它是在 C 后端完成的吗?我四处寻找,没有找到喜欢的东西。

【问题讨论】:

    标签: python-3.x tensorflow deep-learning


    【解决方案1】:

    使用运算符重载是可能的。

    xy 都具有 Tensor 类型。 Tensor 实现了__matmul__ 方法(对应于@ 运算符)。

    __matmul__ 的实现可能如下所示:

    def __matmul__(self, other):
        return tf.matmul(self, other)
    

    关于运算符重载的官方文档:link

    【讨论】:

      猜你喜欢
      • 2022-11-03
      • 2015-03-14
      • 1970-01-01
      • 2016-11-29
      • 2020-11-10
      • 2018-03-29
      • 1970-01-01
      • 2018-12-27
      • 2016-12-23
      相关资源
      最近更新 更多