Ticket #11599: trac_11599_numerical_noise.patch

File trac_11599_numerical_noise.patch, 1.5 KB (added by vbraun, 10 years ago)

Initial patch

  • sage/schemes/generic/morphism.py

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1331058395 28800
    # Node ID 702a84e3b6f515d95aca3ee6fd97747e65010e1e
    # Parent  691a04c3291df0ee408f13ede76301a61417d43b
    Trac #11599: Toric morphisms
    
    Fixes for numerical noise on some platforms
    
    diff --git a/sage/schemes/generic/morphism.py b/sage/schemes/generic/morphism.py
    a b  
    13071307            if len(v) != d and len(v) != d-1:
    13081308                raise TypeError, "v (=%s) must have %s components"%(v, d)
    13091309            #v = Sequence(v, X.base_ring())
    1310             v = Sequence(v, X.value_ring())
     1310            R = X.value_ring()
     1311            v = Sequence(v, R)
    13111312            if len(v) == d-1:     # very common special case
    13121313                v.append(1)
    13131314           
    13141315            n = len(v)
    13151316            all_zero = True
    13161317            for i in range(n):
    1317                 if v[n-1-i]:
     1318                last = n-1-i
     1319                if v[last]:
    13181320                    all_zero = False
    1319                     c = v[n-1-i]
    1320                     if c == 1:
     1321                    c = v[last]
     1322                    if c == R.one():
    13211323                        break
    1322                     for j in range(n-i):
     1324                    for j in range(last):
    13231325                        v[j] /= c
     1326                    v[last] = R.one()
    13241327                    break
    13251328            if all_zero:
    13261329                raise ValueError, "%s does not define a valid point since all entries are 0"%repr(v)