(x, b=None, dim=1, act='linear', alpha=None, gain=None, clamp=None)
return x
Slow reference implementation of `bias_act()` using standard TensorFlow ops.
Slow reference implementation of `bias_act()` using standard TensorFlow ops.
Slow reference implementation of bias_act () using standard TensorFlow ops .
def _bias_act_ref(x, b=None, dim=1, act='linear', alpha=None, gain=None, clamp=None):
    """Slow reference implementation of `bias_act()` using standard TensorFlow ops.
    """
    assert isinstance(x, torch.Tensor)
    assert clamp is None or clamp >= 0
    spec = activation_funcs[act]
    alpha = float(alpha if alpha is not None else spec.def_alpha)
    gain = float(gain if gain is not None else spec.def_gain)
    clamp = float(clamp if clamp is not None else -1)

    # Add bias.
    if b is not None:
        assert isinstance(b, torch.Tensor) and b.ndim == 1
        assert 0 <= dim < x.ndim
        assert b.shape[0] == x.shape[dim]
        x = x + b.reshape([-1 if i == dim else 1 for i in range(x.ndim)])

    # Evaluate activation function.
    alpha = float(alpha)
    x = spec.func(x, alpha=alpha)

    # Scale by gain.
    gain = float(gain)
    if gain != 1:
        x = x * gain

    # Clamp.
    if clamp >= 0:
        x = x.clamp(-clamp, clamp) # pylint: disable=invalid-unary-operand-type
    return x
def _bias_act_ref ( x , b = None , dim = 1 , act = 'linear' , alpha = None , gain = None , clamp = None ) : assert isinstance ( x , torch . Tensor ) assert clamp is None or clamp >= 0 spec = activation_funcs [ act ] alpha = float ( alpha if alpha is not None else spec . def_alpha ) gain = float ( gain if gain is not None else spec . def_gain ) clamp = float ( clamp if clamp is not None else - 1 ) # Add bias. if b is not None : assert isinstance ( b , torch . Tensor ) and b . ndim == 1 assert 0 <= dim < x . ndim assert b . shape [ 0 ] == x . shape [ dim ] x = x + b . reshape ( [ - 1 if i == dim else 1 for i in range ( x . ndim ) ] ) # Evaluate activation function. alpha = float ( alpha ) x = spec . func ( x , alpha = alpha ) # Scale by gain. gain = float ( gain ) if gain != 1 : x = x * gain # Clamp. if clamp >= 0 : x = x . clamp ( - clamp , clamp ) # pylint: disable=invalid-unary-operand-type return x