def cwise_linear()

in blocksparse/conv.py [0:0]


def cwise_linear(x, gain=None, bias=None, relu=False, bias_first=False, use_tf=False):

    assert gain is not None or bias is not None

    dev = x.op.device.lower()
    if use_tf or not dev or "cpu" in dev:
        if bias_first:
            if bias is not None:
                x += bias
            if gain is not None:
                x *= gain
        else:
            if gain is not None:
                x *= gain
            if bias is not None:
                x += bias
        return tf.nn.relu(x) if relu else x

    gain = [] if gain is None else [gain]
    bias = [] if bias is None else [bias]

    return cwise_linear_op(x, gain, bias, relu=relu, swap=bias_first)