コード例 #1
0
def test():
    numpyX = np.array([1, 2, 3])
    numpyY = np.array([4, 5, 6])

    x = lg.array(numpyX)
    y = lg.array(numpyY)

    z = x + y
    # # print(z)
    assert np.array_equal(z, numpyX + numpyY)

    z = x + 2
    # print(z)
    assert np.array_equal(z, numpyX + 2)

    z = 2 + x
    # print(z)
    assert np.array_equal(z, 2 + numpyX)

    z = x - y
    # print(z)
    assert np.array_equal(z, numpyX - numpyY)

    z = x - 2
    # print(z)
    assert np.array_equal(z, numpyX - 2)

    z = 2 - x
    # print(z)
    assert np.array_equal(z, 2 - numpyX)

    z = x / y
    # print(z)
    assert np.array_equal(z, numpyX / numpyY)

    z = x / 2
    # print(z)
    assert np.array_equal(z, numpyX / 2)

    z = 2 / x
    # print(z)
    assert np.array_equal(z, 2 / numpyX)

    z = x * y
    # print(z)
    assert np.array_equal(z, numpyX * numpyY)

    z = x * 2
    # print(z)
    assert np.array_equal(z, numpyX * 2)

    z = 2 * x
    # print(z)
    assert np.array_equal(z, 2 * numpyX)

    z = x**5
    # print(z)
    assert np.array_equal(z, numpyX**5)

    return
コード例 #2
0
def test():
    a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    a_lg = lg.array(a)
    b_lg = a_lg.swapaxes(0, 1)

    print("small")
    assert lg.array_equal(a_lg.sum(axis=0), b_lg.sum(axis=1))

    a_tall = np.concatenate((a, ) * 100)
    a_tall_lg = lg.array(a_tall)
    b_tall_lg = a_tall_lg.swapaxes(0, 1)

    print("tall")
    assert lg.array_equal(a_tall_lg.sum(axis=0), b_tall_lg.sum(axis=1))

    a_wide = np.concatenate((a, ) * 100, axis=1)
    a_wide_lg = lg.array(a_wide)
    b_wide_lg = a_wide_lg.swapaxes(0, 1)

    print("wide")
    assert lg.array_equal(a_wide_lg.sum(axis=0), b_wide_lg.sum(axis=1))

    a_big = np.concatenate((a_tall, ) * 100, axis=1)
    a_big_lg = lg.array(a_big)
    b_big_lg = a_big_lg.swapaxes(0, 1)

    print("big")
    assert lg.array_equal(a_big_lg.sum(axis=0), b_big_lg.sum(axis=1))
コード例 #3
0
ファイル: dot.py プロジェクト: prettywork2021/legate.numpy
def test():
    a = lg.array([[1, 2, 3, 4, 5, 6], [4, 5, 6, 7, 8, 9]], dtype=np.float64)
    b = lg.array(
        [[10, 11], [12, 13], [14, 15], [16, 17], [18, 19], [20, 21]],
        dtype=np.float64,
    )
    c = a.dot(b)
    assert lg.array_equal(c, [[350, 371], [620, 659]])

    d = lg.array([1, 2, 3, 4, 5, 6], dtype=np.float64)
    e = lg.array([1, 2, 3, 4, 5, 6], dtype=np.float64)
    f = d.dot(e)
    assert f == 91

    # This test does not work ATM. It seems that setting random seed to
    # be the same is not sufficient to make the inputs the same.

    # lg.random.seed(42)
    # a = lg.random.randn(1, 3, 15)
    # b = lg.random.randn(15, 16)
    # c = a[0].dot(b)

    # np.random.seed(42)
    # an = np.random.randn(1, 3, 15)
    # bn = np.random.randn(15, 16)
    # cn = an[0].dot(bn)

    # assert lg.allclose(c, cn)

    return
