Skip to content
Snippets Groups Projects

Add quantize function and enums

Merged Oscar Gustafsson requested to merge quantization into master
+ 5
2
@@ -13,6 +13,7 @@ class Quantization(Enum):
TRUNCATION = 2
MAGNITUDE_TRUNCATION = 3
JAMMING = 4
UNBIASED_ROUNDING = 5
class Overflow(Enum):
@@ -38,7 +39,7 @@ def quantize(
fractional_bits : int
integer_bits : int, default: 1
quantization : Quantization, default: Quantization.TRUNCATION
overflow : Overflow, default: Overflow.SATURATION
overflow : Overflow, default: Overflow.TWOS_COMPLEMENT
Returns
-------
@@ -73,8 +74,10 @@ def quantize(
v = math.floor(v)
else:
v = math.ceil(v)
else: # Quantization.JAMMING
elif quantization is Quantization.JAMMING:
v = math.floor(v) | 1
else: # Quantization.UNBIASED_ROUNDING
v = round(v)
# TODO: overflow handling
Loading