from scipy.spatial import Voronoi, voronoi_plot_2d import matplotlib.pyplot as plt import numpy as np def get_gray_code(n: int): return n ^ (n >> 1) def difference(sym0: int, sym1: int): return bit_count(sym0 ^ sym1) def bit_count(i: int): """ Hamming weight algorithm, just counts number of 1s """ assert 0 <= i < 0x100000000 i = i - ((i >> 1) & 0x55555555) i = (i & 0x33333333) + ((i >> 2) & 0x33333333) return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24 def compute_optimal(points, show_graph=False): available = set(range(len(points))) map = {} vor = Voronoi(points) if show_graph: voronoi_plot_2d(vor) plt.show() pass if __name__ == '__main__': a = np.array([[-1, -1], [-1, 1], [1, 1], [1, -1]]) # a = basic.load_alphabet('16qam', polar=False) compute_optimal(a, show_graph=True) pass