Coverage for src/arraybridge/dtype_scaling.py: 90%

10 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 11:15 +0000

1"""Declaration-owned dtype scaling and compatibility projections.""" 

2 

3from functools import partial 

4from types import MappingProxyType 

5from typing import Any 

6 

7from arraybridge.array_operations import _SCALING_RANGES as _SCALING_RANGES 

8from arraybridge.types import MemoryType 

9 

10 

11def _scale_generic(result: Any, target_dtype: Any, mem_type: MemoryType) -> Any: 

12 """Scale through the operation leaf carried by ``mem_type``.""" 

13 

14 return mem_type.scale_dtype(result, target_dtype) 

15 

16 

17def _scale_pyclesperanto(result: Any, target_dtype: Any) -> Any: 

18 """Compatibility adapter for the pyclesperanto scaling leaf.""" 

19 

20 return MemoryType.PYCLESPERANTO.scale_dtype(result, target_dtype) 

21 

22 

23SCALING_FUNCTIONS = MappingProxyType( 

24 {memory_type.value: partial(_scale_generic, mem_type=memory_type) for memory_type in MemoryType} 

25)