()
| 78 | |
| 79 | |
| 80 | def main(): |
| 81 | # Number of points along the x-axis used to draw the sine wave. |
| 82 | n_points = 1e6 |
| 83 | xs = np.linspace(-np.pi, np.pi, n_points).astype(np.float64) |
| 84 | w = xs |
| 85 | |
| 86 | w_16bit = dequantize(*quantize(w, 16)) |
| 87 | w_8bit = dequantize(*quantize(w, 8)) |
| 88 | |
| 89 | plot_delta = 1.2e-4 |
| 90 | plot_range = range(int(n_points * (0.5 - plot_delta)), |
| 91 | int(n_points * (0.5 + plot_delta))) |
| 92 | |
| 93 | plt.figure(figsize=(20, 6)) |
| 94 | plt.subplot(1, 3, 1) |
| 95 | plt.plot(xs[plot_range], w[plot_range], '-') |
| 96 | plt.title('Original (float32)', {'fontsize': 16}) |
| 97 | plt.xlabel('x') |
| 98 | |
| 99 | plt.subplot(1, 3, 2) |
| 100 | plt.plot(xs[plot_range], w_16bit[plot_range], '-') |
| 101 | plt.title('16-bit quantization', {'fontsize': 16}) |
| 102 | plt.xlabel('x') |
| 103 | |
| 104 | plt.subplot(1, 3, 3) |
| 105 | plt.plot(xs[plot_range], w_8bit[plot_range], '-') |
| 106 | plt.title('8-bit quantization', {'fontsize': 16}) |
| 107 | plt.xlabel('x') |
| 108 | |
| 109 | plt.show() |
| 110 | |
| 111 | |
| 112 | if __name__ == '__main__': |
no test coverage detected