Dear all, I am frustrated with the following and would like to fix it:
Is "Set" supposed to be slow? Replacing "Set" with "set" in "SetPartition.__init__" is a huge improvement, we go down to about 5.5 ms per loop, but "Set" has bitten me performance (https://trac.sagemath.org/ticket/23877) and featurewise (https://trac.sagemath.org/ticket/23324) already so often, that I'd rather get rid of it altogether. Is there any point at all in having "Set"? Please help! Martin """ sage: n=7 sage: %timeit [P for P in set_partitions_all(n, False)] 10 loops, best of 3: 66.3 ms per loop sage: %timeit [P for P in set_partitions_all(n, True)] 100 loops, best of 3: 2.34 ms per loop sage: %lprun -f sage.combinat.set_partition.SetPartition.__init__ [P for P in set_partitions_all(n, False)] 535 def __init__(self, parent, s, check=True): ... 547 877 600 0.7 0.5 self._latex_options = {} 548 877 108495 123.7 91.2 sets = map(Set, s) 549 877 8625 9.8 7.2 blocks = sorted(sets, key=min) 550 877 1251 1.4 1.1 ClonableArray.__init__(self, parent, blocks, check=check) """ def set_partitions_all(n, fast): k = n a = [0]*n S = SetPartitions(n) def from_word(w): R = [] for i, B in enumerate(w, 1): if len(R) <= B: R.append([i]) else: R[B].append(i) if fast: return R else: return S.element_class(S, R, check=False) def gen(l, m): if l >= n: yield from_word(a) else: for i in range(m+1): a[l] = i for P in gen(l+1, m): yield P if m < k-1: a[l] = m+1 for P in gen(l+1, m+1): yield P return gen(1, 0) -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.