@@ -1607,7 +1607,16 @@ cdef class Matrix(Matrix1):
16071607 sage: A = matrix(R, 2,2, [x, y, x^2, y^2])
16081608 sage: A.permanent()
16091609 x^2*y + x*y^2
1610+
1611+ TESTS::
1612+
1613+ sage: A = matrix(ZZ, 0, 0, [])
1614+ sage: A.permanent()
1615+ 1
16101616 """
1617+ if not self.nrows():
1618+ return self.base_ring().one()
1619+
16111620 if algorithm == "Ryser":
16121621 return self._permanent_ryser()
16131622
@@ -2899,7 +2908,7 @@ cdef class Matrix(Matrix1):
28992908 """
29002909 M = self.parent().change_ring(phi.codomain())
29012910 if self.is_sparse():
2902- values = {(i, j) : phi(z) for (i, j) , z in self.dict()}
2911+ values = {ij : phi(z) for ij , z in self.dict()}
29032912 else:
29042913 values = [phi(z) for z in self.list()]
29052914 image = M(values)
@@ -3009,7 +3018,7 @@ cdef class Matrix(Matrix1):
30093018 return self.dense_matrix()
30103019
30113020 if self.is_sparse():
3012- values = {(i, j) : phi(v) for (i, j) , v in self.dict().iteritems()}
3021+ values = {ij : phi(v) for ij , v in self.dict().iteritems()}
30133022 if R is None:
30143023 R = sage.structure.sequence.Sequence(values.values()).universe()
30153024 else:
@@ -12227,7 +12236,7 @@ cdef class Matrix(Matrix1):
1222712236 evals = eigenvalues
1222812237 else:
1222912238 evals = A.charpoly().roots()
12230- if sum(mult for ( _, mult) in evals) < n:
12239+ if sum(mult for _, mult in evals) < n:
1223112240 raise RuntimeError("Some eigenvalue does not exist in %s." % (A.base_ring()))
1223212241
1223312242 # Compute the block information. Here, ``blocks`` is a list of pairs,
@@ -12254,7 +12263,7 @@ cdef class Matrix(Matrix1):
1225412263 # are ordered firstly by the eigenvalues, in the same order as obeyed
1225512264 # by ``.roots()``, and secondly by size from greatest to smallest.
1225612265 J = block_diagonal_matrix([jordan_block(eval, size, sparse=sparse)
12257- for ( eval, size) in blocks],
12266+ for eval, size in blocks],
1225812267 subdivide=subdivide)
1225912268
1226012269 if transformation:
@@ -12513,7 +12522,7 @@ cdef class Matrix(Matrix1):
1251312522
1251412523 # check if the sum of algebraic multiplicities equals the number of rows
1251512524 evals = A.charpoly().roots()
12516- if sum(mult for ( _, mult) in evals) < self._nrows:
12525+ if sum(mult for _, mult in evals) < self._nrows:
1251712526 raise ValueError('not diagonalizable over {}'.format(A.base_ring()))
1251812527
1251912528 # compute diagonalization from the eigenspaces
@@ -12706,7 +12715,7 @@ cdef class Matrix(Matrix1):
1270612715
1270712716 # check if the sum of algebraic multiplicities equals to the number of rows
1270812717 evals = A.charpoly().roots()
12709- if sum(mult for ( _, mult) in evals) < self._nrows:
12718+ if sum(mult for _, mult in evals) < self._nrows:
1271012719 return False
1271112720
1271212721 # Obtaining a generic minimal polynomial requires much more
@@ -17082,9 +17091,9 @@ cdef class Matrix(Matrix1):
1708217091 return R.ideal(prod(elemdiv[:rank_minors]))
1708317092 except (TypeError, NotImplementedError, ArithmeticError):
1708417093 pass
17085- for ( nr, r) in enumerate(self.rows()):
17094+ for nr, r in enumerate(self.rows()):
1708617095 nz = [e for e in enumerate(r) if e[1]]
17087- if len(nz) == 0 :
17096+ if not nz :
1708817097 N = self.delete_rows([nr])
1708917098 return N.fitting_ideal(i)
1709017099 elif len(nz) == 1:
@@ -17093,7 +17102,7 @@ cdef class Matrix(Matrix1):
1709317102 N = N.delete_columns([nz[0][0]])
1709417103 F2 = N.fitting_ideal(i)
1709517104 return F1 + nz[0][1]*F2
17096- for ( nc, c) in enumerate(self.columns()):
17105+ for nc, c in enumerate(self.columns()):
1709717106 nz = [e for e in enumerate(c) if e[1]]
1709817107 if len(nz) == 0:
1709917108 N = self.delete_columns([nc])
@@ -18679,7 +18688,7 @@ cdef class Matrix(Matrix1):
1867918688 raise ValueError(msg)
1868018689
1868118690 return all(s * (self * x) >= 0
18682- for ( x, s) in K.discrete_complementarity_set())
18691+ for x, s in K.discrete_complementarity_set())
1868318692
1868418693 def is_Z_operator_on(self, K):
1868518694 r"""
@@ -18955,7 +18964,7 @@ cdef class Matrix(Matrix1):
1895518964 # many inequalities as the number of equalities that we're
1895618965 # about to check.
1895718966 return all(s * (self * x) == 0
18958- for ( x, s) in K.discrete_complementarity_set())
18967+ for x, s in K.discrete_complementarity_set())
1895918968
1896018969 def LLL_gram(self, flag=0):
1896118970 """
@@ -19775,7 +19784,7 @@ cdef class Matrix(Matrix1):
1977519784 [ 0 0 27], ((0, 0, 0), (0, 1, 1), (0, 2, 2))
1977619785 )
1977719786 sage: rows.sort(key=lambda x: (x[1] + shifts[x[0]], x[0]))
19778- sage: [(i, j) for ( i, j, k) in rows[:3]]
19787+ sage: [(i, j) for i, j, k in rows[:3]]
1977919788 [(0, 0),
1978019789 (0, 1),
1978119790 (0, 2)]
@@ -19798,7 +19807,7 @@ cdef class Matrix(Matrix1):
1979819807 [ 0 0 50], ((1, 0, 0), (1, 1, 1), (1, 2, 2))
1979919808 )
1980019809 sage: rows.sort(key=lambda x: (x[1] + shifts[x[0]], x[0]))
19801- sage: [(i, j) for ( i, j, k) in rows[:3]]
19810+ sage: [(i, j) for i, j, k in rows[:3]]
1980219811 [(1, 0),
1980319812 (1, 1),
1980419813 (1, 2)]
0 commit comments