def test_leaf_components_combination_kernel():
    """
    Regression test for kernel compositions - output for printing should not be empty (issue #1066).
    """
    k = gpflow.kernels.SquaredExponential(
    ) + gpflow.kernels.SquaredExponential()
    assert leaf_components(
        k), "Combination kernel should have non-empty leaf components"
def test_merge_leaf_components_merges_keys_with_same_values(
        dag_module, expected_var_dicts):
    leaf_components_dict = leaf_components(dag_module)
    for path, variable in _merge_leaf_components(leaf_components_dict).items():
        assert path in expected_var_dicts
        for sub_path in path.split("\n"):
            assert sub_path in leaf_components_dict
            assert leaf_components_dict[sub_path] is variable
def test_leaf_components_registers_param_properties(module_class,
                                                    expected_var_dicts):
    module = module_class()
    for path, variable in leaf_components(module).items():
        var_name = path.split(".")[-2] + "." + path.split(".")[-1]
        assert isinstance(variable, tf.Variable)
        np.testing.assert_equal(variable.numpy(),
                                expected_var_dicts[var_name]["value"])
        assert variable.trainable == expected_var_dicts[var_name]["trainable"]
        assert variable.shape == expected_var_dicts[var_name]["shape"]
def test_leaf_components_registers_compose_kernel_variable_properties(
        module_callable, expected_param_dicts):
    module = module_callable()
    leaf_components_dict = leaf_components(module)
    assert len(leaf_components_dict) > 0
    for path, variable in leaf_components_dict.items():
        path_as_list = path.split(".")
        param_name = path_as_list[-3] + "." + path_as_list[
            -2] + "." + path_as_list[-1]
        assert isinstance(variable, gpflow.Parameter)
        np.testing.assert_equal(variable.numpy(),
                                expected_param_dicts[param_name]["value"])
        assert variable.trainable == expected_param_dicts[param_name][
            "trainable"]
        assert variable.shape == expected_param_dicts[param_name]["shape"]
def test_leaf_components_only_returns_parameters_and_variables(module):
    for path, variable in leaf_components(module).items():
        assert isinstance(variable, tf.Variable) or isinstance(
            variable, gpflow.Parameter)