ml_switcheroo.generated_tests.inputs ==================================== .. py:module:: ml_switcheroo.generated_tests.inputs .. autoapi-nested-parse:: Input Value Code Generation. This module handles the logic for generating Python *source code strings* that instantiate test data explicitly in the generated verification scripts. It parses argument definitions and emits code like `random.randint(1, 5)` or `np.random.randn(...)`. Features: - Infers generation logic from explicit types. - **Default Value Inference**: Uses default values to guess types when explicit hints are missing (e.g. `default=True` implies boolean generation). - **Constraint Inference**: Uses `min`/`max` to govern random ranges. Functions --------- .. autoapisummary:: ml_switcheroo.generated_tests.inputs.parse_arg_def ml_switcheroo.generated_tests.inputs.generate_input_value_code Module Contents --------------- .. py:function:: parse_arg_def(arg: Union[str, tuple, dict]) -> Dict[str, Any] Normalizes a heterogeneous argument definition into a standard dictionary. Extracts `default`, `min`, `max` to help downstream inference. Defaults un-typed arguments to 'Array' to ensure gradient checks in test generators correctly identify implicit tensors. :param arg: An argument definition. Can be a string ("x"), a tuple ("x", "int"), or a dictionary (ODL schema). :returns: Normalized dict with keys 'name', 'type', 'default', and constraints. .. py:function:: generate_input_value_code(name: str, arg_def: Union[str, Dict[str, Any]]) -> str Generates Python code string to instantiate inputs based on type/constraints. Prioritizes: 1. Explicit `options` list. 2. Explicit `type` hint. 3. Inference from `default` value if type is Any. 4. Inference from `min`/`max` constraints. 5. Heuristics based on argument name. :param name: The argument name (used for heuristics if type is missing). :param arg_def: The normalized argument definition dictionary or type string. :returns: Valid Python source code expression (e.g., "random.randint(0, 5)").