Skip to content

Check that vectors are not passed to matrix.block #40277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/sage/matrix/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,22 @@ def block_matrix(*args, **kwds):
[-----+-----]
[ 1 0| 3 5]
[ 0 1| 8 13]

Ensure errors are raised if vectors are passed in::

sage: matrix.block([
....: [matrix.zero(2), vector([0]*2)],
....: ])
Traceback (most recent call last):
...
ValueError: block_matrix only accept matrices, not vectors
sage: matrix.block([
....: [matrix.zero(2), vector([0]*2)],
....: [0, matrix.zero(2)],
....: ])
Traceback (most recent call last):
...
ValueError: block_matrix only accept matrices, not vectors
"""
args = list(args)
sparse = kwds.get('sparse', None)
Expand Down Expand Up @@ -2050,6 +2066,12 @@ def block_matrix(*args, **kwds):

# At this point sub_matrices is a list of lists

from sage.structure.element import Vector
for row in sub_matrices:
for M in row:
if isinstance(M, Vector):
raise ValueError("block_matrix only accept matrices, not vectors")

# determine the base ring and sparsity
if ring is None:
ring = ZZ
Expand Down
Loading