import numpy as np from bposd.css import css_code import sys def row_perm(l, m, k): S = np.zeros(shape=(l,l), dtype=np.uint8) for i in range(l): S[i, (i+k) % l] = 1 return np.kron(S, np.eye(m, dtype=np.uint8)) def col_perm(l, m, k): S = np.zeros(shape=(m,m),dtype=np.uint8) for i in range(m): S[i, (i+k) % m] = 1 return np.kron(np.eye(l, dtype=np.uint8), S) def perm(l, k): S = np.zeros(shape=(l,l), dtype=np.uint8) for i in range(l): S[i, (i+k)%l] = 1 return S def generalized_bicycle_qc(l, params): A = perm(l, params[0]) + perm(l, params[1]) + perm(l, params[2]) B = perm(l, params[3]) + perm(l, params[4]) + perm(l, params[5]) H_X = np.concatenate((A,B), axis=1) H_Z = np.concatenate((B.T, A.T), axis=1) return css_code(H_X, H_Z) def generalized_bicycle(l, m, params): A = row_perm(l, m, params[0]) + col_perm(l, m, params[1]) + col_perm(l, m, params[2]) B = col_perm(l, m, params[3]) + row_perm(l, m, params[4]) + row_perm(l, m, params[5]) H_X = np.concatenate((A,B), axis=1) H_Z = np.concatenate((B.T, A.T), axis=1) return css_code(H_X, H_Z) def lift(B, r, s, l): m = B.shape[0] n = B.shape[1] H = np.zeros((m*s*l, n*s*l), dtype=np.uint8) for i in range(m): for j in range(n): for k in range(s): for p in range(l): H[(i*s+k)*l+p][(j*s+k)*l+(p+B[i][j])%l] = 1 return np.kron(np.eye(r, dtype=np.uint8), H) def lifted_product(B, l): B = np.array(B, dtype=np.uint8) m = B.shape[0] n = B.shape[1] B_T = (np.ones((n,m), dtype=np.uint8)*l - B.T) % l H_x = np.concatenate( (lift(B_T, 1, m, l), lift(B, n, 1, l)), axis=1) H_z = np.concatenate( (lift(B_T, m, 1, l), lift(B, 1, n, l)), axis=1) return css_code(H_x, H_z) def hypergraph_product(H): H = np.array(H, dtype=np.uint8) I_nv = np.eye(H.shape[1], dtype=np.uint8) I_nc = np.eye(H.shape[0], dtype=np.uint8) H_x = np.concatenate( (np.kron(H, I_nv), np.kron(I_nc, H.T)), axis = 1) H_z = np.concatenate( (np.kron(I_nv, H), np.kron(H.T, I_nc)), axis = 1) return css_code(H_x, H_z) if __name__ == "__main__": m,n = map(int,sys.stdin.readline().split()) H=[] for i in range(m): H.append(list(map(int, sys.stdin.readline().split()))) code = hypergraph_product(H) code.test()