loom.py 文件源码

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

项目:fold 作者: tensorflow 项目源码 文件源码
def __new__(cls, dtype=None, shape=None, tag='', tensor=None):
    if tensor is not None:
      if dtype is not None:
        raise TypeError('Specify only one of tensor and dtype.')
      if shape is not None:
        raise TypeError('Specify only one of tensor and shape.')
      dtype = tensor.dtype
      shape = tensor.get_shape().as_list()
    elif not (isinstance(dtype, tf.DType) or
              isinstance(dtype, six.string_types)):
      raise TypeError('%r is not a tf.DType or string' % (dtype,))
    dtype = tf.as_dtype(dtype).base_dtype.name
    if not all(isinstance(s, numbers.Integral) and s >= 0 for s in shape):
      raise TypeError('shape must be non-negative integers: %s' % shape)
    shape = tuple(int(s) for s in shape)
    if not isinstance(tag, six.string_types):
      raise TypeError('A TypeShape tag must be a string; type of %r is %s' %
                      (tag, type(tag)))
    return _TypeShape.__new__(cls, dtype, shape, tag)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号