Added examples to OneSumNode in SeymoursDecomposition.pyx#8
Added examples to OneSumNode in SeymoursDecomposition.pyx#8mkoeppe merged 7 commits intomkoeppe:cmrfrom
Conversation
|
|
||
| summands = DecompositionNode._children | ||
|
|
||
| def get_children_matrices(self): |
There was a problem hiding this comment.
-
In the line above, I define
summandsas an alias for the internal method_children. This method does not start with_, so this is the intended public method. So instead ofget_children_matricesit should beget_summands_matrices. -
Grammar: Don't pluralize both words; so it should be
get_summand_matrices. -
In most cases, the word
getis redundant in naming methods and is typically avoided in Python. That's why it's justsummands, notget_summands. So it should be justsummand_matrices.
|
|
||
| def get_children_matrices(self): | ||
| if self._children() is None: | ||
| raise ValueError('Node has no children') |
There was a problem hiding this comment.
If you look at the implementation of _children, you see that it always returns a tuple and never None.
So this case cannot arise.
Could you add documentation and an example to the _children method please?
|
|
||
| pass | ||
| def block_diagonal_repr(self): | ||
| r""" |
There was a problem hiding this comment.
This is a nice idea for a useful method. Some comments:
-
The name won't generalize to
TwoSumandThreeSumNode; they are still block matrices, but not block diagonal matrices. -
I would avoid the word
reprin such names because in Python this means a string representation.
|
I'll look into the bug |
|
I have reproduced the bug on my machine; for me it segfaults instead of just running into an OverflowError. |
|
The bug is fixed on my branch in 6bcdbeb. |
....: and added examples to ._children()
|
|
||
| sage: from sage.matrix.matrix_cmr_sparse import Matrix_cmr_chr_sparse | ||
| sage: M = Matrix_cmr_chr_sparse.one_sum([[1, 0], [-1, 1]], [[1, 1], [-1, 0]], [[1, 0], [0,1]] | ||
| ....: ); M |
There was a problem hiding this comment.
better to break the line between the 3 provided matrices
| (GraphicNode, GraphicNode, GraphicNode, GraphicNode) | ||
|
|
||
| sage: M2 = Matrix_cmr_chr_sparse(MatrixSpace(ZZ, 2, 2, sparse=True), [[1, 1], [- | ||
| ...: 1, 0]]); M2 |
There was a problem hiding this comment.
better to break the line before the matrix data
…block_matrix_form, summand_matrices (#8) * wip onesum * wip onesum2 * wip onesum test * onesum node example * fixed names of .summand_matrices() and .block_matrix_form, ....: and added examples to ._children() * style fixes --------- Co-authored-by: J S <[email protected]> Co-authored-by: J S <[email protected]>
…block_matrix_form, summand_matrices (#8) * wip onesum * wip onesum2 * wip onesum test * onesum node example * fixed names of .summand_matrices() and .block_matrix_form, ....: and added examples to ._children() * style fixes --------- Co-authored-by: J S <[email protected]> Co-authored-by: J S <[email protected]>
…block_matrix_form, summand_matrices (#8) * wip onesum * wip onesum2 * wip onesum test * onesum node example * fixed names of .summand_matrices() and .block_matrix_form, ....: and added examples to ._children() * style fixes --------- Co-authored-by: J S <[email protected]> Co-authored-by: J S <[email protected]>
…block_matrix_form, summand_matrices (#8) * wip onesum * wip onesum2 * wip onesum test * onesum node example * fixed names of .summand_matrices() and .block_matrix_form, ....: and added examples to ._children() * style fixes --------- Co-authored-by: J S <[email protected]> Co-authored-by: J S <[email protected]>
…block_matrix_form, summand_matrices (#8) * wip onesum * wip onesum2 * wip onesum test * onesum node example * fixed names of .summand_matrices() and .block_matrix_form, ....: and added examples to ._children() * style fixes --------- Co-authored-by: J S <[email protected]> Co-authored-by: J S <[email protected]>
…block_matrix_form, summand_matrices (#8) * wip onesum * wip onesum2 * wip onesum test * onesum node example * fixed names of .summand_matrices() and .block_matrix_form, ....: and added examples to ._children() * style fixes --------- Co-authored-by: J S <[email protected]> Co-authored-by: J S <[email protected]>
📚 Description
Added method for block matrix representation of a one-sum node. Issue found with one_sum method in matrix_cmr_sparse.pyx, found as follows:sage: from sage.matrix.matrix_cmr_sparse import Matrix_cmr_chr_sparse
sage: M3 = Matrix_cmr_chr_sparse.one_sum([[1, 0], [-1, 1]], [[1, 1], [-1, 0]], [[1, 0], [0,1]]
....:
....: ....: ); M3
[ 1 0| 0 0| 0 0]
[-1 1| 0 0| 0 0]
[-----+-----+-----]
[ 0 0| 1 1| 0 0]
[ 0 0|-1 0| 0 0]
[-----+-----+-----]
[ 0 0| 0 0| 1 0]
[ 0 0| 0 0| 0 1]
sage: result, certificate = M3.is_totally_unimodular(certificate=True); certificate
OneSumNode with 4 children
sage: certificate.block_diagonal_repr()
[ 1 0| 0 0| 0| 0]
[-1 1| 0 0| 0| 0]
[-----+-----+--+--]
[ 0 0| 1 1| 0| 0]
[ 0 0|-1 0| 0| 0]
[-----+-----+--+--]
[ 0 0| 0 0| 1| 0]
[-----+-----+--+--]
[ 0 0| 0 0| 0| 1]
sage: type(certificate)
<class 'sage.matrix.seymour_decomposition.OneSumNode'>
sage: certificate.block_diagonal_repr()
OverflowError Traceback (most recent call last)
Cell In [7], line 1
----> 1 certificate.block_diagonal_repr()
File ~/sage/worktree-cmr/src/sage/matrix/seymour_decomposition.pyx:252, in sage.matrix.seymour_decomposition.OneSumNode.block_diagonal_repr()
250 [ 0 0| 0 0| 0| 1]
251 """
--> 252 return Matrix_cmr_chr_sparse.one_sum(*self.get_children_matrices())
253
254
File ~/sage/worktree-cmr/src/sage/matrix/seymour_decomposition.pyx:199, in genexpr()
197 if self._children() is None:
198 raise ValueError('Node has no children')
--> 199 return tuple(ch.matrix() for ch in self._children())
200
201
File ~/sage/worktree-cmr/src/sage/matrix/seymour_decomposition.pyx:199, in genexpr()
197 if self._children() is None:
198 raise ValueError('Node has no children')
--> 199 return tuple(ch.matrix() for ch in self._children())
200
201
File ~/sage/worktree-cmr/src/sage/misc/cachefunc.pyx:2301, in sage.misc.cachefunc.CachedMethodCallerNoArgs.call()
2299 if self.cache is None:
2300 f = self.f
-> 2301 self.cache = f(self._instance)
2302 return self.cache
2303
File ~/sage/worktree-cmr/src/sage/matrix/seymour_decomposition.pyx:59, in sage.matrix.seymour_decomposition.DecompositionNode.matrix()
57 if mat == NULL:
58 return None
---> 59 ms = MatrixSpace(ZZ, mat.numRows, mat.numColumns, sparse=True)
60 result = Matrix_cmr_chr_sparse.new(Matrix_cmr_chr_sparse, ms)
61 result._mat = mat
File ~/sage/worktree-cmr/src/sage/misc/classcall_metaclass.pyx:320, in sage.misc.classcall_metaclass.ClasscallMetaclass.call()
318 """
319 if cls.classcall is not None:
--> 320 return cls.classcall(cls, *args, **kwds)
321 else:
322 # Fast version of type.call(cls, *args, **kwds)
File ~/sage/worktree-cmr/src/sage/matrix/matrix_space.py:587, in MatrixSpace.classcall(cls, base_ring, nrows, ncols, sparse, implementation, **kwds)
585 raise ArithmeticError("ncols must be nonnegative")
586 if nrows > sys.maxsize or ncols > sys.maxsize:
--> 587 raise OverflowError("number of rows and columns may be at most %s" % sys.maxsize)
589 matrix_cls = get_matrix_class(base_ring, nrows, ncols, sparse, implementation)
590 return super().classcall(cls, base_ring, nrows,
591 ncols, sparse, matrix_cls, **kwds)
OverflowError: number of rows and columns may be at most 9223372036854775807
📝 Checklist
⌛ Dependencies