Ticket #12841: trac_12841_m4rie_new_version.patch

File trac_12841_m4rie_new_version.patch, 8.9 KB (added by malb, 14 months ago)
  • sage/libs/m4rie.pxd

    # HG changeset patch
    # User Martin Albrecht <martinralbrecht@googlemail.com>
    # Date 1326300377 -3600
    # Node ID 62b283ab0192cdaf62719e332ec700528aaadece
    # Parent  ba3a0fe5a10da1f31070c6e80128530bc8440173
    #12841: adapted to new M4RIE version
    
    diff --git a/sage/libs/m4rie.pxd b/sage/libs/m4rie.pxd
    a b  
    1818 
    1919    void gf2e_free(gf2e *ff) 
    2020 
    21 #cdef extern from "m4rie/gf2e_matrix.h": 
     21#cdef extern from "m4rie/mzed.h": 
    2222    ctypedef struct mzed_t: 
    2323        mzd_t *x 
    2424        gf2e *finite_field 
     
    8787 
    8888    void mzed_print(const_mzed_t *M) 
    8989  
    90     mzed_t *mzed_invert_travolta(mzed_t *A, mzed_t *B) 
     90    mzed_t *mzed_invert_newton_john(mzed_t *A, mzed_t *B) 
    9191 
    9292    # TODO: not implemented yet in m4rie 
    9393    double mzed_density(mzed_t *A, int res) 
     
    9595    # TODO: not implemented yet in m4rie 
    9696    double _mzed_density(mzed_t *A, int res, size_t r, size_t c) 
    9797 
    98 #cdef extern from "m4rie/travolta.h": 
    99     size_t mzed_echelonize_travolta(mzed_t *, size_t) 
     98#cdef extern from "m4rie/newton_john.h": 
     99    size_t mzed_echelonize_newton_john(mzed_t *, size_t) 
    100100 
    101     mzed_t *mzed_mul_travolta(mzed_t *, mzed_t *, mzed_t *) 
     101    mzed_t *mzed_mul_newton_john(mzed_t *, mzed_t *, mzed_t *) 
    102102 
    103103#cdef extern from "m4rie/echelonform.h": 
    104104    size_t mzed_echelonize(mzed_t *, size_t) 
     
    110110 
    111111    size_t _mzed_strassen_cutoff(mzed_t *C, mzed_t *A, mzed_t *B) 
    112112 
    113 #cdef extern from "m4rie/bitslice.h": 
     113#cdef extern from "m4rie/mzd_slice.h": 
    114114 
    115115    int __M4RIE_MAX_KARATSUBA_DEGREE 
    116116 
  • sage/matrix/matrix_mod2e_dense.pxd

    diff --git a/sage/matrix/matrix_mod2e_dense.pxd b/sage/matrix/matrix_mod2e_dense.pxd
    a b  
    1212    cdef object _one 
    1313    cdef object _zero 
    1414 
    15     cpdef Matrix_mod2e_dense _multiply_travolta(Matrix_mod2e_dense self, Matrix_mod2e_dense right) 
     15    cpdef Matrix_mod2e_dense _multiply_newton_john(Matrix_mod2e_dense self, Matrix_mod2e_dense right) 
    1616    cpdef Matrix_mod2e_dense _multiply_karatsuba(Matrix_mod2e_dense self, Matrix_mod2e_dense right) 
    1717    cpdef Matrix_mod2e_dense _multiply_strassen(Matrix_mod2e_dense self, Matrix_mod2e_dense right, cutoff=*) 
  • sage/matrix/matrix_mod2e_dense.pyx

    diff --git a/sage/matrix/matrix_mod2e_dense.pyx b/sage/matrix/matrix_mod2e_dense.pyx
    a b  
    1212  represented as ``[0xxx|0xxx|0xxx|0xxx|...]``. This representation is 
    1313  wrapped as :class:`Matrix_mod2e_dense` in Sage. 
    1414 
    15   Multiplication and elimination both use "Travolta" tables. These 
     15  Multiplication and elimination both use "Newton-John" tables. These 
    1616  tables are simply all possible multiples of a given row in a matrix 
    1717  such that a scale+add operation is reduced to a table lookup + 
    18   add. On top of Travolta multiplication M4RIE implements 
     18  add. On top of Newton-John multiplication M4RIE implements 
    1919  asymptotically fast Strassen-Winograd multiplication. Elimination 
    2020  uses simple Gaussian elimination which requires `O(n^3)` additions 
    2121  but only `O(n^2 * 2^e)` multiplications. 
     
    430430            sage: K.<a> = GF(2^3) 
    431431            sage: A = random_matrix(K, 51, 50) 
    432432            sage: B = random_matrix(K, 50, 52) 
    433             sage: A*B == A._multiply_travolta(B) # indirect doctest 
     433            sage: A*B == A._multiply_newton_john(B) # indirect doctest 
    434434            True 
    435435 
    436436            sage: K.<a> = GF(2^5) 
    437437            sage: A = random_matrix(K, 10, 50) 
    438438            sage: B = random_matrix(K, 50, 12) 
    439             sage: A*B == A._multiply_travolta(B) 
     439            sage: A*B == A._multiply_newton_john(B) 
    440440            True 
    441441 
    442442            sage: K.<a> = GF(2^7) 
     
    458458        _sig_off 
    459459        return ans 
    460460 
    461     cpdef Matrix_mod2e_dense _multiply_travolta(Matrix_mod2e_dense self, Matrix_mod2e_dense right): 
     461    cpdef Matrix_mod2e_dense _multiply_newton_john(Matrix_mod2e_dense self, Matrix_mod2e_dense right): 
    462462        """ 
    463         Return A*B using Travolta tables. 
     463        Return A*B using Newton-John tables. 
    464464 
    465465        We can write classical cubic multiplication (``C=A*B``) as:: 
    466466 
     
    474474        ``e * B[j]`` is computed more than once for any ``e`` in the finite 
    475475        field. Instead, we compute all possible 
    476476        multiples of ``B[j]`` and re-use this data in the inner loop. 
    477         This is what is called a "Travolta" table in M4RIE. 
     477        This is what is called a "Newton-John" table in M4RIE. 
    478478 
    479479        INPUT: 
    480480 
     
    485485            sage: K.<a> = GF(2^2) 
    486486            sage: A = random_matrix(K, 50, 50) 
    487487            sage: B = random_matrix(K, 50, 50) 
    488             sage: A._multiply_travolta(B) == A._multiply_classical(B) # indirect doctest 
     488            sage: A._multiply_newton_john(B) == A._multiply_classical(B) # indirect doctest 
    489489            True 
    490490 
    491491            sage: K.<a> = GF(2^4) 
    492492            sage: A = random_matrix(K, 50, 50) 
    493493            sage: B = random_matrix(K, 50, 50) 
    494             sage: A._multiply_travolta(B) == A._multiply_classical(B) 
     494            sage: A._multiply_newton_john(B) == A._multiply_classical(B) 
    495495            True 
    496496 
    497497            sage: K.<a> = GF(2^8) 
    498498            sage: A = random_matrix(K, 50, 50) 
    499499            sage: B = random_matrix(K, 50, 50) 
    500             sage: A._multiply_travolta(B) == A._multiply_classical(B) 
     500            sage: A._multiply_newton_john(B) == A._multiply_classical(B) 
    501501            True 
    502502 
    503503            sage: K.<a> = GF(2^10) 
    504504            sage: A = random_matrix(K, 50, 50) 
    505505            sage: B = random_matrix(K, 50, 50) 
    506             sage: A._multiply_travolta(B) == A._multiply_classical(B) 
     506            sage: A._multiply_newton_john(B) == A._multiply_classical(B) 
    507507            True 
    508508        """ 
    509509        if self._ncols != right._nrows: 
     
    516516            return ans 
    517517 
    518518        _sig_on 
    519         ans._entries = mzed_mul_travolta(ans._entries, self._entries, (<Matrix_mod2e_dense>right)._entries) 
     519        ans._entries = mzed_mul_newton_john(ans._entries, self._entries, (<Matrix_mod2e_dense>right)._entries) 
    520520        _sig_off 
    521521        return ans 
    522522 
     
    550550 
    551551        TESTS:: 
    552552 
    553             sage: K.<a> = GF(2^5) 
     553            sage: K.<a> = GF(2^10) 
    554554            sage: A = random_matrix(K, 50, 50) 
    555555            sage: B = random_matrix(K, 50, 50) 
    556556            sage: A._multiply_karatsuba(B) == A._multiply_classical(B) 
    557557            Traceback (most recent call last): 
    558558            ... 
    559             NotImplementedError: Karatsuba multiplication is only implemented for matrices over GF(2^e) with e <= 4. 
     559            NotImplementedError: Karatsuba multiplication is only implemented for matrices over GF(2^e) with e <= 8. 
    560560        """ 
    561561        if self._ncols != right._nrows: 
    562562            raise ArithmeticError("left ncols must match right nrows") 
     
    577577 
    578578    cpdef Matrix_mod2e_dense _multiply_strassen(Matrix_mod2e_dense self, Matrix_mod2e_dense right, cutoff=0): 
    579579        """ 
    580         Winograd-Strassen matrix multiplication with Travolta 
     580        Winograd-Strassen matrix multiplication with Newton-John 
    581581        multiplication as base case. 
    582582 
    583583        INPUT: 
    584584 
    585585        - ``right`` - a matrix 
    586586        - ``cutoff`` - row or column dimension to switch over to 
    587           Travolta multiplication (default: 64) 
     587          Newton-John multiplication (default: 64) 
    588588 
    589589        EXAMPLES:: 
    590590 
     
    877877 
    878878        - ``algorithm`` - one of the following 
    879879          - ``heuristic`` - let M4RIE decide (default) 
    880           - ``travolta`` - use travolta table based algorithm 
     880          - ``newton_john`` - use newton_john table based algorithm 
    881881          - ``ple`` - use PLE decomposition 
    882882          - ``naive`` - use naive cubic Gaussian elimination (M4RIE implementation) 
    883883          - ``builtin`` - use naive cubic Gaussian elimination (Sage implementation) 
     
    904904            sage: MS = MatrixSpace(K,m,n) 
    905905            sage: A = random_matrix(K, 3, 5) 
    906906 
    907             sage: copy(A).echelon_form('travolta') 
     907            sage: copy(A).echelon_form('newton_john') 
    908908            [          1           0           0         a^2     a^2 + 1] 
    909909            [          0           1           0         a^2           1] 
    910910            [          0           0           1 a^2 + a + 1       a + 1] 
     
    940940            r =  mzed_echelonize_naive(self._entries, full) 
    941941            _sig_off 
    942942             
    943         elif algorithm == 'travolta': 
     943        elif algorithm == 'newton_john': 
    944944            _sig_on 
    945             r =  mzed_echelonize_travolta(self._entries, full) 
     945            r =  mzed_echelonize_newton_john(self._entries, full) 
    946946            _sig_off 
    947947             
    948948        elif algorithm == 'ple': 
     
    10141014        A = Matrix_mod2e_dense.__new__(Matrix_mod2e_dense, self._parent, 0, 0, 0) 
    10151015         
    10161016        if self._nrows and self._nrows == self._ncols: 
    1017             mzed_invert_travolta(A._entries, self._entries) 
     1017            mzed_invert_newton_john(A._entries, self._entries) 
    10181018 
    10191019        return A 
    10201020