|
|
|
@ -18,6 +18,9 @@ import unittest
|
|
|
|
|
import numpy as np
|
|
|
|
|
from op_test import OpTest
|
|
|
|
|
|
|
|
|
|
import paddle.fluid.core as core
|
|
|
|
|
from paddle.fluid.op import Operator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFillConstantOp1(OpTest):
|
|
|
|
|
def setUp(self):
|
|
|
|
@ -47,5 +50,27 @@ class TestFillConstantOp2(OpTest):
|
|
|
|
|
self.check_output()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFillConstantOpWithSelectedRows(OpTest):
|
|
|
|
|
def check_with_place(self, place):
|
|
|
|
|
scope = core.Scope()
|
|
|
|
|
# create Out Variable
|
|
|
|
|
out = scope.var('Out').get_selected_rows()
|
|
|
|
|
|
|
|
|
|
# create and run fill_constant_op operator
|
|
|
|
|
fill_constant_op = Operator(
|
|
|
|
|
"fill_constant", shape=[123, 92], value=3.8, Out='Out')
|
|
|
|
|
fill_constant_op.run(scope, place)
|
|
|
|
|
|
|
|
|
|
# get result from Out
|
|
|
|
|
result_array = np.array(out)
|
|
|
|
|
self.assertEqual(result_array, np.full((123, 92), 3.8))
|
|
|
|
|
|
|
|
|
|
def test_fill_constant_with_selected_rows(self):
|
|
|
|
|
places = [core.CPUPlace()]
|
|
|
|
|
# currently only support CPU
|
|
|
|
|
for place in places:
|
|
|
|
|
self.check_with_place(place)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|
|
|
|
|