Ticket #4260: trac_4260-minor_fixes.patch

File trac_4260-minor_fixes.patch, 4.6 KB (added by burcin, 9 years ago)

minor fixes

  • sage/matrix/matrix_integer_dense.pyx

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1317312469 -7200
    # Node ID a92619b6af73a23c22682faa90654e0786513441
    # Parent  7e1a7074f3e09c3da6f3afcb68bb0d0e544abc1e
    trac 4260: fix possible memory leak if allocation of modn_dense matrices fails
    
    diff --git a/sage/matrix/matrix_integer_dense.pyx b/sage/matrix/matrix_integer_dense.pyx
    a b  
    13011301        for k in range(n):
    13021302            row_list[k] = <mod_int*>sage_malloc(sizeof(mod_int)*nc)
    13031303            if row_list[k] == NULL:
     1304                for i in range(k):
     1305                    sage_free(row_list[i])
     1306                sage_free(row_list)
    13041307                raise MemoryError("out of memory allocating multi-modular coefficient list")
    13051308
    13061309        sig_on()
  • sage/matrix/matrix_modn_dense_double.pyx

    diff --git a/sage/matrix/matrix_modn_dense_double.pyx b/sage/matrix/matrix_modn_dense_double.pyx
    a b  
    165165            sage: K(1237101)^2
    166166            3803997
    167167        """
    168         if (<Matrix_modn_dense_template>self).p <= INTEGER_MOD_INT32_LIMIT:
     168        # note that INTEGER_MOD_INT32_LIMIT is ceil(sqrt(2^31-1)) < 2^23
     169        if (<Matrix_modn_dense_template>self).p <= INTEGER_MOD_INT32_LIMIT:
    169170            return IntegerMod_int(self._base_ring, <mod_int>(<Matrix_modn_dense_template>self)._matrix[i][j])
    170171        else:
    171172            return IntegerMod_int64(self._base_ring, <mod_int>(<Matrix_modn_dense_template>self)._matrix[i][j])
  • sage/matrix/matrix_modn_dense_template.pxi

    diff --git a/sage/matrix/matrix_modn_dense_template.pxi b/sage/matrix/matrix_modn_dense_template.pxi
    a b  
    8989    Invert the finite field element `a` modulo `n`.
    9090    """
    9191    # This is copied from linbox source linbox/field/modular-float.h
    92     # The extended Euclidean algoritm
     92    # The extended Euclidean algorithm
    9393    cdef int x_int, y_int, q, tx, ty, temp
    9494    x_int = <int>n
    9595    y_int = <int>a
     
    183183                ii = j+1
    184184                break
    185185
    186     # TODO: recover pivots
    187186    del F, A, E, EF
    188187    return r, pivots
    189188
     
    29062905        for j in range(self._ncols):
    29072906            to[j] = <mod_int>_from[j]
    29082907
    2909     # def new_matrix(self, nrows=None, ncols=None, entries=0, coerce=True, copy=True, sparse=None):
    2910     #     """
    2911     #     Create a matrix in the parent of this matrix with the given number
    2912     #     of rows, columns, etc. The default parameters are the same as for
    2913     #     self.
    2914 
    2915     #     INPUT:
    2916 
    2917     #     These three variables get sent to :func:`matrix_space`:
    2918 
    2919     #     - ``nrows``, ``ncols`` - number of rows and columns in returned
    2920     #       matrix. If not specified, defaults to ``None`` and will give a
    2921     #       matrix of the same size as self.
    2922     #     - ``sparse`` - whether returned matrix is sparse or
    2923     #       not. Defaults to same value as self.
    2924 
    2925     #     The remaining three variables (``coerce``, ``entries``, and
    2926     #     ``copy``) are used by
    2927     #     :func:`sage.matrix.matrix_space.MatrixSpace` to construct the
    2928     #     new matrix.
    2929 
    2930     #     .. warning::
    2931 
    2932     #        This function called with no arguments returns the zero
    2933     #        matrix of the same dimension and sparseness of self.
    2934 
    2935     #     EXAMPLE::
    2936 
    2937     #         sage: from sage.matrix.matrix_modn_dense_float import Matrix_modn_dense_float
    2938     #         sage: from sage.matrix.matrix_modn_dense_double import Matrix_modn_dense_double
    2939 
    2940     #         sage: K = GF(7)
    2941     #         sage: MS = MatrixSpace(K,100,100)
    2942     #         sage: A = Matrix_modn_dense_float(MS, None, False, False)
    2943     #         sage: B = Matrix_modn_dense_double(MS, None, False, False)
    2944     #         sage: type(A)
    2945     #         <type 'sage.matrix.matrix_modn_dense_float.Matrix_modn_dense_float'>
    2946     #         sage: type(A.new_matrix())
    2947     #         <type 'sage.matrix.matrix_modn_dense_float.Matrix_modn_dense_float'>
    2948     #         sage: type(B)
    2949     #         <type 'sage.matrix.matrix_modn_dense_double.Matrix_modn_dense_double'>
    2950     #         sage: type(B.new_matrix())
    2951     #         <type 'sage.matrix.matrix_modn_dense_double.Matrix_modn_dense_double'>
    2952     #     """
    2953     #     MS = self.matrix_space(nrows, ncols, sparse=sparse)
    2954     #     if sparse:
    2955     #         return MS(entries=entries, coerce=coerce, copy=copy)
    2956     #     else:
    2957     #         return self.__class__(MS, entries, coerce, copy)
    2958 
    29592908cpdef __matrix_from_rows_of_matrices(X):
    29602909    """
    29612910    Return a matrix whose row ``i`` is constructed from the entries of