예제 #1
0
파일: ops_test.py 프로젝트: mot0/luchador
    def test_clip_variable_by_value(self):
        """Test clip with Variable"""
        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_variable = fixture.create_constant_variable(
                shape=[], dtype='float32', value=min_value, name='min_var')
            max_variable = fixture.create_constant_variable(
                shape=[], dtype='float32', value=max_value, name='max_var')
            tensor1 = nn.ops.clip_by_value(
                variable0, max_value=max_variable, min_value=min_variable)

        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)
예제 #2
0
    def test_mul_variable(self):
        """Tensor * Variable is correct elementwise"""
        shape = (3, 5)
        with nn.variable_scope(self.get_scope()):
            tensor1 = fixture.create_ones_tensor(shape, dtype='int32')
            variable = fixture.create_constant_variable(shape, dtype='int32')
            tensor2 = tensor1 * variable
            tensor3 = variable * tensor1

        session = nn.Session()
        session.initialize()

        val1, val2, val3, val0 = session.run(
            outputs=[tensor1, tensor2, tensor3, variable], )
        np.testing.assert_equal(val1 * val0, val2)
        np.testing.assert_equal(val0 * val1, val3)
예제 #3
0
    def test_mul_variable(self):
        """Tensor * Variable is correct elementwise"""
        shape = (3, 5)
        with nn.variable_scope(self.get_scope()):
            tensor1 = fixture.create_ones_tensor(shape, dtype='int32')
            variable = fixture.create_constant_variable(shape, dtype='int32')
            tensor2 = tensor1 * variable
            tensor3 = variable * tensor1

        session = nn.Session()
        session.initialize()

        val1, val2, val3, val0 = session.run(
            outputs=[tensor1, tensor2, tensor3, variable],
        )
        np.testing.assert_equal(val1 * val0, val2)
        np.testing.assert_equal(val0 * val1, val3)