Skip to content

Commit

Permalink
Update test_elementwise_heaviside_op.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BrilliantYuKaimin committed Apr 14, 2022
1 parent 07d5607 commit 30cf8c6
Showing 1 changed file with 16 additions and 18 deletions.
Expand Up @@ -16,8 +16,6 @@
import numpy as np
from op_test import OpTest
import paddle
import paddle.fluid.core as core
import paddle.fluid as fluid


class TestElementwiseOp(OpTest):
Expand Down Expand Up @@ -88,18 +86,20 @@ def setUp(self):

def test_static(self):
for use_cuda in ([False, True]
if core.is_compiled_with_cuda() else [False]):
if paddle.device.is_compiled_with_cuda() else [False]):
place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace()

paddle.enable_static()
x = paddle.fluid.data(
name=f"x_{self.dtype}", shape=[13, 17], dtype=self.dtype)
y = paddle.fluid.data(
name=f"y_{self.dtype}", shape=[13, 17], dtype=self.dtype)
out = paddle.heaviside(x, y)
prog = paddle.static.Program()
with paddle.static.program_guard(prog):
x = paddle.static.data(
name=f"x_{self.dtype}", shape=[13, 17], dtype=self.dtype)
y = paddle.static.data(
name=f"y_{self.dtype}", shape=[13, 17], dtype=self.dtype)
out = paddle.heaviside(x, y)

exe = paddle.static.Executor(place=place)
res = exe.run(fluid.default_main_program(),
res = exe.run(prog,
feed={
f"x_{self.dtype}": self.x_np,
f"y_{self.dtype}": self.y_np
Expand All @@ -111,7 +111,7 @@ def test_static(self):

def test_dygraph(self):
for use_cuda in ([False, True]
if core.is_compiled_with_cuda() else [False]):
if paddle.device.is_compiled_with_cuda() else [False]):
place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace()
paddle.disable_static(place=place)
result = paddle.heaviside(
Expand Down Expand Up @@ -146,23 +146,21 @@ def setUp(self):

class TestHeavisideError(unittest.TestCase):
def test_input(self):
paddle.disable_static()

def test_input_x():
with paddle.fluid.dygraph.guard():
paddle.heaviside(1, paddle.randn([100]))
paddle.heaviside(1, paddle.randn([100]))

self.assertRaises(ValueError, test_input_x)

def test_input_y():
with paddle.fluid.dygraph.guard():
paddle.heaviside(paddle.randn([100]), 1)
paddle.heaviside(paddle.randn([100]), 1)

self.assertRaises(ValueError, test_input_y)

def test_input_xy():
with paddle.fluid.dygraph.guard():
paddle.heaviside(
paddle.randn([100], 'float32'),
paddle.randn([100], 'float64'))
paddle.heaviside(
paddle.randn([100], 'float32'), paddle.randn([100], 'float64'))

self.assertRaises(ValueError, test_input_xy)

Expand Down

1 comment on commit 30cf8c6

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on 30cf8c6 Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵️ CI failures summary

🔍 PR: #40934 Commit ID: 30cf8c6 contains failed CI.

🔹 Failed: PR-CI-APPROVAL

Unknown Failed
Unknown Failed

🔹 Failed: PR-CI-Static-Check

Unknown Failed
Unknown Failed

🔹 Failed: PR-CE-Framework

Unknown Failed
Unknown Failed

Please sign in to comment.