Skip to content

Commit 32d334d

Browse files
committed
fix child parent indices refactor
1 parent 176962d commit 32d334d

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

src/sage/matrix/seymour_decomposition.pyx

+50-10
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,47 @@ cdef class ThreeSumNode(SumNode):
623623
sage: C1.parent_rows_and_columns()
624624
((0, 1, a, 3), (b, c, d, e, +3+e))
625625
sage: C2.parent_rows_and_columns()
626-
((0, 2, 3, 5), (+b+0, d, 4, e, f))
626+
((0, 2, 3, 5), (+d+0, d, 4, e, f))
627+
628+
sage: from sage.matrix.matrix_cmr_sparse import Matrix_cmr_chr_sparse
629+
sage: R12_large = Matrix_cmr_chr_sparse(MatrixSpace(ZZ, 9, 12, sparse=True),
630+
....: [[1, -1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
631+
....: [0, 0, 0, 1, -1, 0, 0, 0, 1 , 1, 1, 1],
632+
....: [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
633+
....: [ 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0],
634+
....: [ 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, -1, -1],
635+
....: [ 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0],
636+
....: [ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, -1, -1],
637+
....: [ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0],
638+
....: [ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1]])
639+
sage: result, certificate = R12_large.is_totally_unimodular(certificate=True,
640+
....: three_sum_strategy="Wide_Wide",
641+
....: row_keys=range(9),
642+
....: column_keys='abcdefghijkl')
643+
sage: C = certificate._children()[0]; C
644+
ThreeSumNode (9×12) with 2 children
645+
sage: C1, C2 = C._children()
646+
sage: C1.matrix()
647+
[ 0 0 1 1 1 1 1]
648+
[ 1 1 0 0 0 -1 -1]
649+
[ 1 0 -1 0 -1 -1 -1]
650+
[ 0 1 1 0 1 0 0]
651+
[ 0 0 0 -1 -1 0 -1]
652+
sage: C2.matrix()
653+
[ 1 0 0 0 0 1 -1 0 -1]
654+
[ 0 0 1 -1 0 -1 1 0 1]
655+
[-1 -1 1 0 1 -1 1 0 1]
656+
[-1 -1 0 1 1 0 0 0 0]
657+
[-1 -1 0 0 0 0 1 1 1]
658+
[-1 -1 0 0 0 0 1 1 0]
659+
sage: C.row_keys()
660+
(0, i, 2, 3, 4, 5, 6, 7, 8)
661+
sage: C.column_keys()
662+
(a, b, c, d, e, f, g, h, 1, j, k, l)
663+
sage: C1.parent_rows_and_columns()
664+
((i, 2, 7, 8, 3), (g, h, j, k, l, d, -3+d))
665+
sage: C2.parent_rows_and_columns()
666+
((i, 0, 3, 4, 5, 6), (+i+k, k, a, b, c, d, e, f, 1))
627667
628668
sage: result, certificate = R12.is_totally_unimodular(certificate=True,
629669
....: three_sum_strategy="Mixed_Mixed",
@@ -642,9 +682,9 @@ cdef class ThreeSumNode(SumNode):
642682
[ 1 0 1 0]
643683
[ 0 -1 0 1]
644684
sage: C1.parent_rows_and_columns()
645-
((0, 1, 2, 3), (a, b, c, d, +2+3))
685+
((0, 1, 2, 3), (a, b, c, d, +3+2))
646686
sage: C2.parent_rows_and_columns()
647-
((+a+b, 2, 3, 4, 5), (a, d, e, f))
687+
((+a+d, 2, 3, 4, 5), (a, d, e, f))
648688
"""
649689
if self.nchildren() != 2:
650690
raise ValueError("ThreeSumNode has exactly two children")
@@ -686,7 +726,7 @@ cdef class ThreeSumNode(SumNode):
686726
else:
687727
epsilon2 = Integer(mat1.entryValues[index2])
688728

689-
child1_column_keys += (ElementKey((epsilon1, row_keys[child1_nrows-2], epsilon2, row_keys[child1_nrows-1]), composition=True),)
729+
child1_column_keys += (ElementKey((epsilon1, child1_row_keys[child1_nrows-2], epsilon2, child1_row_keys[child1_nrows-1]), composition=True),)
690730
else: # Wide_Wide
691731
child1_row_keys = tuple(self._CMRelement_to_key(parent_rows1[i])
692732
for i in range(child1_nrows))
@@ -699,8 +739,8 @@ cdef class ThreeSumNode(SumNode):
699739
else:
700740
epsilon1 = Integer(mat1.entryValues[index1])
701741

702-
child1_column_keys += (ElementKey((1, column_keys[child1_ncols-1], epsilon1,
703-
row_keys[child1_nrows-1]), composition=True),)
742+
child1_column_keys += (ElementKey((1, child1_column_keys[child1_ncols-2], epsilon1,
743+
child1_row_keys[child1_nrows-1]), composition=True),)
704744

705745
child1 = create_DecompositionNode(child1_dec, root=self._root or self,
706746
row_keys=child1_row_keys,
@@ -712,6 +752,8 @@ cdef class ThreeSumNode(SumNode):
712752
if self.is_concentrated_rank(): # Mixed_Mixed
713753
child2_row_keys = tuple(self._CMRelement_to_key(parent_rows2[i])
714754
for i in range(1, child2_nrows))
755+
child2_column_keys = tuple(self._CMRelement_to_key(parent_columns2[i])
756+
for i in range(child2_ncols))
715757

716758
CMR_CALL(CMRchrmatFindEntry(mat2, 0, 0, &index1))
717759
if index1 == SIZE_MAX:
@@ -725,9 +767,7 @@ cdef class ThreeSumNode(SumNode):
725767
else:
726768
epsilon2 = Integer(mat1.entryValues[index2])
727769

728-
child2_row_keys = (ElementKey((epsilon1, column_keys[0], epsilon2, column_keys[1]), composition=True), ) + child2_row_keys
729-
child2_column_keys = tuple(self._CMRelement_to_key(parent_columns2[i])
730-
for i in range(child2_ncols))
770+
child2_row_keys = (ElementKey((epsilon1, child2_column_keys[0], epsilon2, child2_column_keys[1]), composition=True), ) + child2_row_keys
731771
else: # Wide_Wide
732772
child2_row_keys = tuple(self._CMRelement_to_key(parent_rows2[i])
733773
for i in range(child2_nrows))
@@ -740,7 +780,7 @@ cdef class ThreeSumNode(SumNode):
740780

741781
child2_column_keys = tuple(self._CMRelement_to_key(parent_columns2[i])
742782
for i in range(1, child2_ncols))
743-
child2_column_keys = (ElementKey((1, column_keys[1], epsilon1, row_keys[0]), composition=True),) + child2_column_keys
783+
child2_column_keys = (ElementKey((1, child2_column_keys[0], epsilon1, child2_row_keys[0]), composition=True),) + child2_column_keys
744784

745785
child2 = create_DecompositionNode(child2_dec, root=self._root or self,
746786
row_keys=child2_row_keys,

0 commit comments

Comments
 (0)