def test_clip_number_by_value(self): """Test clip with float""" shape, min_value, max_value = (10, 10), 0.4, 0.6 with nn.variable_scope(self.get_scope()): variable0 = fixture.create_random_variable(shape, dtype='float32') tensor1 = nn.clip_by_value(variable0, max_value=max_value, min_value=min_value) session = nn.Session() session.initialize() val0, val1 = session.run(outputs=[variable0, tensor1], ) expected = np.clip(val0, a_max=max_value, a_min=min_value) np.testing.assert_almost_equal(val1, expected)
def test_clip_number_by_value(self): """Test clip with float""" shape, min_value, max_value = (10, 10), 0.4, 0.6 with nn.variable_scope(self.get_scope()): variable0 = fixture.create_random_variable(shape, dtype='float32') tensor1 = nn.ops.clip_by_value( variable0, max_value=max_value, min_value=min_value) session = nn.Session() session.initialize() val0, val1 = session.run( outputs=[variable0, tensor1], ) expected = np.clip(val0, a_max=max_value, a_min=min_value) np.testing.assert_almost_equal(val1, expected)
def test_clip_input_by_value(self): """Test clip with Input""" shape, min_value, max_value = (10, 10), 0.4, 0.6 with nn.variable_scope(self.get_scope()): variable0 = fixture.create_random_variable(shape, dtype='float32') min_input = nn.Input(shape=[], dtype='float32') max_input = nn.Input(shape=[], dtype='float32') tensor1 = nn.ops.clip_by_value( variable0, max_value=max_input, min_value=min_input) session = nn.Session() session.initialize() val0, val1 = session.run( outputs=[variable0, tensor1], givens={ min_input: np.array(min_value, dtype='float32'), max_input: np.array(max_value, dtype='float32'), }, ) expected = np.clip(val0, a_max=max_value, a_min=min_value) np.testing.assert_almost_equal(val1, expected)