Exemple #1
0
def test_equal6():
    """
    x != y broadcast
    """
    x = randtool("float", -10, 10, [3, 3, 3, 1])
    y = randtool("float", -10, 10, [3, 3, 1])
    res = np.equal(x, y)
    obj.run(res=res, x=x, y=y)
Exemple #2
0
def test_pow1():
    """
    y = 0
    """
    x = randtool("float", 1, 2, [2, 2, 2])
    y = randtool("int", 2, 3, [1, 1, 1])
    res = np.power(x, y)
    obj.run(res=res, x=x, y=y)
Exemple #3
0
def test_equal5():
    """
    x != y
    """
    x = randtool("float", -10, 10, [3, 3, 3])
    y = randtool("float", -10, 10, [3, 3, 3])
    res = np.equal(x, y)
    obj.run(res=res, x=x, y=y)
Exemple #4
0
def test_elementwise_pow():
    """
    default
    """
    x = randtool("float", 1, 2, [2, 2, 2])
    y = randtool("int", 1, 2, [2, 2, 2])
    res = np.power(x, y)
    obj.run(res=res, x=x, y=y)
def test_elementwise_floordiv():
    """
    default
    """
    x = randtool("float", -10, 10, [3, 3, 3])
    y = randtool("float", -10, 10, [3, 3, 3])
    res = np.divide(x, y)
    print(res)
    obj.run(res=res, x=x, y=y)
def test_elementwise_mul():
    """
    default
    """
    x = randtool("float", -10, 10, [3, 3, 3])
    y = randtool("float", -10, 10, [3, 3, 3])
    res = np.multiply(x, y)
    print(res)
    obj.run(res=res, x=x, y=y)
def test_elementwise_add():
    """
    default
    """
    x = randtool("float", -10, 10, [1024, 8192])
    y = randtool("float", -10, 10, [1024, 8192])
    res = np.add(x, y)
    print(res)
    obj.run(res=res, x=x, y=y)
Exemple #8
0
def test_elementwise_sub():
    """
    default
    """
    x = randtool("float", -10, 10, [3, 3, 3])
    y = randtool("float", -10, 10, [3, 3, 3])
    res = x - y
    # print(res)
    obj.run(res=res, x=x, y=y)
def test_elementwise_mul():
    """
    default
    """
    x = randtool("float", -10, 10, [1])
    y = randtool("float", -10, 10, [1232, 19000])
#    res = np.multiply(x, y)
    res = [1]
    print(res)
    obj.run(res=res, x=x, y=y)
Exemple #10
0
def test_tanh():
    """
    x=+
    """
    x = randtool('float', 1, 10, [3, 3, 3])
    res = np.tanh(x)
    obj.run(res=res, x=x)
Exemple #11
0
def test_relu():
    """
    default
    """
    x = randtool("float", -10, 10, [10, 10, 10])
    res = np.maximum(0, x)
    obj.run(res=res, x=x)
Exemple #12
0
def test_relu_base():
    """
    base
    """
    x = randtool("float", -10, 10, [3, 3, 3])
    res = np.maximum(0, x)
    obj.run(res=res, x=x)
Exemple #13
0
def test_pow1():
    """
    y = 0
    """
    x = randtool("float", 1, 2, [2, 2, 2])
    y = 0
    res = np.power(x, y)
    obj.run(res=res, x=x, factor=y)
Exemple #14
0
def test_equal():
    """
    default
    """
    x = randtool("int", -10, 10, [3, 3, 3])
    y = x
    res = np.equal(x, y)
    obj.run(res=res, x=x, y=y)
Exemple #15
0
def test_gelu1():
    """
    approximate=True
    """
    x = randtool("float", -10, 10, [3, 3, 3])
    # 算法
    res = 0.5 * x * (1 +
                     tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * pow(x, 3))))
    obj.run(res=res, x=x)
Exemple #16
0
def test_gelu():
    """
    default approximate=False
    """
    x = randtool("float", -10, 10, [3, 3, 3])
    # 算法
    arr = []
    for i in range(len(x.flatten())):
        arr.append(math.erf(x.flatten()[i] / math.sqrt(2)))
    arr = np.array(arr).reshape(x.shape)
    res = 0.5 * x * (1 + arr)
    obj.run(res=res, x=x)