def conflictors(H): s = conflictor_set(H) ds = {} num = reduce(np.bitwise_or, s) for i in xrange(gmp.bit_length(num)): if num & 1 << i: ds[1 << i] = [x for x in s if x & (1 << i)] return ds
def conflictors(H): s = conflictor_set(H) ds = {} num = reduce(operator.or_,s) for i in xrange(gmp.bit_length(num)): if num & 1<<i: ds[1<<i] = [x for x in s if x&(1<<i)] return ds
def lconflictors(H, sloops=None): if not sloops: sloops = prune_loops(allsloops(len(H)),H) s = conflictor_set(H) ds = {} num = reduce(operator.or_,s) for i in xrange(gmp.bit_length(num)): if num & 1<<i: cset = [x for x in s if x&(1<<i)] for sloop in sloops: if sloop & 1<<i: ds.setdefault(sloop,[]).extend(cset) return ds
def num2CG(num, n): """num2CG - converts a number whose binary representaion encodes edge presence/absence into a compressed graph representaion """ n2 = n * n G = {str(i + 1): {} for i in range(n)} if num == 0: return G bl = gmp.bit_length(num) idx = [n2 - i - 1 for i in xrange(bl) if num & (1 << i)] idx = np.unravel_index(idx, (n, n)) x = idx[0] + 1 y = idx[1] + 1 for i in range(len(x)): G['%i' % x[i]]['%i' % y[i]] = set([(0, 1)]) return G
def num2CG(num,n): """num2CG - converts a number whose binary representaion encodes edge presence/absence into a compressed graph representaion """ n2 = n*n G = {str(i+1):{} for i in range(n)} if num == 0: return G bl = gmp.bit_length(num) idx = [n2-i-1 for i in xrange(bl) if num & (1<<i)] idx = np.unravel_index(idx,(n,n)) x = idx[0]+1 y = idx[1]+1 for i in range(len(x)): G['%i' % x[i]]['%i' % y[i]] = set([(0,1)]) return G
def to_mpi(n): """Converts `n` to an MPI""" return two_octet(bit_length(n)) + bytearray(long_to_bytes(n))
def issingleloop(num): bl = gmp.bit_length(num) idx = [1 for i in xrange(bl) if num & (1<<i)] return len(idx) == 1