From 7c423e4b0db7657e526ad05b0dd0e20e6582acf0 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Thu, 14 Sep 2017 11:17:04 +0800 Subject: [PATCH] add unit test for rank_loss_op --- .../v2/framework/tests/test_rank_loss_op.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 python/paddle/v2/framework/tests/test_rank_loss_op.py diff --git a/python/paddle/v2/framework/tests/test_rank_loss_op.py b/python/paddle/v2/framework/tests/test_rank_loss_op.py new file mode 100644 index 00000000000..48354b7f7bd --- /dev/null +++ b/python/paddle/v2/framework/tests/test_rank_loss_op.py @@ -0,0 +1,27 @@ +import unittest +import numpy as np +from op_test import OpTest + + +class TestReshapeOp(OpTest): + def setUp(self): + self.op_type = "rank_loss" + num = 5 + # P = {0, 1.0} or {0, 0.5, 1.0} + P = np.random.randint(0, 2, size=(num, num)).astype("float32") + Oi = np.random.random((num, num)).astype("float32") + Oj = np.random.random((num, num)).astype("float32") + O = Oi - Oj + Out = np.log(1.0 + np.exp(O)) - P * O + self.inputs = {'P': P, 'Oi': Oi, 'Oj': Oj} + self.outputs = {'Out': Out} + + def test_check_output(self): + self.check_output() + + def test_check_grad(self): + self.check_grad(["Oj"], "Out") + + +if __name__ == '__main__': + unittest.main() -- GitLab