]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
mjo/matrix_algebra.py: support Vector "rows" in from_list()
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 8 Apr 2026 23:48:48 +0000 (19:48 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 8 Apr 2026 23:48:48 +0000 (19:48 -0400)
Something in Sage changed and now we're getting Vector "rows" in what
used to be a list-of-lists resulting from a block matrix. Tweak the
test to support anything with a __len__ method inside, rather than
just list or tuple.

mjo/matrix_algebra.py

index affafc3570cd1344af8fcf503beec4b01fb9c5a8..5df5c21119a188f1ea89130136ceaf79cf780630 100644 (file)
@@ -1,3 +1,5 @@
+from collections.abc import Sized
+
 from sage.misc.table import table
 from sage.categories.magmatic_algebras import MagmaticAlgebras
 from sage.misc.cachefunc import cached_method
@@ -459,7 +461,9 @@ class MatrixAlgebra(CombinatorialFreeModule):
         nrows = len(entries)
         ncols = 0
         if nrows > 0:
-            if isinstance(entries[0], (list, tuple)):
+            # Support list, tuple, vector, etc. The "Sized" type class
+            # is what provides the __len__ we use immediately after.
+            if isinstance(entries[0], Sized):
                 ncols = len(entries[0])
             else:
                 # We were given one long list of entries,