# Ticket #8276: trac_8276-fix_sagelib-fh.2.patch

File trac_8276-fix_sagelib-fh.2.patch, 9.3 KB (added by hivert, 11 years ago)
• ## sage/algebras/quatalg/quaternion_algebra_cython.pyx

```# HG changeset patch
# User Florent Hivert <Florent.Hivert@univ-rouen.fr>
# Date 1266364350 -3600
# Node ID 33fe668b345f4ec181a543f9cd9ec08e05b146ee
# Parent  a65a1e2fe596020b3406d8ea8dfcca5901bfe8f3
#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 def integral_matrix_and_denom_from_ratio cdef Py_ssize_t i, n=len(v) M = MatrixSpace(ZZ, n, 4) cdef Matrix_integer_dense A = M.zero_matrix() cdef Matrix_integer_dense A = M.zero_matrix().__copy__() if n == 0: return A # Find least common multiple of the denominators def rational_matrix_from_rational_quater """ cdef Py_ssize_t i, j, n=len(v) M = MatrixSpace(QQ, n, 4) cdef Matrix_rational_dense A = M.zero_matrix() cdef Matrix_rational_dense A = M.zero_matrix().__copy__() if n == 0: return A 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 class LabelledPermutation(SageObject): winner_letter = self._intervals[winner][side] loser_letter = self._intervals[1-winner][side] m = identity_matrix(len(self)) m = copy(identity_matrix(len(self))) m[winner_letter, loser_letter] = 1 return m
• ## sage/combinat/sf/sfa.py

`diff --git a/sage/combinat/sf/sfa.py b/sage/combinat/sf/sfa.py`
 a from sage.misc.misc import repr_lincomb, from sage.algebras.algebra_element import AlgebraElement import operator from functools import partial from copy import copy def SymmetricFunctionAlgebra(R, basis="schur"): """ Return the free algebra over the ring `R` on `n` class SymmetricFunctionAlgebra_generic(C #substitution.  We solve a len(pn) systems of #equations known_matrix_n*x = b_i for x, where e_i #is the ith standard basis vector inverse = known_matrix_n.parent().zero_matrix() inverse = copy(known_matrix_n.parent().zero_matrix()) delta = lambda i: lambda j: one if i == j else zero class SymmetricFunctionAlgebra_generic(C #substitution.  We solve a len(pn) systems of #equations known_matrix_n*x = b_i for x, where e_i #is the ith standard basis vector inverse = known_matrix_n.parent().zero_matrix() inverse = copy(known_matrix_n.parent().zero_matrix()) 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 cdef class Matrix: # Ugly code... if sparse: Ts = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix() Ts = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix().__copy__() k = 0 for i from 0 <= i < n: for j from 0 <= j < n: cdef class Matrix: k += 1 return Ts else: Td = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix() Td = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix().__copy__() k = 0 for i from 0 <= i < n: for j from 0 <= j < n:
• ## sage/modular/abvar/abvar.py

`diff --git a/sage/modular/abvar/abvar.py b/sage/modular/abvar/abvar.py`
 a from sage.groups.all import A from sage.databases.cremona     import cremona_letter_code from sage.misc.misc             import prod from copy import copy import homology import homspace import lseries def modsym_lattices(M, factors): X, _ = X._clear_denom() for i, R in enumerate(rows): A = X.matrix_from_rows(R) A = A.saturation() A = copy(A.saturation()) A.echelonize() D.append(tuple(list(factors[i]) + [A.row_module()])) 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 AUTHORS: #                  http://www.gnu.org/licenses/                           # ########################################################################### from copy import copy from sage.categories.homset import HomsetWithBase from sage.misc.functional import parent class Homspace(HomsetWithBase): hom_gens = Asimples[i].Hom(Bsimples[j]).gens() for sub_gen in hom_gens: sub_mat = sub_gen.matrix() M = self.matrix_space()(0) M = copy(self.matrix_space().zero_matrix()) M.set_block(sub_mat.nrows()*i, sub_mat.ncols()*j, sub_mat) gens.append(phi_matrix * M * psi_t_matrix) class Homspace(HomsetWithBase): if Asimple.newform_label() == Bsimple.newform_label(): for sub_gen in Afactor.Hom(Bfactor).gens(): sub_mat = sub_gen.matrix() M = self.matrix_space()(0) M = copy(self.matrix_space().zero_matrix()) M.set_block(cur_row - sub_mat.nrows(), cur_col - sub_mat.ncols(), 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 from sage.modular.dirichlet import Diric import constructor from theta import theta2_qexp, theta_qexp from copy import copy def half_integral_weight_modform_basis(chi, k, prec): r""" def half_integral_weight_modform_basis(c T3  = theta_qexp(prec) n   = len(S) MS  = MatrixSpace(M.base_ring(), 2*n, prec) A   = MS.zero_matrix() A   = copy(MS.zero_matrix()) for i in range(n): T2f = T2*S[i]
• ## sage/modular/quatalg/brandt.py

`diff --git a/sage/modular/quatalg/brandt.py b/sage/modular/quatalg/brandt.py`
 a from sage.misc.mrange import cartesian_p from sage.misc.cachefunc import cached_method from copy import copy cache = {} def BrandtModule(N, M=1, weight=2, base_ring=QQ, use_cache=True): class BrandtModule_class(AmbientHeckeMod if B is None: B = self.dimension() // 2 + 5 T = matrix(self.base_ring(), self.dimension(), sparse=sparse) T = copy(matrix(self.base_ring(), self.dimension(), sparse=sparse)) C = self.right_ideals() theta_dict = self._theta_dict(B) # I think the runtime of this algorithm is now dominated by class BrandtModule_class(AmbientHeckeMod B = self._brandt_series_vectors(2*n+10) m = len(B) K = self.base_ring() Bmat = matrix(K, m, m, sparse=sparse) Bmat = copy(matrix(K, m, m, sparse=sparse)) for i in range(m): for j in range(m): 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 Z = IntegerRing() IR = rings.RealIntervalField(20) from sage.misc.cachefunc import cached_method from copy import copy _MAX_HEIGHT=21 class EllipticCurve_rational_field(Ellip while break_cond < 0.9: #as long as the improvement of the new bound in comparison to the old is greater than 10% c = R((H_q**n)*10)  #c has to be greater than H_q^n M = matrix.MatrixSpace(Z,n) m = M.identity_matrix() m = copy(M.identity_matrix()) for i in range(r): m[i, r] = R(c*mw_base_log[i]).round() m[r,r] = max(Z(1),R(c*w1).round()) #ensures that m isn't singular class EllipticCurve_rational_field(Ellip """ indexp = S.index(p) pc = Z(p**(R(c.log()/log(p,e)).ceil())) m = M.identity_matrix() m = copy(M.identity_matrix()) for i in range(r): try: m[i, r] = Z((beta[indexp][i])%pc) class EllipticCurve_rational_field(Ellip #reduction at infinity bound_list=[] c = R((H_q**n)*100) m = M.identity_matrix() m = copy(M.identity_matrix()) for i in range(r): m[i, r] = R(c*mw_base_log[i]).round() m[r,r] = max(Z(1), R(c*w1).round())