コード例 #4
0
def test():

    np.random.seed(42)
    An = np.random.randn(3, 7).astype(np.float16)
    Bn = np.random.randn(7).astype(np.float16)
    Cn = An.dot(Bn)

    A = lg.array(An)
    B = lg.array(Bn)
    C = A.dot(B)

    # print(C)
    # print(Cn)
    assert np.allclose(C, Cn)

    np.random.seed(42)
    An = np.random.randn(3, 7).astype(np.float16)
    Bn = np.random.randn(3).astype(np.float16)
    Cn = An.transpose().dot(Bn)

    A = lg.array(An)
    B = lg.array(Bn)
    C = A.transpose().dot(B)

    # print(C)
    # print(Cn)
    assert np.allclose(C, Cn)

    return
コード例 #5
0
def test():
    x = np.linspace(2.0, 3.0, num=5)
    y = lg.linspace(2.0, 3.0, num=5)
    assert np.array_equal(x, y)

    x = np.linspace(2.0, 3.0, num=5, endpoint=False)
    y = lg.linspace(2.0, 3.0, num=5, endpoint=False)
    assert np.array_equal(x, y)

    x = np.linspace(2.0, 3.0, num=5, retstep=True)
    y = np.linspace(2.0, 3.0, num=5, retstep=True)
    assert np.array_equal(x[0], y[0])
    assert x[1] == y[1]

    x = np.array([[0, 1], [2, 3]])
    y = np.array([[4, 5], [6, 7]])
    xp = lg.array(x)
    yp = lg.array(y)

    z = np.linspace(x, y, num=5, axis=0)
    w = lg.linspace(xp, yp, num=5, axis=0)
    assert np.array_equal(z, w)

    z = np.linspace(x, y, num=5, axis=1)
    w = lg.linspace(xp, yp, num=5, axis=1)
    assert np.array_equal(z, w)

    z = np.linspace(x, y, num=5, axis=2)
    w = lg.linspace(xp, yp, num=5, axis=2)
    assert np.array_equal(z, w)

    return
コード例 #6
0
def test():
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    assert np.array_equal(lg.divide(a, b), np.divide(anp, bnp))
コード例 #7
0
ファイル: tile.py プロジェクト: prettywork2021/legate.numpy
def test():
    a = lg.array([0, 1, 2])

    b = lg.tile(a, 4)
    assert lg.array_equal(b, [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2])

    c = lg.tile(a, (3, 4))
    assert lg.array_equal(
        c,
        [
            [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2],
            [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2],
            [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2],
        ],
    )

    d = lg.tile(a, (3, 1, 4))
    assert lg.array_equal(
        d,
        [
            [[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]],
            [[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]],
            [[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]],
        ],
    )

    e = lg.array([[1, 2], [3, 4]])

    f = lg.tile(e, 2)
    assert lg.array_equal(f, [[1, 2, 1, 2], [3, 4, 3, 4]])

    g = lg.tile(e, (2, 1))
    assert lg.array_equal(g, [[1, 2], [3, 4], [1, 2], [3, 4]])

    return
コード例 #8
0
def test():
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    assert np.array_equal(a / b, anp / bnp)
コード例 #9
0
def test():
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    assert np.array_equal(a * b, anp * bnp)
    return
コード例 #10
0
ファイル: scalar.py プロジェクト: prettywork2021/legate.numpy
def test():
    # test data type conversion
    x = lg.array([1, 2, 3])
    y = lg.array([1.0, 2.0, 3.0])

    assert lg.max(x) == lg.max(y)

    return
コード例 #11
0
def test():

    # test data type conversion
    x = lg.array([1])
    y = lg.array([1.0])
    assert lg.min(x) == lg.min(y)

    return
コード例 #12
0
def test():
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    assert np.array_equal(lg.multiply(a, b), np.multiply(anp, bnp))

    return
コード例 #13
0
def test():
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    np.true_divide(anp, bnp, out=anp)
    lg.true_divide(a, b, out=a)

    assert np.array_equal(a, anp)
