def I_uu(nballs, nboxes, labels): if nballs == 0: yield (tuple(),) * nboxes else: for occs in unlabeled_balls_in_unlabeled_boxes(nballs, [nballs]*nboxes): stop_points = (0,) + tuple(cummulative_sum(occs)) yield tuple(labels[stop_points[i]:stop_points[i+1]] for i in xrange(nboxes))
def I_uu(nballs, nboxes, labels): if nballs == 0: yield (tuple(), ) * nboxes else: for occs in unlabeled_balls_in_unlabeled_boxes(nballs, [nballs] * nboxes): stop_points = (0, ) + tuple(cummulative_sum(occs)) yield tuple(labels[stop_points[i]:stop_points[i + 1]] for i in xrange(nboxes))
def ordered_partitions_iter(sequence, length): """ This iterates over the P^k,m operator from Allen, et al. Mol. Phys. 89 (1996), 1213-1221 See the explanation of its funtion therein. This is needed for the arbitrary order B tensor formulae. :Examples: >>> [tuple(''.join(part) for part in parts) for parts in ordered_partitions_iter('ABCD', 2)] [('A', 'BCD'), ('AB', 'CD')] >>> [tuple(''.join(part) for part in parts) for parts in ordered_partitions_iter('ABCDEF', 3)] [('A', 'B', 'CDEF'), ('A', 'BC', 'DEF'), ('AB', 'CD', 'EF')] """ n = len(sequence) for partitions in unlabeled_balls_in_unlabeled_boxes(n, [n]*length): if 0 in partitions: continue spart = sorted(partitions) yield tuple(partitioned(sequence, spart))
def ordered_partitions_iter(sequence, length): """ This iterates over the P^k,m operator from Allen, et al. Mol. Phys. 89 (1996), 1213-1221 See the explanation of its funtion therein. This is needed for the arbitrary order B tensor formulae. :Examples: >>> [tuple(''.join(part) for part in parts) for parts in ordered_partitions_iter('ABCD', 2)] [('A', 'BCD'), ('AB', 'CD')] >>> [tuple(''.join(part) for part in parts) for parts in ordered_partitions_iter('ABCDEF', 3)] [('A', 'B', 'CDEF'), ('A', 'BC', 'DEF'), ('AB', 'CD', 'EF')] """ n = len(sequence) for partitions in unlabeled_balls_in_unlabeled_boxes(n, [n] * length): if 0 in partitions: continue spart = sorted(partitions) yield tuple(partitioned(sequence, spart))