def multiset_partitions_baseline(multiplicities, components):
 canon = []
 for (ct, elem) in zip(multiplicities, components):
  canon.extend(([elem] * ct))
 cache = set()
 n = len(canon)
 for (nc, q) in _set_partitions(n):
  rv = [[] for i in range(nc)]
  for i in range(n):
   rv[q[i]].append(canon[i])
  canonical = tuple(sorted([tuple(p) for p in rv]))
  cache.add(canonical)
 return cache

def multiset_partitions_baseline ( multiplicities , components ) : canon = [ ] for ( ct , elem ) in zip ( multiplicities , components ) : canon . extend ( ( [ elem ] * ct ) ) cache = set ( ) n = len ( canon ) for ( nc , q ) in _set_partitions ( n ) : rv = [ [ ] for i in range ( nc ) ] for i in range ( n ) : rv [ q [ i ] ] . append ( canon [ i ] ) canonical = tuple ( sorted ( [ tuple ( p ) for p in rv ] ) ) cache . add ( canonical ) return cache
enumerates partitions of a multiset parameters multiplicities list of integer multiplicities of the components of the multiset .