Returns a `Tensor`.
349059
def _get_dense_tensor(self, inputs, weight_collections=None, trainable=None):
    """"""
    del weight_collections
    text_batch = tf.reshape(inputs.get(self), shape=[-1])
    m = module.Module(self.module_spec, trainable=self.trainable and trainable)
    return m(text_batch)
857178
def batch_tensor(self, name):
        
        if name in self.transition_tensors:
            return tensor_util.merge_first_two_dims(self.transition_tensors[name])
        else:
            return self.rollout_tensors[name]
812111
def get_tensors_by_names(names):
    
    ret = []
    G = tfv1.get_default_graph()
    for n in names:
        opn, varn = get_op_tensor_name(n)
        ret.append(G.get_tensor_by_name(varn))
    return ret
1026901
def rank(tensor: BKTensor) -> int:
    """"""
    if isinstance(tensor, np.ndarray):
        return len(tensor.shape)

    return len(tensor[0].size())
188114
def augment_tensor(matrix, ndim=None):
    
    s = matrix.shape
    if ndim is None:
        ndim = s[0]+1
    arr = N.identity(ndim)
    arr[:s[0],:s[1]] = matrix
    return arr
1331441
def as_proto(self):
        """"""
        if self._dims is None:
            return tensor_shape_pb2.TensorShapeProto(unknown_rank=True)
        else:
            return tensor_shape_pb2.TensorShapeProto(
                dim=[
                    tensor_shape_pb2.TensorShapeProto.Dim(
                        size=-1 if d.value is None else d.value
                    )
                    for d in self._dims
                ]
            )
257349
def nest(thing):
    """"""
    tfutil = util.get_module('tensorflow.python.util')
    if tfutil:
        return tfutil.nest.flatten(thing)
    else:
        return [thing]
878765
def cat(tensors, dim=0):
    
    assert isinstance(tensors, (list, tuple))
    if len(tensors) == 1:
        return tensors[0]
    return torch.cat(tensors, dim)
728396
def _name_to_tensor(self, tensor_name):
    
    id1, id2 = self._tensor_name_to_ids[tensor_name]
    return self._operations[id1].outputs[id2]
1243132
def tensor_components_to_use(mrr, mtt, mpp, mrt, mrp, mtp):
    '''
    
    '''
    return np.array([[mrr, mrt, mrp], [mrt, mtt, mtp], [mrp, mtp, mpp]])
224123
def _call(self, x):
        """"""
        result = self.sess.run(self.output_tensor,
                               feed_dict={self.input_tensor: np.asarray(x)})

        return result
191820
def slice(self, tf_tensor, tensor_shape):
    """""""
    tensor_layout = self.tensor_layout(tensor_shape)

    if tensor_layout.is_fully_replicated:
      return self.LaidOutTensor([tf_tensor])
    else:
      slice_shape = self.slice_shape(tensor_shape)
      slice_begins = [
          self.slice_begin(tensor_shape, pnum) for pnum in xrange(self.size)
      ]
      slice_begins_tensor = tf.stack(slice_begins)
      # slice on source device
      selected_slice_begin = tf.gather(slice_begins_tensor, self.pnum_tensor)
      return self.LaidOutTensor(
          [tf.slice(tf_tensor, selected_slice_begin, slice_shape)])
44533
def unwrap(tensor):
  
  while isinstance(tensor, (PrettyTensor, Loss)):
    tensor = tensor.tensor
  return tensor
56985
def convert_tensor(input_, device=None, non_blocking=False):
    """"""
    def _func(tensor):
        return tensor.to(device=device, non_blocking=non_blocking) if device else tensor

    return apply_to_tensor(input_, _func)
32686
def optimizer_tensor(self) -> Union[tf.Tensor, tf.Operation]:
        
        return _get_attr(self, _optimizer_tensor=None)
837706
def _dense_var_to_tensor(self, dtype=None, name=None, as_ref=False):
    """"""
    # pylint: disable=protected-access
    if _enclosing_tpu_context() is None:
      if hasattr(self._primary_var, '_dense_var_to_tensor'):
        return self._primary_var._dense_var_to_tensor(dtype, name, as_ref)
      else:
        return ops.convert_to_tensor(self._primary_var)
    # pylint: enable=protected-access
    if dtype is not None and dtype != self.dtype:
      return NotImplemented
    if as_ref:
      return self.handle
    else:
      return self.read_value()
759528
def _get_node_name_from_tensor(tensor_name):
  """"""
  result = re.match(r"([^:]*):\d+$", tensor_name)
  if not result:
    raise ValueError(
        "Unexpected format for tensor name. Expected node_name:output_number. "
        "Got %r" % tensor_name)
  return result.group(1)