예제 #1
0
def __sub__(layeroutput, other):
    if is_compatible_with(other, float):
        return layer.slope_intercept(input=layeroutput, intercept=other)
    if not isinstance(other, Layer):
        raise TypeError("Layer can only be subtracted with"
                        " another Layeroutput or a number")
    return __add__(layeroutput, -other)
예제 #2
0
파일: op.py 프로젝트: absorbguo/Paddle
def __sub__(layeroutput, other):
    if is_compatible_with(other, float):
        return layer.slope_intercept(input=layeroutput, intercept=other)
    if not isinstance(other, Layer):
        raise TypeError("Layer can only be subtracted with"
                        " another Layeroutput or a number")
    return __add__(layeroutput, -other)
예제 #3
0
파일: op.py 프로젝트: absorbguo/Paddle
def __mul__(layeroutput, other):
    if is_compatible_with(other, float):
        return layer.slope_intercept(input=layeroutput, slope=other)
    if not isinstance(other, Layer):
        raise TypeError("Layer can only be multiplied with"
                        " another Layer or a number")
    elif layeroutput.size == 1:
        return layer.scaling(input=other, weight=layeroutput)
    elif other.size == 1:
        return layer.scaling(input=layeroutput, weight=other)
    else:
        raise TypeError("At least one of the operand of '*' must be a number"
                        " or a Layer with size=1")
예제 #4
0
def __mul__(layeroutput, other):
    if is_compatible_with(other, float):
        return layer.slope_intercept(input=layeroutput, slope=other)
    if not isinstance(other, Layer):
        raise TypeError("Layer can only be multiplied with"
                        " another Layer or a number")
    elif layeroutput.size == 1:
        return layer.scaling(input=other, weight=layeroutput)
    elif other.size == 1:
        return layer.scaling(input=layeroutput, weight=other)
    else:
        raise TypeError("At least one of the operand of '*' must be a number"
                        " or a Layer with size=1")
예제 #5
0
파일: op.py 프로젝트: absorbguo/Paddle
def __add__(layeroutput, other):
    if is_compatible_with(other, float):
        return layer.slope_intercept(input=layeroutput, intercept=other)
    if not isinstance(other, Layer):
        raise TypeError("Layer can only be added with"
                        " another Layer or a number")
    if layeroutput.size == other.size:
        return layer.mixed(input=[
            layer.identity_projection(input=layeroutput),
            layer.identity_projection(input=other)
        ])
    if other.size != 1 and layeroutput.size != 1:
        raise TypeError("Two Layer can be added only if they have equal size"
                        " or one of their sizes is 1. sizes are %s and %s" %
                        (layeroutput.size, other.size))
    elif layeroutput.size == 1:
        tmp = layeroutput
        layeroutput = other
        other = tmp
    other = layer.repeat(other, layeroutput.size)
    return layer.mixed(input=[
        layer.identity_projection(input=layeroutput),
        layer.identity_projection(input=other)
    ])
예제 #6
0
def __add__(layeroutput, other):
    if is_compatible_with(other, float):
        return layer.slope_intercept(input=layeroutput, intercept=other)
    if not isinstance(other, Layer):
        raise TypeError("Layer can only be added with"
                        " another Layer or a number")
    if layeroutput.size == other.size:
        return layer.mixed(input=[
            layer.identity_projection(input=layeroutput),
            layer.identity_projection(input=other)
        ])
    if other.size != 1 and layeroutput.size != 1:
        raise TypeError("Two Layer can be added only if they have equal size"
                        " or one of their sizes is 1. sizes are %s and %s" %
                        (layeroutput.size, other.size))
    elif layeroutput.size == 1:
        tmp = layeroutput
        layeroutput = other
        other = tmp
    other = layer.repeat(other, layeroutput.size)
    return layer.mixed(input=[
        layer.identity_projection(input=layeroutput),
        layer.identity_projection(input=other)
    ])
예제 #7
0
파일: op.py 프로젝트: absorbguo/Paddle
def __rsub__(layeroutput, other):
    neg = layer.slope_intercept(input=layeroutput, slope=-1.0)
    return __add__(neg, other)
예제 #8
0
파일: op.py 프로젝트: absorbguo/Paddle
def __neg__(layeroutput):
    return layer.slope_intercept(input=layeroutput, slope=-1.0)
예제 #9
0
def __rsub__(layeroutput, other):
    neg = layer.slope_intercept(input=layeroutput, slope=-1.0)
    return __add__(neg, other)
예제 #10
0
def __neg__(layeroutput):
    return layer.slope_intercept(input=layeroutput, slope=-1.0)