Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
2.5 kB
7
Indexable
Never
class TestComplexAddV2(CommonTFLayerTest):
    def _prepare_input(self, inputs_info):
        rng = np.random.default_rng()
        assert 'param_real1:0' in inputs_info
        assert 'param_imag1:0' in inputs_info
        assert 'param_real2:0' in inputs_info
        assert 'param_imag2:0' in inputs_info
        
        # Assuming the shapes of real and imaginary parts are the same
        param_real_shape = inputs_info['param_real1:0']
        param_imag_shape = inputs_info['param_imag1:0']
        
        inputs_data = {}
        inputs_data['param_real1:0'] = 4 * rng.random(param_real_shape).astype(np.float32) - 2
        inputs_data['param_imag1:0'] = 4 * rng.random(param_imag_shape).astype(np.float32) - 2
        inputs_data['param_real2:0'] = 4 * rng.random(param_real_shape).astype(np.float32) - 2
        inputs_data['param_imag2:0'] = 4 * rng.random(param_imag_shape).astype(np.float32) - 2
        
        return inputs_data

    def create_complex_addv2_net(self, input_shape):
        tf.compat.v1.reset_default_graph()
        # Create the graph and model
        with tf.compat.v1.Session() as sess:
            param_real1 = tf.compat.v1.placeholder(np.float32, input_shape, 'param_real1')
            param_imag1 = tf.compat.v1.placeholder(np.float32, input_shape, 'param_imag1')
            param_real2 = tf.compat.v1.placeholder(np.float32, input_shape, 'param_real2')
            param_imag2 = tf.compat.v1.placeholder(np.float32, input_shape, 'param_imag2')
            
            complex1 = tf.raw_ops.Complex(real=param_real1, imag=param_imag1)
            complex2 = tf.raw_ops.Complex(real=param_real2, imag=param_imag2)

            addv2 = tf.raw_ops.AddV2(x=complex1, y=complex2)
            real = tf.raw_ops.Real(input=addv2)
            img = tf.raw_ops.Imag(input=addv2)
            tf.compat.v1.global_variables_initializer()
            tf_net = sess.graph_def

        return tf_net, None

    test_data_basic = [
        dict(input_shape=[2, 6]),  # Assuming same shape for real and imaginary parts
    ]
    @pytest.mark.parametrize("params", test_data_basic)
    @pytest.mark.precommit_tf_fe
    @pytest.mark.nightly
    def test_complex_addv2(self, params, ie_device, precision, ir_version, temp_dir,
                               use_legacy_frontend):
        self._test(
            *self.create_complex_addv2_net(**params),
            ie_device, precision, ir_version, temp_dir=temp_dir,
            use_legacy_frontend=use_legacy_frontend)
Leave a Comment