MCPcopy Create free account
hub / github.com/DragonisCV/RAM / dequantize

Function dequantize

ram/utils/flow_util.py:150–170  ·  view source on GitHub ↗

Dequantize an array. Args: arr (ndarray): Input array. min_val (scalar): Minimum value to be clipped. max_val (scalar): Maximum value to be clipped. levels (int): Quantization levels. dtype (np.type): The type of the dequantized array. Returns:

(arr, min_val, max_val, levels, dtype=np.float64)

Source from the content-addressed store, hash-verified

148
149
150def dequantize(arr, min_val, max_val, levels, dtype=np.float64):
151 """Dequantize an array.
152
153 Args:
154 arr (ndarray): Input array.
155 min_val (scalar): Minimum value to be clipped.
156 max_val (scalar): Maximum value to be clipped.
157 levels (int): Quantization levels.
158 dtype (np.type): The type of the dequantized array.
159
160 Returns:
161 tuple: Dequantized array.
162 """
163 if not (isinstance(levels, int) and levels > 1):
164 raise ValueError(f'levels must be a positive integer, but got {levels}')
165 if min_val >= max_val:
166 raise ValueError(f'min_val ({min_val}) must be smaller than max_val ({max_val})')
167
168 dequantized_arr = (arr + 0.5).astype(dtype) * (max_val - min_val) / levels + min_val
169
170 return dequantized_arr

Callers 1

dequantize_flowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected