提交 32c15a29 编写于 作者: D dongzhihong

"random op test"

上级 d263ccef
......@@ -6,6 +6,7 @@
namespace paddle {
namespace operators {
template <typename T, typename DeviceContext>
bool Gaussian(DeviceContext& ctx,
framework::Tensor* output,
......
......@@ -36,6 +36,7 @@ USE_OP(mul);
USE_OP(sigmoid);
USE_OP(softmax);
USE_OP(rowwise_add);
USE_OP(random_op);
template <typename ClassType>
void ExposeOperator(ClassType& m) {
......
......@@ -16,13 +16,13 @@ class TestNet(unittest.TestCase):
net.complete_add_op(True)
expected = '''
Op(plain_net), inputs:(@EMPTY@, X, Y, w), outputs:(@TEMP@fc@0, Out, fc.out).
Op(add_two), inputs:(X, Y), outputs:(Out).
Op(plain_net), inputs:(@EMPTY@, X, w), outputs:(@TEMP@fc@0, fc.out).
Op(plain_net), inputs:(@EMPTY@, X, Y, w), outputs:(@TEMP@fc@0, Out, fc.out).
Op(add_two), inputs:(X, Y), outputs:(Out).
Op(plain_net), inputs:(@EMPTY@, X, w), outputs:(@TEMP@fc@0, fc.out).
Op(fc), inputs:(X, w, @EMPTY@), outputs:(fc.out, @TEMP@fc@0).
Op(mul), inputs:(X, w), outputs:(@TEMP@fc@0).
Op(sigmoid), inputs:(@TEMP@fc@0), outputs:(fc.out).
'''
Op(mul), inputs:(X, w), outputs:(@TEMP@fc@0).
Op(sigmoid), inputs:(@TEMP@fc@0), outputs:(fc.out).
'''
self.assertEqual(expected, "\n" + str(net))
......
import unittest
import paddle.v2.framework.create_op_creation_methods as creation
import paddle.v2.framework.core as core
from op_test_util import OpTestMeta
import numpy
class TestRandomOp(unittest.TestCase):
def test_random(self):
scope = core.Scope(None)
# Out = scope.create_var("Out")
op = creation.op_creations.random(
shape=[1000, 1000], mean=5.0, std=1.0, seed=1701, Out="Out")
for out in op.outputs():
if scope.get_var(out) is None:
scope.create_var(out).get_tensor()
tensor = scope.get_var("Y").get_tensor()
op.infer_shape(scope)
self.assertEqual([1000, 1000], tensor.shape())
ctx = core.DeviceContext.cpu_context()
op.run(scope, ctx)
self.assertAlmostEqual(numpy.std(tensor), 1.0)
self.assertAlmostEqual(numpy.mean(tensor), 5.0)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册