ml_switcheroo.frameworks.numpy

Numpy Framework Adapter.

This module provides the implementation definitions for the NumPy API. It maps abstract operations for Math and Extras to numpy.* functions and defines type mappings for data-driven casting logic.

Capabilities: 1. Math: np.abs, np.mean. 2. IO: np.save, np.load for persistence. 3. Weight Migration: Handling dict-based .npz archives via get_weight_* hooks.

Classes

NumpyAdapter

Adapter for generic NumPy.

Module Contents

class ml_switcheroo.frameworks.numpy.NumpyAdapter[source]

Adapter for generic NumPy.

Provides support for: 1. Math Tiers: Basic array operations (abs, mean, sum). 2. Type Mapping: Abstract Dtypes to numpy.float32, etc. 3. IO: Save/Load operations.

display_name: str = 'NumPy'
inherits_from: str | None = None
ui_priority: int = 20
property search_modules: List[str]

Returns list of numpy submodules to scan.

Returns:

Modules.

Return type:

List[str]

property unsafe_submodules: Set[str]

Returns unsafe modules.

Returns:

Empty.

Return type:

Set[str]

property import_alias: Tuple[str, str]

Returns import tuple.

Returns:

(“numpy”, “np”).

Return type:

Tuple[str, str]

property import_namespaces: Dict[str, ml_switcheroo.frameworks.base.ImportConfig]

Remaps imports to ‘np’ alias.

Returns:

Mappings.

Return type:

Dict[str, ImportConfig]

property discovery_heuristics: Dict[str, List[str]]

Regex patterns for IO and Randomness.

Returns:

Patterns.

Return type:

Dict[str, List[str]]

property test_config: Dict[str, str]

Test templates for NumPy.

Returns:

Templates.

Return type:

Dict[str, str]

property harness_imports: List[str]

Imports for harness.

Returns:

Empty.

Return type:

List[str]

get_harness_init_code() str[source]

Init code.

Returns:

Empty.

Return type:

str

get_to_numpy_code() str[source]

Returns identity code for NumPy arrays.

Returns:

Code string.

Return type:

str

property supported_tiers: List[ml_switcheroo.enums.SemanticTier]

NumPy supports Arrays (Math) and Extras (IO). It does NOT support Neural layers structurally.

Returns:

Supported tiers.

Return type:

List[SemanticTier]

property declared_magic_args: List[str]

Returns list of magic args.

Returns:

Empty.

Return type:

List[str]

property structural_traits: ml_switcheroo.frameworks.base.StructuralTraits

Returns default structural traits (no class rewriting).

Returns:

Traits.

Return type:

StructuralTraits

property plugin_traits: ml_switcheroo.frameworks.base.PluginTraits

Plugin capabilities.

Returns:

Capabilities.

Return type:

PluginTraits

property definitions: Dict[str, ml_switcheroo.frameworks.base.StandardMap]

Static definitions for NumPy mappings. Loaded dynamically from frameworks/definitions/numpy.json.

Returns:

Definitions.

Return type:

Dict[str, StandardMap]

property rng_seed_methods: List[str]

Returns seed methods.

Returns:

Methods list.

Return type:

List[str]

collect_api(category: ml_switcheroo.frameworks.base.StandardCategory) List[ml_switcheroo.core.ghost.GhostRef][source]

NumPy doesn’t implement Layers/Losses structurally.

Parameters:

category – Category.

Returns:

Empty list.

Return type:

List[GhostRef]

get_device_syntax(device_type: str, device_index: str | None = None) str[source]

Returns CPU syntax ignoring device requests (NumPy is CPU-only).

Parameters:
  • device_type – Device.

  • device_index – Index.

Returns:

“‘cpu’”.

Return type:

str

get_device_check_syntax() str[source]

NumPy does not support GPUs.

Returns:

“False”.

Return type:

str

get_rng_split_syntax(rng_var: str, key_var: str) str[source]

No-op for NumPy.

Parameters:
  • rng_var – RNG variable.

  • key_var – Key variable.

Returns:

“pass”.

Return type:

str

get_serialization_imports() List[str][source]

Returns imports for IO.

Returns:

Imports.

Return type:

List[str]

get_serialization_syntax(op: str, file_arg: str, object_arg: str | None = None) str[source]

Returns np.save/load syntax.

Parameters:
  • op – ‘save’ or ‘load’.

  • file_arg – Path.

  • object_arg – Obj.

Returns:

Code.

Return type:

str

get_weight_conversion_imports() List[str][source]
get_weight_load_code(path_var: str) str[source]

Loads .npz files into a dictionary.

get_tensor_to_numpy_expr(tensor_var: str) str[source]
get_weight_save_code(state_var: str, path_var: str) str[source]

Saves dictionary to compressed .npz.

apply_wiring(snapshot: Dict[str, Any]) None[source]

No dynamic wiring needed for NumPy.

get_doc_url(api_name: str) str | None[source]

Generates NumPy documentation URL.

Parameters:

api_name – API Path.

Returns:

URL.

Return type:

Optional[str]

convert(data: Any) Any[source]

Attempts to convert input data to a NumPy array.

Parameters:

data (Any) – Input.

Returns:

Numpy array or original.

Return type:

Any

get_tiered_examples() Dict[str, str][source]

Returns NumPy idiomatic examples.

Returns:

Examples.

Return type:

Dict[str, str]