#!/usr/bin/env python3 from Crypto.PublicKey import RSA from multiprocessing import Pool, cpu_count import numpy as np import cvxpy as cvx import pymp def is_in_convex_hull(arg): """Check whether v lies in the convex hull of point set A, using cvxpy.""" A,v = arg lamb = cvx.Variable(A.shape[1]) prob = cvx.Problem(cvx.Minimize(0), [A*lamb == v, lamb >= 0]) prob.solve(solver = cvx.MOSEK) return prob.status == 'optimal' def convex_hull_LP_serial(A): """Compute the convex hull of a point set A with LPs. In contrast to convex_hull_LP() this function works in a single thread. Call: indices = convex_hull_LP_serial(A) Input: A: an (`m` x `n`)-matrix of non-negative integers Output: indices: list of indices, telling which columns of A form the convex hull """ return [i for i in range(A.shape[1]) if not is_in_convex_hull((np.delete(A,i,axis=1),A[:,i]))] def convex_hull_LP(A): """Compute the convex hull of a point set A with LPs. This function calls a new thread for each point, which creates a large overhead. Call: indices = convex_hull_LP(A) Input: A: an (`m` x `n`)-matrix of non-negative integers Output: indices: list of indices, telling which columns of A form the convex hull """ pool = Pool(processes = cpu_count()) res = pool.map(is_in_convex_hull, [(np.delete(A,i,axis=1),A[:,i]) for i in range(A.shape[1])]) pool.close() pool.join() return [i for i in range(A.shape[1]) if not res[i]] if __name__ == '__main__': k = RSA.generate(2048) print(k.decrypt(17)) print(pow(17,k.d,k.n)) def fn(m): return pow(m, k.d, k.n) pool = Pool(8) l = pool.map(fn, range(100)) result = pymp.shared.list() with pymp.Parallel() as env: for m in env.range(100): result.append(pow(m, k.d, k.n)) S = np.random.randint(20, size = (8,100))