Ticket #9475: m4ri_new_version.v2.patch

File m4ri_new_version.v2.patch, 7.8 KB (added by malb, 11 years ago)

Sage library patch - needed to comply with new M4RI API (libm4ri-20100701). (Contains ticket number; apply only this one.)

  • module_list.py

    # HG changeset patch
    # User Martin Albrecht <malb@informatik.uni-bremen.de>
    # Date 1277764034 -3600
    # Node ID 2f5bf687e3d270fb146e70d00f511d10113abf26
    # Parent  0bb69a98789215c64a81c4602f46a50c0aeca5f0
    #9475 Adapts Sage library interface to new M4RI API (libm4ri-20100701)
    
    diff -r 0bb69a987892 -r 2f5bf687e3d2 module_list.py
    a b  
    807807    Extension('sage.matrix.matrix_mod2_dense',
    808808              sources = ['sage/matrix/matrix_mod2_dense.pyx'],
    809809              libraries = ['gmp','m4ri', 'gd', 'png12', 'z'],
    810               depends = [SAGE_ROOT + "/local/include/png.h"]),
     810              depends = [SAGE_ROOT + "/local/include/png.h", SAGE_ROOT + "/local/include/m4ri/m4ri.h"]),
    811811
    812812    Extension('sage.matrix.matrix_modn_dense',
    813813              sources = ['sage/matrix/matrix_modn_dense.pyx'],
     
    995995    Extension('sage.modules.vector_mod2_dense',
    996996              sources = ['sage/modules/vector_mod2_dense.pyx'],
    997997              libraries = ['gmp','m4ri', 'png12', 'gd'],
    998               depends = [SAGE_ROOT + "/local/include/png.h"]),
     998              depends = [SAGE_ROOT + "/local/include/png.h", SAGE_ROOT + "/local/include/m4ri/m4ri.h"]),
    999999   
    10001000    Extension('sage.modules.vector_rational_dense',
    10011001              sources = ['sage/modules/vector_rational_dense.pyx'],
  • sage/libs/m4ri.pxd

    diff -r 0bb69a987892 -r 2f5bf687e3d2 sage/libs/m4ri.pxd
    a b  
    141141    # reduced row echelon form from upper triangular form
    142142    cdef void mzd_top_echelonize_m4ri(mzd_t *m, int k)
    143143
     144    # heuristic choice of algorithms
     145    cdef int mzd_echelonize(mzd_t *m, int full)
     146
    144147    # matrix inversion using Gray codes
    145148    cdef mzd_t *mzd_invert_m4ri(mzd_t *m, mzd_t *identity, int k)
    146149
     
    153156    # cubic PLUQ factorization
    154157    cdef long _mzd_pluq_naive(mzd_t *A, mzp_t *P, mzp_t *Q)
    155158
    156     # asymptotically fast LQUP factorization
    157     cdef long mzd_lqup(mzd_t *A, mzp_t *P, mzp_t *Q, int cutoff)
     159    # asymptotically fast PLS factorization
     160    cdef long mzd_pls(mzd_t *A, mzp_t *P, mzp_t *Q, int cutoff)
    158161
    159     # LQUP factorization using Gray codes
    160     cdef long _mzd_lqup_mmpf(mzd_t *A, mzp_t *P, mzp_t *Q, int k)
     162    # PLS factorization using Gray codes
     163    cdef long _mzd_pls_mmpf(mzd_t *A, mzp_t *P, mzp_t *Q, int k)
    161164
    162     # cubic LQUP factorization
    163     cdef long _mzd_lqup_naive(mzd_t *A, mzp_t *P, mzp_t *Q)
     165    # cubic PLS factorization
     166    cdef long _mzd_pls_naive(mzd_t *A, mzp_t *P, mzp_t *Q)
    164167
    165168    # reduced row echelon form using PLUQ factorization
    166169    cdef long mzd_echelonize_pluq(mzd_t *A, int full)
  • sage/matrix/matrix_mod2_dense.pyx

    diff -r 0bb69a987892 -r 2f5bf687e3d2 sage/matrix/matrix_mod2_dense.pyx
    a b  
    10101010    #    * Matrix windows -- only if you need strassen for that base
    10111011    ########################################################################
    10121012
    1013     def echelonize(self, algorithm='m4ri', cutoff=0, reduced=True, **kwds):
     1013    def echelonize(self, algorithm='heuristic', cutoff=0, reduced=True, **kwds):
    10141014        """
    10151015        Puts self in (reduced) row echelon form.
    10161016
    10171017        INPUT:
    10181018            self -- a mutable matrix
    1019             algorithm -- 'm4ri' -- uses M4RI (default)
     1019            algorithm -- 'heuristic' -- uses M4RI and PLUQ (default)
     1020                         'm4ri' -- uses M4RI
     1021                         'pluq' -- uses PLUQ factorization
    10201022                         'classical' -- uses classical Gaussian elimination
    1021                          'pluq' -- uses PLUQ factorization
    10221023            k --  the parameter 'k' of the M4RI algorithm. It MUST be between
    10231024                  1 and 16 (inclusive). If it is not specified it will be calculated as
    10241025                  3/4 * log_2( min(nrows, ncols) ) as suggested in the M4RI paper.
     
    10661067        x = self.fetch('in_echelon_form')
    10671068        if not x is None: return  # already known to be in echelon form
    10681069
    1069         if algorithm == 'm4ri':
     1070        if algorithm == 'heuristic':
     1071
     1072            self.check_mutability()
     1073            self.clear_cache()       
     1074
     1075            _sig_on
     1076            r =  mzd_echelonize(self._entries, full)
     1077            _sig_off
     1078           
     1079            self.cache('in_echelon_form',True)
     1080            self.cache('rank', r)
     1081            self.cache('pivots', self._pivots())
     1082
     1083        elif algorithm == 'm4ri':
    10701084
    10711085            self.check_mutability()
    10721086            self.clear_cache()       
     
    10781092                    raise RuntimeError,"k must be between 1 and 16"
    10791093                k = round(k)
    10801094            else:
    1081                 #n = min(self._nrows, self._ncols)
    1082                 #k = round(min(0.75 * log(n,2), 16))
    1083                 #if k<1:
    1084                 #    k = 1
    10851095                k = 0
    10861096
    10871097            _sig_on
     
    16811691            sage: float(d)
    16821692            0.63184899999999999
    16831693            sage: A.density(approx=True)
    1684             0.631445000000000
     1694            0.631849000000000
    16851695            sage: float(len(A.nonzero_positions())/1000^2)
    16861696            0.63184899999999999
    16871697        """
     
    16911701        else:
    16921702            return matrix_dense.Matrix_dense.density(self)
    16931703
    1694     def rank(self, algorithm='lqup'):
     1704    def rank(self, algorithm='pls'):
    16951705        """
    16961706        Return the rank of this matrix.
    16971707
    1698         On average 'lqup' should be faster than 'm4ri' and hence it is
     1708        On average 'pls' should be faster than 'm4ri' and hence it is
    16991709        the default choice. However, for small - i.e. quite few
    17001710        thousand rows & columns - and sparse matrices 'm4ri' might be
    17011711        a better choice.
    17021712
    17031713        INPUT:
    17041714
    1705         - ``algorithm`` - either "lqup" or "m4ri"
     1715        - ``algorithm`` - either "pls" or "m4ri"
    17061716
    17071717        EXAMPLE::
    17081718
     
    17221732        cdef mzd_t *A = mzd_copy(NULL, self._entries)
    17231733        cdef mzp_t *P, *Q
    17241734
    1725         if algorithm == 'lqup':
     1735        if algorithm == 'pls':
    17261736            P = mzp_init(self._entries.nrows)
    17271737            Q = mzp_init(self._entries.ncols)
    1728             r = mzd_lqup(A, P, Q, 0)
     1738            r = mzd_pls(A, P, Q, 0)
    17291739            mzp_free(P)
    17301740            mzp_free(Q)
    17311741        elif algorithm == 'm4ri':
     
    20602070    mzp_free(q)
    20612071    return B,P,Q
    20622072
    2063 def lqup(Matrix_mod2_dense A, algorithm="standard", int param=0):
     2073def pls(Matrix_mod2_dense A, algorithm="standard", int param=0):
    20642074    """
    2065     Return LQUP factorization of A.
     2075    Return PLS factorization of A.
    20662076
    20672077    INPUT:
    20682078        A -- matrix
     
    20742084
    20752085    EXAMPLE::
    20762086
    2077         sage: from sage.matrix.matrix_mod2_dense import lqup
     2087        sage: from sage.matrix.matrix_mod2_dense import pls
    20782088        sage: A = random_matrix(GF(2),4,4); A
    20792089        [1 0 0 1]
    20802090        [1 1 0 1]
    20812091        [0 1 0 1]
    20822092        [0 1 1 0]
    20832093
    2084         sage: LU, P, Q = lqup(A)
     2094        sage: LU, P, Q = pls(A)
    20852095        sage: LU
    20862096        [1 0 0 1]
    20872097        [1 1 0 0]
     
    20952105        [0, 1, 2, 3]
    20962106
    20972107        sage: A = random_matrix(GF(2),1000,1000)
    2098         sage: lqup(A) == lqup(A,'mmpf') == lqup(A,'naive')
     2108        sage: pls(A) == pls(A,'mmpf') == pls(A,'naive')
    20992109        True
    21002110    """
    21012111    cdef Matrix_mod2_dense B = A.__copy__()
     
    21042114
    21052115    if algorithm == 'standard':
    21062116        _sig_on
    2107         mzd_lqup(B._entries, p, q, param)
     2117        mzd_pls(B._entries, p, q, param)
    21082118        _sig_off
    21092119    elif algorithm == "mmpf":
    21102120        _sig_on
    2111         _mzd_lqup_mmpf(B._entries, p, q, param)
     2121        _mzd_pls_mmpf(B._entries, p, q, param)
    21122122        _sig_off
    21132123    elif algorithm == "naive":
    21142124        _sig_on
    2115         _mzd_lqup_naive(B._entries, p, q)
     2125        _mzd_pls_naive(B._entries, p, q)
    21162126        _sig_off
    21172127    else:
    21182128        raise ValueError("Algorithm '%s' unknown."%algorithm)