def testIsotypePartition(tensor): """Test that the components of tensor add up to tensor, that projecting them again the same way leaves them unchanged, and that projecting them differently leaves them zero""" #print("---") total = np.zeros_like(tensor, dtype="float64") for pp in partitions(tensor.ndim): p = IntegerPartition(pp).partition t=project(tensor, p) #print (p) #print(";") #print(t) #print(t-project(t,p)) #print(project(t,p)) assert np.allclose(t,project(t,p)) #print(tensor,total,t) total += t for qq in partitions(tensor.ndim): q=IntegerPartition(qq).partition if q!=p: #print(p,q) #print(project(t,q)) assert np.allclose(0,project(t,q)) #print(".") #print(tensor) #print(total) assert np.allclose(tensor,total) print("test ok")
def _get_all_partitions_tuples(n) -> List[IntTuple]: partition = IntegerPartition([1] * n) end_result = IntegerPartition([n]) result = [tuple(partition.partition)] while partition != end_result: partition = partition.next_lex() result.append(tuple(partition.partition)) return result
def get_all_partitions(self) -> List[Partition]: partition = IntegerPartition([1] * self.n) end_result = IntegerPartition([self.n]) result = [Partition(partition.partition)] while partition != end_result: partition = partition.next_lex() result.append(Partition(partition.partition)) return result
def test_integer_partition(): # no zeros in partition raises(ValueError, lambda: IntegerPartition(list(range(3)))) # check fails since 1 + 2 != 100 raises(ValueError, lambda: IntegerPartition(100, list(range(1, 3)))) a = IntegerPartition(8, [1, 3, 4]) b = a.next_lex() c = IntegerPartition([1, 3, 4]) d = IntegerPartition(8, {1: 3, 3: 1, 2: 1}) assert a == c assert a.integer == d.integer assert a.conjugate == [3, 2, 2, 1] assert (a == b) is False assert a <= b assert (a > b) is False assert a != b for i in range(1, 11): next = set() prev = set() a = IntegerPartition([i]) ans = set([IntegerPartition(p) for p in partitions(i)]) n = len(ans) for j in range(n): next.add(a) a = a.next_lex() IntegerPartition(i, a.partition) # check it by giving i for j in range(n): prev.add(a) a = a.prev_lex() IntegerPartition(i, a.partition) # check it by giving i assert next == ans assert prev == ans assert IntegerPartition([1, 2, 3]).as_ferrers() == '###\n##\n#' assert IntegerPartition([1, 1, 3]).as_ferrers('o') == 'ooo\no\no' assert str(IntegerPartition([1, 1, 3])) == '[3, 1, 1]' assert IntegerPartition([1, 1, 3]).partition == [3, 1, 1] raises(ValueError, lambda: random_integer_partition(-1)) assert random_integer_partition(1) == [1] assert random_integer_partition(10, seed=[1, 3, 2, 1, 5, 1] ) == [5, 2, 1, 1, 1]
def test_integer_partition(): # no zeros in partition raises(ValueError, lambda: IntegerPartition(list(range(3)))) # check fails since 1 + 2 != 100 raises(ValueError, lambda: IntegerPartition(100, list(range(1, 3)))) a = IntegerPartition(8, [1, 3, 4]) b = a.next_lex() c = IntegerPartition([1, 3, 4]) d = IntegerPartition(8, {1: 3, 3: 1, 2: 1}) assert a == c assert a.integer == d.integer assert a.conjugate == [3, 2, 2, 1] assert (a == b) is False assert a <= b assert (a > b) is False assert a != b for i in range(1, 11): next = set() prev = set() a = IntegerPartition([i]) ans = set([IntegerPartition(p) for p in partitions(i)]) n = len(ans) for j in range(n): next.add(a) a = a.next_lex() IntegerPartition(i, a.partition) # check it by giving i for j in range(n): prev.add(a) a = a.prev_lex() IntegerPartition(i, a.partition) # check it by giving i assert next == ans assert prev == ans assert IntegerPartition([1, 2, 3]).as_ferrers() == '###\n##\n#' assert IntegerPartition([1, 1, 3]).as_ferrers('o') == 'ooo\no\no' assert str(IntegerPartition([1, 1, 3])) == '[3, 1, 1]' assert IntegerPartition([1, 1, 3]).partition == [3, 1, 1] raises(ValueError, lambda: random_integer_partition(-1)) assert random_integer_partition(1) == [1] assert random_integer_partition(10, seed=[1, 3, 2, 1, 5, 1]) == [5, 2, 1, 1, 1]