Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
py3: future division in matrix2
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Chapoton committed Aug 27, 2017
1 parent 037272c commit e65a63e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/sage/matrix/matrix2.pyx
Expand Up @@ -39,7 +39,7 @@ bug, see :trac:`17527`)::
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function, absolute_import
from __future__ import print_function, absolute_import, division

from cpython cimport *
from cysignals.signals cimport sig_check
Expand Down Expand Up @@ -1348,30 +1348,31 @@ cdef class Matrix(Matrix1):
B = self.new_matrix()
for i in range(m):
for j in range(n):
B.set_unsafe(i,j, one-self.get_unsafe(i,j))
B.set_unsafe(i, j, one-self.get_unsafe(i, j))
b = B.rook_vector(algorithm=algorithm, use_complement=False)
complement = not complement

elif algorithm == "Ryser":
b = [self.permanental_minor(k,algorithm="Ryser") for k in range(mn+1)]
b = [self.permanental_minor(k,algorithm="Ryser")
for k in range(mn + 1)]

elif algorithm == "ButeraPernici":
p = permanental_minor_polynomial(self)
b = [p[k] for k in range(mn+1)]
b = [p[k] for k in range(mn + 1)]

elif algorithm == "Godsil":
from sage.graphs.bipartite_graph import BipartiteGraph
p = BipartiteGraph(self).matching_polynomial()
d = p.degree()
b = [p[i]*(-1)**((d - i)/2) for i in range(d, d-2*mn-1, -2)]
b = [p[i] * (-1)**((d - i)//2) for i in range(d, d-2*mn-1, -2)]

else:
raise ValueError('algorithm must be one of "Ryser", "ButeraPernici" or "Godsil".')

# now compute the permanental minor of the complement matrix if needed
if complement:
a = [one]
c1 = 1
c1 = QQ.one()
for k in range(1, mn + 1):
c1 = c1*(m-k+1)*(n-k+1)/k
c = c1
Expand Down Expand Up @@ -15013,17 +15014,17 @@ def _binomial(Py_ssize_t n, Py_ssize_t k):
"""
cdef Py_ssize_t i

if k > (n/2):
k = n-k
if 2 * k > n:
k = n - k
if k == 0:
return 1

result = n
n, k = n-1, k-1
n, k = n - 1, k - 1
i = 2
while k > 0:
result = (result*n)/i
i, n, k = i+1, n-1, k-1
result = (result * n) // i
i, n, k = i + 1, n - 1, k - 1
return result

def _jordan_form_vector_in_difference(V, W):
Expand Down

0 comments on commit e65a63e

Please sign in to comment.