MCPcopy Create free account
hub / github.com/XiaoMi/mace / adjust_range

Function adjust_range

tools/python/quantize/quantize_util.py:102–122  ·  view source on GitHub ↗
(in_min, in_max, device, non_zero)

Source from the content-addressed store, hash-verified

100
101
102def adjust_range(in_min, in_max, device, non_zero):
103 if device in [DeviceType.HEXAGON.value, DeviceType.HTA.value]:
104 return adjust_range_for_hexagon(in_min, in_max)
105
106 out_max = max(0.0, in_max)
107 out_min = min(0.0, in_min)
108 if non_zero:
109 out_min = min(out_min, in_min - (out_max - in_min) / 254.0)
110 scale = (out_max - out_min) / 255.0
111 eps = 1e-6
112 if out_min < -eps and out_max > eps:
113 zero = -out_min / scale
114 zero_int = int(round(zero))
115 if abs(zero - zero_int) > eps and non_zero:
116 zero_int = int(math.ceil(zero))
117 elif out_min > -eps:
118 zero_int = 0
119 else:
120 zero_int = 255
121
122 return scale, zero_int, -zero_int*scale, (255-zero_int)*scale
123
124
125def adjust_range_for_hexagon(in_min, in_max):

Callers 2

quantizeFunction · 0.85

Calls 4

adjust_range_for_hexagonFunction · 0.85
maxFunction · 0.50
minFunction · 0.50
absFunction · 0.50

Tested by

no test coverage detected