Ticket #4527: sage-4527.patch

File sage-4527.patch, 2.5 KB (added by was, 14 years ago)

this should fix it. the main bug was an off by a factor of two overflow.

  • sage/matrix/matrix_integer_dense.pxd

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1226712530 28800
    # Node ID 855c0f36ea4e6bf5683969bbd7c4aeed8b9b0110
    # Parent  b03e1c6afc63eab7625decd170948528eb414eb2
    #4527 -- weird "Exception in 'sage.matrix.matrix_integer_dense.Matrix_integer_dense._hnf_modn_impl'" (joint work with Craig Citro and Clement Pernet)
    
    diff -r b03e1c6afc63 -r 855c0f36ea4e sage/matrix/matrix_integer_dense.pxd
    a b  
    2727    cdef int _hnf_modn(Matrix_integer_dense self, Matrix_integer_dense res,
    2828            mod_int det) except -1
    2929    cdef long long* _hnf_modn_impl(Matrix_integer_dense self, mod_int det,
    30                                    Py_ssize_t nrows, Py_ssize_t ncols)
     30                                   Py_ssize_t nrows, Py_ssize_t ncols) except NULL
    3131    cdef _new_uninitialized_matrix(self, Py_ssize_t nrows, Py_ssize_t ncols)
  • sage/matrix/matrix_integer_dense.pyx

    diff -r b03e1c6afc63 -r 855c0f36ea4e sage/matrix/matrix_integer_dense.pyx
    a b  
    34533453
    34543454
    34553455    cdef long long* _hnf_modn_impl(Matrix_integer_dense self, mod_int det,
    3456             Py_ssize_t nrows, Py_ssize_t ncols):
     3456            Py_ssize_t nrows, Py_ssize_t ncols) except NULL:
    34573457        cdef long long *res, *T_ent, **res_rows, **T_rows, *B
    34583458        cdef Py_ssize_t i, j, k
    34593459        cdef long long R, mod, T_i_i, T_j_i, c1, c2, q, t
  • sage/matrix/matrix_integer_dense_hnf.py

    diff -r b03e1c6afc63 -r 855c0f36ea4e sage/matrix/matrix_integer_dense_hnf.py
    a b  
    538538        # Since we have no good conditioning code at present,
    539539        # in this case we just fall back to using pari.
    540540        H = W.echelon_form(algorithm='pari')
    541     elif g > CUTOFF:
     541    elif 2*g > CUTOFF:
    542542        # Unlikely that g will be large on even slightly random input
    543543        # if it is, we fallback to the traditional algorithm.
    544544        # A nasty example is A = n*random_matrix(ZZ,m), where
    545545        # this algorithm gets killed.  This is not random input though.
    546546        f = W.gcd()
    547547        g = g / (f**W.nrows())
    548         if g <= CUTOFF:
     548        if 2*g <= CUTOFF:
    549549            verbose("Found common factor of %s -- dividing out; get new g = %s"%(f,g))
    550550            W0 = (W/f).change_ring(ZZ)
    551551            H = W0._hnf_mod(2*g)