Skip to content

Commit

Permalink
Kanvi/Add asserts in some python tests (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanvi-nervana authored and Shrestha Malik committed Dec 20, 2019
1 parent b267ba1 commit 367d3db
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion test/python/test_sigmoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ def test_sigmoid(self):
y: y_np,
z: z_np
})
np.allclose(self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
10 changes: 6 additions & 4 deletions test/python/test_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ def test_sign_1d(self, test_input, expected):
val = tf.placeholder(tf.float32, shape=(1,))
out = tf.sign(val)
sess_fn = lambda sess: sess.run((out,), feed_dict={val: (test_input,)})
np.allclose(self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
np.allclose(self.with_ngraph(sess_fn), expected)
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(self.with_ngraph(sess_fn), expected)

def test_sign_2d(self):
test_input = ((1.5, -2.5, -3.5), (-4.5, 5.5, 0))
expected = ((1, -1, -1), (-1, 1, 0))
val = tf.placeholder(tf.float32, shape=(2, 3))
out = tf.sign(val)
sess_fn = lambda sess: sess.run((out,), feed_dict={val: test_input})
np.allclose(self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
np.allclose(self.with_ngraph(sess_fn), expected)
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(self.with_ngraph(sess_fn), expected)
15 changes: 9 additions & 6 deletions test/python/test_softmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def test_softmax_2d(self):
expected = a_np
a = tf.nn.softmax(x)
sess_fn = lambda sess: sess.run((a), feed_dict={x: x_np})
np.allclose(self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
np.allclose(self.with_ngraph(sess_fn), expected)
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(self.with_ngraph(sess_fn), expected)

def test_softmax_3d(self):
x = tf.placeholder(tf.float32, shape=(2, 3, 2))
Expand All @@ -59,8 +60,9 @@ def test_softmax_3d(self):
expected = a_np
a = tf.nn.softmax(x)
sess_fn = lambda sess: sess.run((a), feed_dict={x: x_np})
np.allclose(self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
np.allclose(self.with_ngraph(sess_fn), expected)
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(self.with_ngraph(sess_fn), expected)

def test_softmax_4d(self):
x = tf.placeholder(tf.float32, shape=(2, 3, 2, 4))
Expand All @@ -75,5 +77,6 @@ def test_softmax_4d(self):
expected = a_np
a = tf.nn.softmax(x)
sess_fn = lambda sess: sess.run((a), feed_dict={x: x_np})
np.allclose(self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
np.allclose(self.with_ngraph(sess_fn), expected)
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(self.with_ngraph(sess_fn), expected)
3 changes: 2 additions & 1 deletion test/python/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def test_stack(self, shapes, axis):
a = tf.stack(placeholders, axis)
sess_fn = lambda sess: sess.run(
[a], feed_dict={p: v for p, v in zip(placeholders, values)})
np.allclose(self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))

0 comments on commit 367d3db

Please sign in to comment.