tensor_signature.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:lsdc 作者: febert 项目源码 文件源码
def is_compatible_with(self, other):
    """Returns True if signatures are compatible."""

    def _shape_is_compatible_0dim(this, other):
      """Checks that shapes are compatible skipping dim 0."""
      other = tensor_shape.as_shape(other)
      # If shapes are None (unknown) they may be compatible.
      if this.dims is None or other.dims is None:
        return True
      if this.ndims != other.ndims:
        return False
      for dim, (x_dim, y_dim) in enumerate(zip(this.dims, other.dims)):
        if dim == 0:
          continue
        if not x_dim.is_compatible_with(y_dim):
          return False
      return True

    if other.is_sparse:
      return self.is_sparse and self.dtype.is_compatible_with(other.dtype)
    return (self.dtype.is_compatible_with(other.dtype) and
            _shape_is_compatible_0dim(self.shape, other.shape) and
            not self.is_sparse)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号