forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scaling_op.py
More file actions
36 lines (29 loc) · 1018 Bytes
/
test_scaling_op.py
File metadata and controls
36 lines (29 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import unittest
from op_test_util import OpTestMeta
from gradient_checker import GradientChecker, create_op
import numpy as np
from paddle.v2.framework.op import Operator
class TestScalingOp(unittest.TestCase):
__metaclass__ = OpTestMeta
def setUp(self):
self.type = "scaling"
self.inputs = {
'X': np.random.random((32, 64)).astype("float32"),
'weight': np.random.random(32).astype("float32")
}
self.outputs = {
'Out': np.dot(np.diag(self.inputs['weight']), self.inputs['X'])
}
class ScalingGradOp(GradientChecker):
def test_scaling(self):
op = create_op("scaling")
inputs = {
'X': np.random.random((32, 64)).astype("float32"),
'weight': np.random.random(32).astype("float32")
}
self.check_grad(
op, inputs, set(['X', "weight"]), "Out", max_relative_error=0.5)
if __name__ == '__main__':
unittest.main()
if __name__ == '__main__':
unittest.main()