fill_constant op supports NINF (#28270)

revert-27871-prv-conv-grad-opt
Leo Chen 4 years ago committed by GitHub
parent 495a9ceb95
commit 7fcb32ddf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -50,6 +50,8 @@ class FillConstantKernel : public framework::OpKernel<T> {
// handle NaN/Inf first, which cannot be read from stream.
if (str_value == "inf") {
value = static_cast<T>(std::numeric_limits<double>::infinity());
} else if (str_value == "-inf") {
value = static_cast<T>(-std::numeric_limits<double>::infinity());
} else if (str_value == "nan") {
value = static_cast<T>(std::numeric_limits<double>::quiet_NaN());
} else {

@ -340,6 +340,12 @@ class TestFillConstantImperative(unittest.TestCase):
res = fluid.layers.fill_constant([1], 'float32', np.inf)
self.assertTrue(np.isinf(res.numpy().item(0)))
def test_ninf(self):
with fluid.dygraph.guard():
res = fluid.layers.fill_constant([1], 'float32', np.NINF)
self.assertTrue(np.isinf(res.numpy().item(0)))
self.assertEqual(np.NINF, res.numpy().item(0))
class TestFillConstantOpError(unittest.TestCase):
def test_errors(self):

Loading…
Cancel
Save