コード例 #14
0
def test():
    x = lg.array([
        [1, 2, 3, 4],
        [5, 6, 7, 8],
        [9, 10, 11, 12],
        [13, 14, 15, 16],
        [17, 18, 19, 20],
    ])
    x[0, :] = 0
    assert lg.array_equal(x[0, :], [0, 0, 0, 0])

    y = lg.array([[20, 30, 40, 50], [70, 80, 90, 100]])
    x[1:4:2] = y
    assert lg.array_equal(x[1, :], [20, 30, 40, 50])
    assert lg.array_equal(x[3, :], [70, 80, 90, 100])

    input_size = 10
    hidden_size = 4
    WLSTM = lg.random.randn(input_size + hidden_size + 1, 4 *
                            hidden_size) / lg.sqrt(input_size + hidden_size)
    WLSTM[0, :] = 0  # initialize biases to zero
    assert lg.array_equal(
        WLSTM[0, :],
        [
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
        ],
    )

    lg.random.seed(10)
    WLSTM = lg.random.randn(15, 16)
    dIFOGt = lg.random.randn(3, 16)
    dHoutt_in = lg.random.randn(2, 3, 4)
    dHoutt = dHoutt_in.copy()
    dHint = dIFOGt.dot(WLSTM.transpose())
    temp = dHoutt[0, :] + dHint[:, 11:]
    dHoutt[0, :] = temp
    assert not lg.array_equal(dHoutt[0, :], dHoutt_in[0, :])

    return
コード例 #15
0
def test():
    np.random.seed(13)
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    anp *= bnp
    a *= b

    assert np.array_equal(a, anp)
コード例 #16
0
def test():
    bases_np = np.random.randn(4, 5)

    # avoid fractional exponents
    exponents_np = np.random.randint(10, size=(4, 5)).astype(np.float64)

    bases = lg.array(bases_np)
    exponents = lg.array(exponents_np)

    assert lg.allclose(lg.power(bases, exponents),
                       np.power(bases_np, exponents_np))
コード例 #17
0
def test():
    np.random.seed(13)
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    np.divide(anp, bnp, out=anp)
    lg.divide(a, b, out=a)

    assert np.array_equal(a, anp)
コード例 #18
0
def test():
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    np.subtract(anp, bnp, out=anp)
    lg.subtract(a, b, out=a)

    assert np.array_equal(a, anp)
    return
コード例 #19
0
def test():
    anp = np.random.randn(4, 5)
    bnp = np.random.randn(4, 5)
    a = lg.array(anp)
    b = lg.array(bnp)

    anp += bnp
    a += b

    assert np.array_equal(a, anp)
    return
コード例 #20
0
ファイル: copy.py プロジェクト: prettywork2021/legate.numpy
def test():
    x = lg.array([[1, 2, 3], [4, 5, 6]])
    y = lg.array([[7, 8, 9], [10, 11, 12]])
    xc = x.copy()
    yc = y.copy()
    x[0, :] = [7, 8, 9]
    y = lg.array([[10, 12, 13], [25, 26, 27]])
    w = x + y
    wc = xc + yc
    assert np.array_equal(w, [[17, 20, 22], [29, 31, 33]])
    assert np.array_equal(wc, [[8, 10, 12], [14, 16, 18]])
    return
コード例 #21
0
def test():
    x = lg.array([[1, 2, 3], [4, 5, 6]])
    y = lg.transpose(x)
    assert lg.array_equal(y, [[1, 4], [2, 5], [3, 6]])
    z = lg.transpose(y)
    assert lg.array_equal(x, z)

    x = lg.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    y = x.transpose()
    assert lg.array_equal(y, [[1, 4, 7], [2, 5, 8], [3, 6, 9]])
    z = lg.transpose(y)
    assert lg.array_equal(x, z)
    return
コード例 #22
0
def test():
    sr = pd.Series([1, 2, 3])
    array = np.asarray(sr)
    x = np.array([1, 2, 3])
    assert np.array_equal(array, x)

    y = np.array([4, 5, 6])
    z = np.add(sr, y)
    assert np.array_equal(z, x + y)

    df = pd.DataFrame({"x": x, "y": y})
    z = np.add(df["x"], df["y"])
    assert np.array_equal(z, x + y)
    return
