Find the underlying tf.Variable object.

  Args:
    t: a Tensor

  Returns:
    tf.Variable.
423437
def underlying_variable(t):
  
  t = underlying_variable_ref(t)
  assert t is not None
  # make sure that the graph has a variable index and that it is up-to-date
  if not hasattr(tf.get_default_graph(), "var_index"):
    tf.get_default_graph().var_index = {}
  var_index = tf.get_default_graph().var_index
  for v in tf.global_variables()[len(var_index):]:
    var_index[v.name] = v
  return var_index[t.name]
872665
def _get_variable_value(defined_variables, name):
    
    def fallback(*args, **kwargs):
        raise AssertionError("Variable {0} is not defined in class {1}".format(
                name, defined_variables.__class__.__name__))
    method = getattr(defined_variables, name, fallback)
    val = method()
    return method.field_type(val)
1225116
def getvariable(name):
    """"""
    import inspect
    fr = inspect.currentframe()
    try:
        while fr:
            fr = fr.f_back
            vars = fr.f_locals
            if name in vars:
                return vars[name]
    except:
        pass
    return None
1364324
def get_variables_path(export_dir):
  """"""
  return os.path.join(
      tf.compat.as_bytes(export_dir),
      tf.compat.as_bytes(tf_v1.saved_model.constants.VARIABLES_DIRECTORY),
      tf.compat.as_bytes(tf_v1.saved_model.constants.VARIABLES_FILENAME))
561244
def _parse_var_dict(self, var_tbl: dict) -> dict:
        
        var_names = var_tbl.copy()
        # check that all of the variables are bound
        for v in self.var_names:
            if v not in var_tbl:
                if self.var_names[v] is None:
                    raise(KeyError("variable " + v + " is unbound"))
                else:
                    var_names[v] = self.var_names[v]
        # squeeze the variables
        return self._squeeze(var_names)
835081
def isel_variable_and_index(
    name: Hashable,
    variable: Variable,
    index: pd.Index,
    indexers: Mapping[Any, Union[slice, Variable]],
) -> Tuple[Variable, Optional[pd.Index]]:
    """"""
    if not indexers:
        # nothing to index
        return variable.copy(deep=False), index

    if len(variable.dims) > 1:
        raise NotImplementedError(
            'indexing multi-dimensional variable with indexes is not '
            'supported yet')

    new_variable = variable.isel(indexers)

    if new_variable.dims != (name,):
        # can't preserve a index if result has new dimensions
        return new_variable, None

    # we need to compute the new index
    (dim,) = variable.dims
    indexer = indexers[dim]
    if isinstance(indexer, Variable):
        indexer = indexer.data
    new_index = index[indexer]
    return new_variable, new_index
988971
def get_source_var_declaration(self, var):
        
        return next((x.source_mapping for x in self.variables if x.name == var))
158037
def get_variable_ddi(name, shape, initial_value, dtype=tf.float32, init=False,
                     trainable=True):
  """"""
  # If init is a tf bool: w is assigned dynamically at runtime.
  # If init is a python bool: then w is determined during graph construction.
  w = tf.get_variable(name, shape, dtype, None, trainable=trainable)
  if isinstance(init, bool):
    if init:
      return assign(w, initial_value)
    return w
  else:
    return tf.cond(init, lambda: assign(w, initial_value), lambda: w)
105128
def variable(self):
        """"""
        # Use a character invalid in python identifiers to avoid clashing.
        name = "@py_assert" + str(next(self.variable_counter))
        self.variables.append(name)
        return name
909281
def get_neutralized_variable(variable):
    
    result = variable.clone()
    result.is_neutralized = True
    result.label = '[Neutralized]' if variable.label is None else '[Neutralized] {}'.format(variable.label),

    return result
1019691
def variable_iter(self, base):
        
        base_substs = dict(('<' + t + '>', u) for (t, u) in base.items())
        substs = []
        vals = []
        for with_defn in self.with_exprs:
            substs.append('<' + with_defn[0] + '>')
            vals.append(Host.expand_with(with_defn[1:]))
        for val_tpl in product(*vals):
            r = base_substs.copy()
            r.update(dict(zip(substs, val_tpl)))
            yield r
213051
def get_var(name, factory=None):
    
    if name not in _VARS and factory is not None:
        _VARS[name] = factory()
    return _VARS.get(name)
1129645
def getVariable(self, name):
        
        return lock_and_call(
            lambda: Variable(self._impl.getVariable(name)),
            self._lock
        )
1155126
def generic_var(self, key, value=None):
        
        return self._get_or_set('{0}{1}'.format(self._GENERIC_VAR_KEY_PREFIX, key), value)
778042
def _check_forward_mode_input_dict(self, var_tbl: dict) -> int:
        
        T: int = 1
        for var_name in var_tbl:
            # The bound value to this variable name
            val = var_tbl[var_name]
            # case 1: this is a scalar; T=1
            if isinstance(val, scalar_instance_types):
                t = 1
            # case 2: this is an array; calulate T
            elif isinstance(val, np.ndarray):
                t = self._calc_T_var(val)
            #case 3: throw an error
            else:
                raise ValueError(f'val={val} in var_tbl; {type(val)} not a recognized value type.')
            #update T
            if t > 1 and T == 1:
                T = t
            elif t not in (1,T):
                raise ValueError(f'Bound variable {var_name} has inconsistent shape')
        return T
473798
def weight_variable(name, shape, trainable):
        
        w = tf.get_variable(name=name, shape=shape, initializer=tf.contrib.layers.variance_scaling_initializer(),
                            trainable=trainable)
        weights_norm = tf.reduce_sum(tf.nn.l2_loss(w),
                                     name=name + '_norm')  # Should user want to optimize weight decay
        tf.add_to_collection('weight_losses', weights_norm)
        return w
1141610
def cast(self, dtype: tf.DType) -> 'TensorFluent':
        '''
        '''
        if self.dtype == dtype:
            return self
        t = tf.cast(self.tensor, dtype)
        scope = self.scope.as_list()
        batch = self.batch
        return TensorFluent(t, scope, batch=batch)