ml_switcheroo.testing.fuzzer.generators¶

Primitive Generation Logic for the Fuzzer.

This module contains functions to generate random scalars, NumPy arrays, and dummy callables respecting specified constraints (min, max, dtype).

Feature Update: Added broadcasting logic generator.

Functions¶

generate_scalar_int(→ int)

Generates a random integer within constrained bounds.

generate_scalar_float(→ float)

Generates a random float within constrained bounds.

generate_array(→ numpy.ndarray)

Generates a random NumPy array bounded by constraints.

get_random_shape(→ Tuple[int, Ellipsis])

Selects a random rank (1-4) and random dimensions (2-5).

make_broadcastable_shape(→ Tuple[int, Ellipsis])

Derives a shape that is broadcast-compatible with the base_shape.

generate_fake_callable(→ Any)

Generates a dummy function (identity) for functional ops.

Module Contents¶

ml_switcheroo.testing.fuzzer.generators.generate_scalar_int(constraints: Dict[str, Any]) → int¶

Generates a random integer within constrained bounds.

Parameters:

constraints (Dict[str, Any]) – Dictionary containing optional ‘min’ and ‘max’.

Returns:

A random integer.

Return type:

int

ml_switcheroo.testing.fuzzer.generators.generate_scalar_float(constraints: Dict[str, Any]) → float¶

Generates a random float within constrained bounds.

Parameters:

constraints (Dict[str, Any]) – Dictionary containing optional ‘min’ and ‘max’.

Returns:

A random float.

Return type:

float

ml_switcheroo.testing.fuzzer.generators.generate_array(type_lbl: str, shape: Tuple[int, Ellipsis], constraints: Dict[str, Any]) → numpy.ndarray¶

Generates a random NumPy array bounded by constraints.

Parameters:
  • type_lbl (str) – General type category (‘float’, ‘int’, ‘bool’).

  • shape (Tuple[int, ...]) – The shape of the array.

  • constraints (Dict[str, Any]) – Constraints like ‘min’, ‘max’, ‘dtype’.

Returns:

The generated array.

Return type:

np.ndarray

ml_switcheroo.testing.fuzzer.generators.get_random_shape(seed_shape: Tuple[int, Ellipsis] | None = None) → Tuple[int, Ellipsis]¶

Selects a random rank (1-4) and random dimensions (2-5).

Parameters:

seed_shape (Optional[Tuple]) – Optional fixed shape to return.

Returns:

The random or seeded shape.

Return type:

Tuple[int, …]

ml_switcheroo.testing.fuzzer.generators.make_broadcastable_shape(base_shape: Tuple[int, Ellipsis], salt: int = 0) → Tuple[int, Ellipsis]¶

Derives a shape that is broadcast-compatible with the base_shape.

For each dimension, there is a probability it becomes 1 (broadcasting dimension). The ‘salt’ ensures arguments don’t all degenerate to 1s in the same way, creating varied valid broadcasting patterns (e.g. (A, 1, C) vs (1, B, C)).

Parameters:
  • base_shape – The target accumulated shape.

  • salt – Integer to vary the random choice (arg index).

Returns:

A new shape tuple.

ml_switcheroo.testing.fuzzer.generators.generate_fake_callable(constraints: Dict[str, Any] = None) → Any¶

Generates a dummy function (identity) for functional ops.