コード例 #23
0
def test():
    x = lg.ndarray.convert_to_legate_ndarray([])
    y = np.array([])
    asserts.assert_equal(x, y)
    z = lg.array([])
    asserts.assert_equal(y, z)

    x = lg.ndarray.convert_to_legate_ndarray([[]])
    y = np.array([[]])
    asserts.assert_equal(x, y)
    z = lg.array([[]])
    asserts.assert_equal(y, z)

    x = lg.ndarray.convert_to_legate_ndarray([[[]]])
    y = np.array([[[]]])
    asserts.assert_equal(x, y)
    z = lg.array([[[]]])
    asserts.assert_equal(y, z)

    x = lg.ndarray.convert_to_legate_ndarray([[], []])
    y = np.array([[], []])
    asserts.assert_equal(x, y)
    z = lg.array([[], []])
    asserts.assert_equal(y, z)

    x = lg.ndarray.convert_to_legate_ndarray([1])
    y = np.array([1])
    asserts.assert_equal(x, y)
    z = lg.array([1])
    asserts.assert_equal(y, z)

    x = lg.ndarray.convert_to_legate_ndarray([[1]])
    y = np.array([[1]])
    asserts.assert_equal(x, y)
    z = lg.array([[1]])
    asserts.assert_equal(y, z)

    x = lg.ndarray.convert_to_legate_ndarray([[[1]]])
    y = np.array([[[1]]])
    asserts.assert_equal(x, y)
    z = lg.array([[[1]]])
    asserts.assert_equal(y, z)

    x = lg.ndarray.convert_to_legate_ndarray([[1], [1]])
    y = np.array([[1], [1]])
    asserts.assert_equal(x, y)
    z = lg.array([[1], [1]])
    asserts.assert_equal(y, z)

    x = lg.ndarray.convert_to_legate_ndarray([1, 2, 3, 4])
    y = np.array([1, 2, 3, 4])
    asserts.assert_equal(x, y)
    z = lg.array([1, 2, 3, 4])
    asserts.assert_equal(y, z)
コード例 #24
0
def test():
    x = [1.0, 2, 3]
    y = [4, 5, 6]
    z = x + y
    numpyResult = np.sum(z)
    # print(numpyResult)

    gx = lg.array(x)
    gy = lg.array(y)
    z = gx + gy
    legate_oldResult = lg.sum(z)
    # print(legate_oldResult)

    assert legate_oldResult == numpyResult
    return
コード例 #25
0
def test():
    x = lg.array([1, 2, 3, 4, 5])

    assert 4 in x
    assert 6 not in x

    return
コード例 #26
0
def test():
    anp = np.random.random_integers(100, size=(4, 5))
    a = lg.array(anp)

    assert np.array_equal(~a, ~anp)

    return
コード例 #27
0
def test():
    anp = np.random.randn(4, 5)
    a = lg.array(anp)

    assert np.array_equal(lg.negative(a), np.negative(anp))

    return
コード例 #28
0
ファイル: normal.py プロジェクト: prettywork2021/legate.numpy
def test():
    anp = np.random.randn(4, 5)
    a = lg.array(anp)

    assert np.array_equal(lg.logical_not(a), np.logical_not(anp))

    return
コード例 #29
0
def test():
    x = lg.array([1.0, 2.0, 3.0, 4.0])
    y = lg.exp(x)
    # print(y)
    # print(np.exp([1, 2, 3, 4]))
    assert np.allclose(y, np.exp([1, 2, 3, 4]))
    return
コード例 #30
0
def test():
    npa = np.array([-np.pi, 0, np.pi / 2, np.pi])
    a = lg.array(npa)
    lg.tanh(a, out=a)
    np.tanh(npa, out=npa)
    assert np.array_equal(a, npa)
    return