import sys, os
import numpy as np
np.random.seed(42)
n = int(sys.argv[1]) if len(sys.argv) > 1 else 48
batchSize = int(sys.argv[2]) if len(sys.argv) > 2 else 2
a_real = np.random.randn(batchSize, n, n).astype(np.float32)
a_imag = np.random.randn(batchSize, n, n).astype(np.float32)
a = a_real + 1j * a_imag
for b in range(batchSize):
for i in range(n):
row_sum = np.sum(np.abs(a[b, i, :])) - np.abs(a[b, i, i])
a[b, i, i] = (row_sum + np.random.rand() * 10) * (1 + 1j)
inv_a = np.zeros((batchSize, n, n), dtype=np.complex64)
for b in range(batchSize):
inv_a[b] = np.linalg.inv(a[b]).astype(np.complex64)
os.makedirs(os.path.dirname("./test/cgetri_batched/data/input/A_gm.bin"), exist_ok=True)
os.makedirs(os.path.dirname("./test/cgetri_batched/data/golden/Ainv_gm.bin"), exist_ok=True)
with open("./test/cgetri_batched/data/input/A_gm.bin", "wb") as f:
f.write(a.tobytes())
with open("./test/cgetri_batched/data/golden/Ainv_gm.bin", "wb") as f:
f.write(inv_a.tobytes())
print(f"Generated batch {batchSize} of {n}x{n} complex matrices and their inverses")