Ticket #8276: trac-8276-fix_sagelib-review.patch

File trac-8276-fix_sagelib-review.patch, 9.7 KB (added by mraum, 11 years ago)

Seconded reviewed patch.

  • sage/algebras/quatalg/quaternion_algebra_cython.pyx

    # HG changeset patch
    # User Florent Hivert <Florent.Hivert@univ-rouen.fr>
    # Date 1266429254 -3600
    # Node ID 028e0be953f5e73fb867a02966d52a25afd1cb27
    # Parent  875d385920904fb995babb0f749a6db2de4f324a
    #8276: Make one(), identity_matrix() and zero_matrix() cached and immutable.
    Fix Sage's lib accordingly.
    
    diff --git a/sage/algebras/quatalg/quaternion_algebra_cython.pyx b/sage/algebras/quatalg/quaternion_algebra_cython.pyx
    a b def integral_matrix_and_denom_from_ratio 
    6666   
    6767    cdef Py_ssize_t i, n=len(v)
    6868    M = MatrixSpace(ZZ, n, 4)
    69     cdef Matrix_integer_dense A = M.zero_matrix()
     69    cdef Matrix_integer_dense A = M.zero_matrix().__copy__()
    7070    if n == 0: return A
    7171   
    7272    # Find least common multiple of the denominators
    def rational_matrix_from_rational_quater 
    110110    """
    111111    cdef Py_ssize_t i, j, n=len(v)
    112112    M = MatrixSpace(QQ, n, 4)
    113     cdef Matrix_rational_dense A = M.zero_matrix()
     113    cdef Matrix_rational_dense A = M.zero_matrix().__copy__()
    114114    if n == 0: return A
    115115
    116116    cdef QuaternionAlgebraElement_rational_field x
  • sage/combinat/iet/labelled.py

    diff --git a/sage/combinat/iet/labelled.py b/sage/combinat/iet/labelled.py
    a b class LabelledPermutation(SageObject): 
    533533        winner_letter = self._intervals[winner][side]
    534534        loser_letter = self._intervals[1-winner][side]
    535535
    536         m = identity_matrix(len(self))
     536        m = copy(identity_matrix(len(self)))
    537537        m[winner_letter, loser_letter] = 1
    538538
    539539        return m
  • sage/combinat/sf/sfa.py

    diff --git a/sage/combinat/sf/sfa.py b/sage/combinat/sf/sfa.py
    a b from sage.misc.misc import repr_lincomb, 
    190190from sage.algebras.algebra_element import AlgebraElement
    191191import operator
    192192from functools import partial
     193from copy import copy
    193194
    194        
     195
    195196def SymmetricFunctionAlgebra(R, basis="schur"):
    196197    """
    197198    Return the free algebra over the ring `R` on `n`
    class SymmetricFunctionAlgebra_generic(C 
    839840            #substitution.  We solve a len(pn) systems of
    840841            #equations known_matrix_n*x = b_i for x, where e_i
    841842            #is the ith standard basis vector
    842             inverse = known_matrix_n.parent().zero_matrix()
     843            inverse = copy(known_matrix_n.parent().zero_matrix())
    843844
    844845            delta = lambda i: lambda j: one if i == j else zero
    845846           
    class SymmetricFunctionAlgebra_generic(C 
    866867            #substitution.  We solve a len(pn) systems of
    867868            #equations known_matrix_n*x = b_i for x, where e_i
    868869            #is the ith standard basis vector
    869             inverse = known_matrix_n.parent().zero_matrix()
     870            inverse = copy(known_matrix_n.parent().zero_matrix())
    870871
    871872           
    872873            delta = lambda i: lambda j: one if i == j else zero
  • sage/libs/cremona/mat.pyx

    diff --git a/sage/libs/cremona/mat.pyx b/sage/libs/cremona/mat.pyx
    a b cdef class Matrix: 
    213213
    214214        # Ugly code...
    215215        if sparse:
    216             Ts = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix()
     216            Ts = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix().__copy__()
    217217            k = 0
    218218            for i from 0 <= i < n:
    219219                for j from 0 <= j < n:
    cdef class Matrix: 
    222222                    k += 1
    223223            return Ts
    224224        else:
    225             Td = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix()
     225            Td = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix().__copy__()
    226226            k = 0
    227227            for i from 0 <= i < n:
    228228                for j from 0 <= j < n:
  • sage/misc/sageinspect.py

    diff --git a/sage/misc/sageinspect.py b/sage/misc/sageinspect.py
    a b def sage_getsourcelines(obj, is_binary=F 
    575575
    576576        sage: from sage.misc.sageinspect import sage_getsourcelines
    577577        sage: sage_getsourcelines(matrix, True)[1]
    578         33
     578        34
    579579        sage: sage_getsourcelines(matrix, False)[0][0][4:]
    580580        'matrix(*args, **kwds):\n'
    581581
  • sage/modular/abvar/abvar.py

    diff --git a/sage/modular/abvar/abvar.py b/sage/modular/abvar/abvar.py
    a b from sage.groups.all import A 
    4545from sage.databases.cremona     import cremona_letter_code
    4646from sage.misc.misc             import prod
    4747
     48from copy import copy
     49
    4850import homology
    4951import homspace
    5052import lseries
    def modsym_lattices(M, factors): 
    46724674    X, _ = X._clear_denom()
    46734675    for i, R in enumerate(rows):
    46744676        A = X.matrix_from_rows(R)
    4675         A = A.saturation()
     4677        A = copy(A.saturation())
    46764678        A.echelonize()
    46774679        D.append(tuple(list(factors[i]) + [A.row_module()]))
    46784680    return Sequence(D, cr=True)
  • sage/modular/abvar/homspace.py

    diff --git a/sage/modular/abvar/homspace.py b/sage/modular/abvar/homspace.py
    a b AUTHORS: 
    171171#                  http://www.gnu.org/licenses/                           #
    172172###########################################################################
    173173
     174from copy import copy
     175
    174176from sage.categories.homset import HomsetWithBase
    175177from sage.misc.functional import parent
    176178
    class Homspace(HomsetWithBase): 
    559561                        hom_gens = Asimples[i].Hom(Bsimples[j]).gens()
    560562                        for sub_gen in hom_gens:
    561563                            sub_mat = sub_gen.matrix()
    562                             M = self.matrix_space()(0)
     564                            M = copy(self.matrix_space().zero_matrix())
    563565                            M.set_block(sub_mat.nrows()*i, sub_mat.ncols()*j, sub_mat)
    564566                            gens.append(phi_matrix * M * psi_t_matrix)
    565567
    class Homspace(HomsetWithBase): 
    577579                    if Asimple.newform_label() == Bsimple.newform_label():
    578580                        for sub_gen in Afactor.Hom(Bfactor).gens():
    579581                            sub_mat = sub_gen.matrix()
    580                             M = self.matrix_space()(0)
     582                            M = copy(self.matrix_space().zero_matrix())
    581583                            M.set_block(cur_row - sub_mat.nrows(),
    582584                                        cur_col - sub_mat.ncols(),
    583585                                        sub_mat)
  • sage/modular/modform/half_integral.py

    diff --git a/sage/modular/modform/half_integral.py b/sage/modular/modform/half_integral.py
    a b from sage.modular.dirichlet import Diric 
    1414import constructor
    1515
    1616from theta import theta2_qexp, theta_qexp
    17 
     17from copy import copy
    1818
    1919def half_integral_weight_modform_basis(chi, k, prec):
    2020    r"""
    def half_integral_weight_modform_basis(c 
    142142    T3  = theta_qexp(prec)
    143143    n   = len(S)
    144144    MS  = MatrixSpace(M.base_ring(), 2*n, prec)
    145     A   = MS.zero_matrix()
     145    A   = copy(MS.zero_matrix())
    146146   
    147147    for i in range(n):
    148148        T2f = T2*S[i]
  • sage/modular/quatalg/brandt.py

    diff --git a/sage/modular/quatalg/brandt.py b/sage/modular/quatalg/brandt.py
    a b from sage.misc.mrange import cartesian_p 
    229229
    230230from sage.misc.cachefunc import cached_method
    231231
     232from copy import copy
     233
    232234cache = {}
    233235
    234236def BrandtModule(N, M=1, weight=2, base_ring=QQ, use_cache=True):
    class BrandtModule_class(AmbientHeckeMod 
    955957        if B is None:
    956958            B = self.dimension() // 2 + 5
    957959
    958         T = matrix(self.base_ring(), self.dimension(), sparse=sparse)
     960        T = copy(matrix(self.base_ring(), self.dimension(), sparse=sparse))
    959961        C = self.right_ideals()
    960962        theta_dict = self._theta_dict(B)
    961963        # I think the runtime of this algorithm is now dominated by
    class BrandtModule_class(AmbientHeckeMod 
    10791081            B = self._brandt_series_vectors(2*n+10) 
    10801082        m = len(B)
    10811083        K = self.base_ring()
    1082         Bmat = matrix(K, m, m, sparse=sparse)
     1084        Bmat = copy(matrix(K, m, m, sparse=sparse))
    10831085        for i in range(m):
    10841086            for j in range(m):
    10851087                Bmat[i,j] = K(B[j][i][n])
  • sage/schemes/elliptic_curves/ell_rational_field.py

    diff --git a/sage/schemes/elliptic_curves/ell_rational_field.py b/sage/schemes/elliptic_curves/ell_rational_field.py
    a b Z = IntegerRing() 
    111111IR = rings.RealIntervalField(20)
    112112
    113113from sage.misc.cachefunc import cached_method
     114from copy import copy
    114115
    115116_MAX_HEIGHT=21
    116117
    class EllipticCurve_rational_field(Ellip 
    62116212        while break_cond < 0.9: #as long as the improvement of the new bound in comparison to the old is greater than 10%
    62126213            c = R((H_q**n)*10)  #c has to be greater than H_q^n
    62136214            M = matrix.MatrixSpace(Z,n)
    6214             m = M.identity_matrix()
     6215            m = copy(M.identity_matrix())
    62156216            for i in range(r):
    62166217                m[i, r] = R(c*mw_base_log[i]).round()
    62176218            m[r,r] = max(Z(1),R(c*w1).round()) #ensures that m isn't singular
    class EllipticCurve_rational_field(Ellip 
    64986499            """
    64996500            indexp = S.index(p)
    65006501            pc = Z(p**(R(c.log()/log(p,e)).ceil()))
    6501             m = M.identity_matrix()
     6502            m = copy(M.identity_matrix())
    65026503            for i in range(r):
    65036504                try:
    65046505                    m[i, r] = Z((beta[indexp][i])%pc)
    class EllipticCurve_rational_field(Ellip 
    68476848         #reduction at infinity
    68486849            bound_list=[]
    68496850            c = R((H_q**n)*100)
    6850             m = M.identity_matrix()
     6851            m = copy(M.identity_matrix())
    68516852            for i in range(r):
    68526853                m[i, r] = R(c*mw_base_log[i]).round()
    68536854            m[r,r] = max(Z(1), R(c*w1).round())