(arr: np.ndarray)
| 82 | |
| 83 | |
| 84 | def array_code_gen(arr: np.ndarray) -> str: |
| 85 | n = arr.shape[0] |
| 86 | if arr.shape[0] != arr.shape[1]: |
| 87 | msg = f"Hadamard matrix is not square: {arr.shape}" |
| 88 | raise ValueError(msg) |
| 89 | out = [ |
| 90 | f"out[{i}] = " |
| 91 | + " ".join([f"{'+' if arr[i, j] == 1 else '-'} x[{j}]" for j in range(n)]) |
| 92 | + ";" |
| 93 | for i in range(n) |
| 94 | ] |
| 95 | return template.replace("{N}", str(n)).replace("{code}", "\n ".join(out)) |
| 96 | |
| 97 | |
| 98 | def main() -> None: |