|
|
|
@ -765,6 +765,15 @@ class TestLog(TestActivation):
|
|
|
|
|
return
|
|
|
|
|
self.check_grad(['X'], 'Out')
|
|
|
|
|
|
|
|
|
|
def test_error(self):
|
|
|
|
|
in1 = fluid.layers.data(
|
|
|
|
|
name="in1", shape=[11, 17], append_batch_size=False, dtype="int32")
|
|
|
|
|
in2 = fluid.layers.data(
|
|
|
|
|
name="in2", shape=[11, 17], append_batch_size=False, dtype="int64")
|
|
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, fluid.layers.log, in1)
|
|
|
|
|
self.assertRaises(TypeError, fluid.layers.log, in2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSquare(TestActivation):
|
|
|
|
|
def setUp(self):
|
|
|
|
@ -856,6 +865,29 @@ class TestPow_factor_tensor(TestActivation):
|
|
|
|
|
assert np.array_equal(res_3, res)
|
|
|
|
|
assert np.array_equal(res_6, np.power(input, 3))
|
|
|
|
|
|
|
|
|
|
def test_error(self):
|
|
|
|
|
in1 = fluid.layers.data(
|
|
|
|
|
name="in1", shape=[11, 17], append_batch_size=False, dtype="int32")
|
|
|
|
|
in2 = fluid.layers.data(
|
|
|
|
|
name="in2", shape=[11, 17], append_batch_size=False, dtype="int64")
|
|
|
|
|
in3 = fluid.layers.data(
|
|
|
|
|
name="in3",
|
|
|
|
|
shape=[11, 17],
|
|
|
|
|
append_batch_size=False,
|
|
|
|
|
dtype="float32")
|
|
|
|
|
in4 = fluid.layers.data(
|
|
|
|
|
name="in4",
|
|
|
|
|
shape=[11, 17],
|
|
|
|
|
append_batch_size=False,
|
|
|
|
|
dtype="float64")
|
|
|
|
|
|
|
|
|
|
factor_1 = fluid.layers.fill_constant([1], "float64", 3.0)
|
|
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, fluid.layers.pow, x=in1, factor=factor_1)
|
|
|
|
|
self.assertRaises(TypeError, fluid.layers.pow, x=in2, factor=factor_1)
|
|
|
|
|
self.assertRaises(TypeError, fluid.layers.pow, x=in3, factor=factor_1)
|
|
|
|
|
self.assertRaises(TypeError, fluid.layers.pow, x=in4, factor=factor_1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSTanh(TestActivation):
|
|
|
|
|
def setUp(self):
|
|
|
|
@ -1035,6 +1067,39 @@ class TestSwishOpError(unittest.TestCase):
|
|
|
|
|
fluid.layers.swish(x_fp16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#------------------ Test Error Activation----------------------
|
|
|
|
|
def create_test_error_class(op_type):
|
|
|
|
|
class TestOpErrors(unittest.TestCase):
|
|
|
|
|
def test_errors(self):
|
|
|
|
|
with program_guard(Program(), Program()):
|
|
|
|
|
op = getattr(fluid.layers, op_type)
|
|
|
|
|
# The input dtype of op_type must be float32, float64.
|
|
|
|
|
in1 = fluid.layers.data(
|
|
|
|
|
name='input2', shape=[12, 10], dtype="int32")
|
|
|
|
|
in2 = fluid.layers.data(
|
|
|
|
|
name='input3', shape=[12, 10], dtype="int64")
|
|
|
|
|
self.assertRaises(TypeError, op, in1)
|
|
|
|
|
self.assertRaises(TypeError, op, in2)
|
|
|
|
|
|
|
|
|
|
cls_name = "{0}_{1}".format(op_type, "test_errors")
|
|
|
|
|
TestOpErrors.__name__ = cls_name
|
|
|
|
|
globals()[cls_name] = TestOpErrors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create_test_error_class('acos')
|
|
|
|
|
create_test_error_class('asin')
|
|
|
|
|
create_test_error_class('atan')
|
|
|
|
|
create_test_error_class('ceil')
|
|
|
|
|
create_test_error_class('cos')
|
|
|
|
|
create_test_error_class('floor')
|
|
|
|
|
create_test_error_class('reciprocal')
|
|
|
|
|
create_test_error_class('round')
|
|
|
|
|
create_test_error_class('rsqrt')
|
|
|
|
|
create_test_error_class('sin')
|
|
|
|
|
create_test_error_class('sqrt')
|
|
|
|
|
create_test_error_class('tanh')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#------------------ Test Cudnn Activation----------------------
|
|
|
|
|
def create_test_act_cudnn_class(parent, atol=1e-3, grad_atol=1e-3):
|
|
|
|
|
@unittest.skipIf(not core.is_compiled_with_cuda(),
|
|
|
|
|