Ticket #10734: trac_10734.03-referee_refactor_to_support_p2.patch

File trac_10734.03-referee_refactor_to_support_p2.patch, 9.0 KB (added by Gonzalo Tornaría, 11 years ago)

refactor code to support p=2 case (part 1)

  • module_list.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1302244060 25200
    # Node ID 12f01df427a0005e5dccfc5cecdb5d6980562c7d
    # Parent dad7d059b9287f15433ffaddecd2e052cfac2fab
    refactor code to support p=2 case (part 1)
    
    diff -r dad7d059b928 module_list.py
    a b  
    892892              sources = ['sage/matrix/matrix_modn_dense.pyx'],
    893893              libraries = ['gmp']),
    894894
     895    Extension('sage.matrix.matrix_mod_dense',
     896              sources = ['sage/matrix/matrix_mod_dense.pyx']),
     897
    895898    Extension('sage.matrix.matrix_modn_sparse',
    896899              sources = ['sage/matrix/matrix_modn_sparse.pyx'],
    897900              libraries = ['gmp']),
  • sage/matrix/matrix_mod2_dense.pxd

    diff -r dad7d059b928 sage/matrix/matrix_mod2_dense.pxd
    a b  
    11# choose: dense or sparse
    22
    3 cimport matrix_dense
     3from matrix_mod_dense cimport Matrix_mod_dense
    44
    55from sage.libs.m4ri cimport *
    66
    7 cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense):
     7cdef class Matrix_mod2_dense(Matrix_mod_dense):
    88    cdef mzd_t *_entries
    99    cdef object _one
    1010    cdef object _zero
    1111
    12     cdef set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value)
    13 
    1412    cpdef Matrix_mod2_dense _multiply_m4rm(Matrix_mod2_dense self, Matrix_mod2_dense right, int k)
    1513    cpdef Matrix_mod2_dense _multiply_strassen(Matrix_mod2_dense self, Matrix_mod2_dense right, int cutoff)
    1614
  • sage/matrix/matrix_mod2_dense.pyx

    diff -r dad7d059b928 sage/matrix/matrix_mod2_dense.pyx
    a b  
    149149
    150150   
    151151
    152 cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense):   # dense or sparse
     152cdef class Matrix_mod2_dense(Matrix_mod_dense):
    153153    """
    154154    Dense matrix over GF(2).
    155155    """
     
    431431    cdef set_unsafe(self, Py_ssize_t i, Py_ssize_t j, value):
    432432        mzd_write_bit(self._entries, i, j, int(value))
    433433
     434    # this exists for compatibility with matrix_modn_dense
     435    cdef int get_unsafe_int(self, Py_ssize_t i, Py_ssize_t j):
     436        """
     437        Get the (i,j) entry of self as an int.
     438        """
     439        if mzd_read_bit(self._entries, i, j):
     440            return 1
     441        else:
     442            return 0
     443
    434444    cdef get_unsafe(self, Py_ssize_t i, Py_ssize_t j):
    435445        if mzd_read_bit(self._entries, i, j):
    436446            return self._one
  • new file sage/matrix/matrix_mod_dense.pxd

    diff -r dad7d059b928 sage/matrix/matrix_mod_dense.pxd
    - +  
     1cimport matrix_dense
     2
     3cdef class Matrix_mod_dense(matrix_dense.Matrix_dense):
     4    cdef set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value)
     5    cdef int get_unsafe_int(self, Py_ssize_t i, Py_ssize_t j)
     6
     7
  • new file sage/matrix/matrix_mod_dense.pyx

    diff -r dad7d059b928 sage/matrix/matrix_mod_dense.pyx
    - +  
     1cdef class Matrix_mod_dense(matrix_dense.Matrix_dense):
     2    cdef set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value):
     3        raise NotImplementedError
     4
     5    cdef int get_unsafe_int(self, Py_ssize_t i, Py_ssize_t j):
     6        raise NotImplementedError
  • sage/matrix/matrix_modn_dense.pxd

    diff -r dad7d059b928 sage/matrix/matrix_modn_dense.pxd
    a b  
    11cimport matrix_dense
     2from matrix_mod_dense cimport Matrix_mod_dense
    23
    34cdef extern from "../ext/multi_modular.h":
    45    ctypedef unsigned long mod_int
    56    mod_int MOD_INT_OVERFLOW
    67
    7 cdef class Matrix_modn_dense(matrix_dense.Matrix_dense):
     8cdef class Matrix_modn_dense(Matrix_mod_dense):
    89    cdef mod_int **_matrix
    910    cdef mod_int *_entries
    1011    cdef mod_int p
     
    1314    #cdef set_matrix(Matrix_modn_dense self, mod_int **m)
    1415    #cdef mod_int **get_matrix(Matrix_modn_dense self)
    1516    #cdef mod_int entry(self, mod_int i, mod_int j)
    16     cdef set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value)
    17     cdef get_unsafe_int(self, Py_ssize_t i, Py_ssize_t j)
    1817    cdef _rescale_row_c(self, Py_ssize_t row, mod_int multiple, Py_ssize_t start_col)
    1918    cdef _rescale_col_c(self, Py_ssize_t col, mod_int multiple, Py_ssize_t start_row)   
    2019    cdef _add_multiple_of_row_c(self,  Py_ssize_t row_to, Py_ssize_t row_from,
  • sage/matrix/matrix_modn_dense.pyx

    diff -r dad7d059b928 sage/matrix/matrix_modn_dense.pyx
    a b  
    165165#                  http://www.gnu.org/licenses/
    166166##############################################################################
    167167
    168 cdef class Matrix_modn_dense(matrix_dense.Matrix_dense): 
     168cdef class Matrix_modn_dense(Matrix_mod_dense):
    169169    ########################################################################
    170170    # LEVEL 1 functionality
    171171    # x * __cinit__ 
     
    355355        """       
    356356        self._matrix[i][j] = (<IntegerMod_int> value).ivalue
    357357
    358     cdef get_unsafe_int(self, Py_ssize_t i, Py_ssize_t j):
     358    cdef int get_unsafe_int(self, Py_ssize_t i, Py_ssize_t j):
    359359        """
    360360        Get the (i,j) entry of self as an int value, no checks.
    361361        """
  • sage/matrix/matrix_modn_sparse.pxd

    diff -r dad7d059b928 sage/matrix/matrix_modn_sparse.pxd
    a b  
    1 from matrix_modn_dense cimport Matrix_modn_dense
     1include '../modules/vector_modn_sparse_h.pxi'
    22
    3 include '../modules/vector_modn_sparse_h.pxi'
     3cimport matrix_sparse
     4cimport matrix_dense
     5
     6from matrix_mod_dense cimport Matrix_mod_dense
     7
     8
    49
    510cdef class Matrix_modn_sparse(matrix_sparse.Matrix_sparse):   
    611    cdef c_vector_modint* rows
    712    cdef public int p
    813    cdef swap_rows_c(self, Py_ssize_t n1, Py_ssize_t n2)
    9     cdef set_block_unsafe(self, Py_ssize_t row, Py_ssize_t col, Matrix_modn_dense block)
     14    cdef set_block_unsafe(self, Py_ssize_t row, Py_ssize_t col, Matrix_mod_dense block)
    1015
    1116    cdef _init_linbox(self)
  • sage/matrix/matrix_modn_sparse.pyx

    diff -r dad7d059b928 sage/matrix/matrix_modn_sparse.pyx
    a b  
    8080include '../modules/vector_modn_sparse_c.pxi'
    8181
    8282cimport matrix
    83 cimport matrix_sparse
    84 cimport matrix_dense
    8583from sage.rings.finite_rings.integer_mod cimport IntegerMod_int, IntegerMod_abstract
    8684
    8785from sage.misc.misc import verbose, get_verbose, graphics_filename
     
    9492from sage.structure.element import is_Vector
    9593
    9694cimport sage.structure.element
    97 from matrix_modn_dense cimport Matrix_modn_dense
    9895
    9996include '../modules/binary_search.pxi'
    10097include '../modules/vector_integer_sparse_h.pxi'
     
    573570
    574571        M = self.new_matrix(nrows, ncols)
    575572        for i from 0 <= i < nrows:
    576           for j from 0 <= j < self.rows[row+i].num_nonzero:
    577             pos = self.rows[row+i].positions[j] - col
    578             if 0 <= pos < ncols:
    579               set_entry(&M.rows[i], pos, self.rows[row+i].entries[j])
     573            for j from 0 <= j < self.rows[row+i].num_nonzero:
     574                pos = self.rows[row+i].positions[j] - col
     575                if 0 <= pos < ncols:
     576                    set_entry(&M.rows[i], pos, self.rows[row+i].entries[j])
    580577        return M
    581578
    582579    def dense_matrix(self):
     
    602599            Full MatrixSpace of 4 by 4 dense matrices over Ring of integers modulo 7
    603600        """
    604601        cdef Py_ssize_t i, j
    605         cdef Matrix_modn_dense M
     602        cdef Matrix_mod_dense M
    606603
    607604        M = self.new_matrix(self._nrows, self._ncols, sparse=False)
    608605        for i from 0 <= i < self._nrows:
     
    645642            True
    646643        """
    647644        cdef Py_ssize_t i, j, pos
    648         cdef Matrix_modn_dense M
     645        cdef Matrix_mod_dense M
    649646
    650647        if nrows == -1:
    651           nrows = self._nrows - row
     648            nrows = self._nrows - row
    652649        if ncols == -1:
    653           ncols = self._ncols - col
     650            ncols = self._ncols - col
    654651
    655652        M = self.new_matrix(nrows, ncols, sparse=False)
    656653        for i from 0 <= i < nrows:
    657           for j from 0 <= j < self.rows[row+i].num_nonzero:
    658             pos = self.rows[row+i].positions[j] - col
    659             if 0 <= pos < ncols:
    660               M.set_unsafe_int(i, pos, self.rows[row+i].entries[j])
     654            for j from 0 <= j < self.rows[row+i].num_nonzero:
     655                pos = self.rows[row+i].positions[j] - col
     656                if 0 <= pos < ncols:
     657                    M.set_unsafe_int(i, pos, self.rows[row+i].entries[j])
    661658        return M
    662659
    663     cdef set_block_unsafe(self, Py_ssize_t row, Py_ssize_t col, Matrix_modn_dense block):
     660    cdef set_block_unsafe(self, Py_ssize_t row, Py_ssize_t col, Matrix_mod_dense block):
    664661        """
    665662        Sets the sub-matrix of self, with upper left corner given by row,
    666663        col to block. No checks.