Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Dgl ops 2 #16416

Merged
merged 12 commits into from
Oct 23, 2019
76 changes: 76 additions & 0 deletions tests/nightly/test_large_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,9 @@ def test_div():
b = 3*nd.ones(shape=(LARGE_X, SMALL_Y))
c = b
ChaiBapchya marked this conversation as resolved.
Show resolved Hide resolved
c = c.__div__(a)
mx_divide = nd.divide(b, a)
assert c[0][-1] == 3/2
assert mx_divide[0][-1] == c[0][-1]
assert c.shape == a.shape


Expand Down Expand Up @@ -1212,6 +1214,80 @@ def test_full():
assert a[-1][-1] == 3


def test_hyperbolic():
def test_arccosh(a):
ChaiBapchya marked this conversation as resolved.
Show resolved Hide resolved
mx_res = mx.nd.arccosh(a)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.arccosh(a[-1][-1].asnumpy()))

def test_arcsinh(a):
mx_res = mx.nd.arcsinh(a)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.arcsinh(a[-1][-1].asnumpy()))

def test_arctanh(a):
a[-1][-1] = 0 # arctanh of 1 is inf, assert_almost_equal gives "divide by 0" for comparing 2 inf values
mx_res = mx.nd.arctanh(a)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.arctanh(a[-1][-1].asnumpy()))

ChaiBapchya marked this conversation as resolved.
Show resolved Hide resolved
def test_cosh(a):
mx_res = mx.nd.cosh(a)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.cosh(a[-1][-1].asnumpy()))

def test_sinh(a):
mx_res = mx.nd.sinh(a)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.sinh(a[-1][-1].asnumpy()))

def test_tanh(a):
mx_res = mx.nd.tanh(a)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.tanh(a[-1][-1].asnumpy()))

a = mx.nd.ones((LARGE_X, SMALL_Y))
test_arccosh(a)
test_arcsinh(a)
test_arctanh(a)
test_cosh(a)
test_sinh(a)
test_tanh(a)


def test_sign():
a = mx.nd.random.normal(-1,1, shape=(LARGE_X, SMALL_Y))
mx_res = mx.nd.sign(a)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.sign(a[-1][-1].asnumpy()))


def test_logical():
def test_logical_and(a, b):
mx_res = mx.nd.logical_and(a, b)
ChaiBapchya marked this conversation as resolved.
Show resolved Hide resolved
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.logical_and(a[-1][-1].asnumpy(), b[-1][-1].asnumpy()))

def test_logical_or(a, b):
mx_res = mx.nd.logical_and(a, b)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.logical_and(a[-1][-1].asnumpy(), b[-1][-1].asnumpy()))

def test_logical_not(a, b):
mx_res = mx.nd.logical_and(a, b)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.logical_and(a[-1][-1].asnumpy(), b[-1][-1].asnumpy()))

def test_logical_xor(a, b):
mx_res = mx.nd.logical_and(a, b)
assert_almost_equal(mx_res[-1][-1].asnumpy(), np.logical_and(a[-1][-1].asnumpy(), b[-1][-1].asnumpy()))
ChaiBapchya marked this conversation as resolved.
Show resolved Hide resolved

a = mx.nd.ones((LARGE_X, SMALL_Y))
b = mx.nd.zeros((LARGE_X, SMALL_Y))
test_logical_and(a, b)
test_logical_or(a, b)
test_logical_not(a, b)
test_logical_xor(a, b)


def test_batch_dot():
a = mx.nd.ones((LARGE_X, 5, 10))
b = 2*mx.nd.ones((LARGE_X, 10, 6))
res = mx.nd.batch_dot(a, b)
assert res[0][0][0] == 20
assert res.shape == (LARGE_X, 5, 6)


if __name__ == '__main__':
import nose
nose.runmodule()