quantize#
- class diffsptk.UniformQuantization(abs_max=1, n_bit=8, quantizer='mid-rise')[source]#
See this page for details. The gradient is copied from the subsequent module.
- Parameters:
- abs_maxfloat > 0
The absolute maximum value of the input waveform.
- n_bitint >= 1
The number of quantization bits.
- quantizer[‘mid-rise’, ‘mid-tread’]
The quantizer type.
- forward(x)[source]#
Quantize the input waveform.
- Parameters:
- xTensor [shape=(…,)]
The input waveform.
- Returns:
- outTensor [shape=(…,)]
The quantized waveform.
Examples
>>> x = diffsptk.ramp(-4, 4) >>> quantize = diffsptk.UniformQuantization(4, 2) >>> y = quantize(x).int() >>> y tensor([0, 0, 1, 1, 2, 2, 3, 3, 3], dtype=torch.int32)
- diffsptk.functional.quantize(x, abs_max=1, n_bit=8, quantizer='mid-rise')[source]#
Quantize the input waveform.
- Parameters:
- xTensor [shape=(…,)]
The input waveform.
- abs_maxfloat > 0
The absolute maximum value of the input waveform.
- n_bitint >= 1
The number of quantization bits.
- quantizer[‘mid-rise’, ‘mid-tread’]
The quantizer type.
- Returns:
- outTensor [shape=(…,)]
The quantized waveform.
See also