def test_perf_ckks_enc_matmul(benchmark, matrix_shape): ctx = ckks_context() vector_shape = matrix_shape[-1] matrix, vec = generate_input(matrix_shape, vector_shape) ckks_vector = ts.enc_matmul_encoding(ctx, matrix.tolist()) benchmark.pedantic( helper_perf, args=("enc_matmul", ckks_vector, vec, matrix_shape[0]), rounds=rounds, iterations=iterations, )
def test_enc_matmul_plain(context, matrix_shape, vector_size, precision): def generate_input(matrix_shape, vector_size): # generated random values matrix = np.random.randn(*matrix_shape) vector = np.random.randn(vector_size) return matrix, vector matrix, vector = generate_input(matrix_shape, vector_size) expected = matrix @ vector context.generate_galois_keys() ckks_vector = ts.enc_matmul_encoding(context, matrix.tolist()) result = ckks_vector.enc_matmul_plain(vector.tolist(), matrix_shape[0]) assert _almost_equal(result.decrypt(), expected, precision), "Matrix multiplication is incorrect."