Ejemplo n.º 1
0
def test_merge_func_code(logging_mixin: Any, simple_test_functions: Any,
                         function_list_names: List[int],
                         expected_result: List[str],
                         expected_argument_positions: List[List[int]]) -> None:
    """ Test merging function codes for a list of functions. """
    funcs = simple_test_functions
    function_list = [funcs[f_label - 1] for f_label in function_list_names]
    result, argument_positions = fit_base.merge_func_codes(function_list)
    assert result == expected_result
    assert argument_positions == expected_argument_positions
Ejemplo n.º 2
0
    def __init__(self, *functions: Callable[..., float], prefixes: Optional[Sequence[str]] = None,
                 skip_prefixes: Optional[Sequence[str]] = None) -> None:
        # Store the functions
        self.functions = list(functions)

        # Determine the arguments for the functions.
        merged_args, argument_positions = fit_base.merge_func_codes(
            self.functions, prefixes = prefixes, skip_prefixes = skip_prefixes
        )
        logger.debug(f"merged_args: {merged_args}")
        self.func_code = fit_base.FuncCode(merged_args)
        self.argument_positions = argument_positions
Ejemplo n.º 3
0
    def __init__(self, *cost_functions: Union[T_CostFunction,
                                              "SimultaneousFit"]):
        # Validation
        # Ensure that we unravel any SimultaneousFit objects to their base cost functions.
        funcs = list(unravel_simultaneous_fits(list(cost_functions)))

        self.cost_functions = funcs
        logger.debug("Simultaneous Fit")
        merged_args, argument_positions = fit_base.merge_func_codes(
            self.cost_functions)
        # We don't drop any of the arguments here because the cost functions already did it.
        self.func_code = fit_base.FuncCode(merged_args)
        self.argument_positions = argument_positions
Ejemplo n.º 4
0
def test_merge_func_code_against_probfit(
        logging_mixin: Any, simple_test_functions: Any,
        function_list_names: List[int]) -> None:
    """ Test merging function codes against probfit. """
    # Setup
    funcs = simple_test_functions
    function_list = tuple(
        [funcs[f_label - 1] for f_label in function_list_names])
    probfit = pytest.importorskip("probfit")

    # Run the test and check
    result, argument_positions = fit_base.merge_func_codes(function_list)
    probfit_result, probfit_argument_positions = probfit.merge_func_code(
        *function_list)
    assert result == list(probfit_result.co_varnames)
    np.testing.assert_allclose(argument_positions, probfit_argument_positions)