Skip to content

Commit

Permalink
fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhui29 committed Oct 21, 2020
1 parent 80210a0 commit 7ed33b7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions python/paddle/fluid/tests/unittests/test_reduce_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,9 @@ def test_dygraph(self):
paddle.disable_static()
for place in self.places:
with fluid.dygraph.guard(place):
x = fluid.layers.assign(np.array([[1, 0], [1, 1]], dtype='int32'))
x = fluid.layers.assign(
np.array(
[[1, 0], [1, 1]], dtype='int32'))
x = fluid.layers.cast(x, 'bool')

out1 = paddle.all(x)
Expand Down Expand Up @@ -825,47 +827,49 @@ def setUp(self):
self.places = [fluid.CPUPlace()]
if core.is_compiled_with_cuda():
self.places.append(fluid.CUDAPlace(0))

def check_static_result(self, place):
paddle.disable_static()
with fluid.program_guard(fluid.Program(), fluid.Program()):
input = fluid.data(name="input", shape=[4, 4], dtype="float64")
result = paddle.inverse(x=input)
input_np = np.random.random([4, 4]).astype("float64")
result_np = np.linalg.inv(input_np)

exe = fluid.Executor(place)
fetches = exe.run(fluid.default_main_program(),
feed={"input": input_np},
fetch_list=[result])
self.assertTrue(np.allclose(fetches[0], np.linalg.inv(input_np)))

def test_static(self):
for place in self.places:
self.check_static_result(place=place)

def test_dygraph(self):
paddle.disable_static()
for place in self.places:
with fluid.dygraph.guard(place):
x = fluid.layers.assign(np.array([[1, 0], [1, 1]], dtype='int32'))
x = fluid.layers.assign(
np.array(
[[1, 0], [1, 1]], dtype='int32'))
x = fluid.layers.cast(x, 'bool')

out1 = paddle.any(x)
res1 = fluid.layers.assign(np.array([1], dtype='int32'))
res1 = fluid.layers.cast(res1, 'bool')
self.assertTrue(out1, res1)

out2 = paddle.any(x, axis=0)
res2 = fluid.layers.assign(np.array([1, 0], dtype='int32'))
res2 = fluid.layers.cast(res2, 'bool')
self.assertTrue(out2, res2)

out3 = paddle.any(x, axis=-1)
res3 = fluid.layers.assign(np.array([1, 0], dtype='int32'))
res3 = fluid.layers.cast(res3, 'bool')
self.assertTrue(out3, res3)

out4 = paddle.any(x, axis=1, keep_dim=True)
res4 = fluid.layers.assign(np.array([[1, 0]], dtype='int32'))
res4 = fluid.layers.cast(res4, 'bool')
Expand Down

0 comments on commit 7ed33b7

Please sign in to comment.