MCPcopy Create free account
hub / github.com/apple/coremltools / _update_tensor_range

Function _update_tensor_range

coremltools/optimize/_utils.py:860–881  ·  view source on GitHub ↗

Utility to update the "rmin" and "rmax" values in activation stats dictionary.

(
    tensor_name: str,
    tensor_value: Union[int, float],
    activation_stats_dict: Dict[str, Dict[str, float]],
)

Source from the content-addressed store, hash-verified

858
859
860def _update_tensor_range(
861 tensor_name: str,
862 tensor_value: Union[int, float],
863 activation_stats_dict: Dict[str, Dict[str, float]],
864) -> None:
865 """
866 Utility to update the "rmin" and "rmax" values in activation stats dictionary.
867 """
868 tensor_min = np.min(np.array(tensor_value).flatten())
869 tensor_max = np.max(np.array(tensor_value).flatten())
870 activation_stats_dict[tensor_name]["rmin"] = tensor_min
871 activation_stats_dict[tensor_name]["rmax"] = tensor_max
872 if tensor_name in activation_stats_dict:
873 activation_stats_dict[tensor_name]["rmin"] = min(
874 tensor_min, activation_stats_dict[tensor_name]["rmin"]
875 )
876 activation_stats_dict[tensor_name]["rmax"] = max(
877 tensor_max, activation_stats_dict[tensor_name]["rmax"]
878 )
879 else:
880 activation_stats_dict[tensor_name]["rmin"] = tensor_min
881 activation_stats_dict[tensor_name]["rmax"] = tensor_max
882
883
884def _combine_lists_with_common_elements(data: List[List[str]]) -> List[List[str]]:

Callers

nothing calls this directly

Calls 5

minFunction · 0.85
maxFunction · 0.85
minMethod · 0.80
maxMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected