Changeset 5498:dd7f96fc2561


Ignore:
Timestamp:
07/24/07 11:21:37 (6 years ago)
Author:
Robert Bradshaw <robertwb@…>
Branch:
default
Children:
5499:66c89ee30e12, 5858:90c27feeca40
Message:

fix obscure pyrex errors

Location:
sage
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sage/modules/free_module_element.pyx

    r5489 r5498  
    489489     
    490490    cdef ModuleElement _rmul_nonscalar_c_impl(left, right): 
    491          raise TypeError 
     491        raise TypeError 
    492492 
    493493    def degree(self): 
  • sage/schemes/generic/morphism.py

    r4853 r5498  
    1414#***************************************************************************** 
    1515 
    16 from sage.structure.element   import AdditiveGroupElement, RingElement 
     16from sage.structure.element   import AdditiveGroupElement, RingElement, Element 
    1717from sage.structure.sequence  import Sequence 
    1818 
    1919from sage.categories.morphism import Morphism 
     20from sage.categories.homset   import Homset 
    2021 
    2122from sage.rings.all           import is_RingHomomorphism, is_CommutativeRing, Integer 
     
    3132    return isinstance(f, (SchemeMorphism, EllipticCurvePoint_field)); 
    3233 
    33 class SchemeMorphism(Morphism): 
     34 
     35class PyMorphism(Element): 
     36    # Double inheritance from both Morphism and AdditiveGroupElement seems to mess up the ModuleElement pyrex vtab, which is really bad! 
     37    def __init__(self, parent): 
     38        if not isinstance(parent, Homset): 
     39            raise TypeError, "parent (=%s) must be a Homspace"%parent 
     40        Element.__init__(self, parent) 
     41        self._domain = parent.domain() 
     42        self._codomain = parent.codomain() 
     43 
     44    def _repr_type(self): 
     45        return "Generic" 
     46 
     47    def _repr_defn(self): 
     48        return "" 
     49 
     50    def _repr_(self): 
     51        if self.is_endomorphism(): 
     52            s = "%s endomorphism of %s"%(self._repr_type(), self.domain()) 
     53        else: 
     54            s = "%s morphism:"%self._repr_type() 
     55            s += "\n  From: %s"%self.domain() 
     56            s += "\n  To:   %s"%self.codomain() 
     57        d = self._repr_defn() 
     58        if d != '': 
     59            s += "\n  Defn: %s"%('\n        '.join(self._repr_defn().split('\n'))) 
     60        return s 
     61         
     62    def domain(self): 
     63        return self._domain 
     64         
     65    def codomain(self): 
     66        return self.parent().codomain() 
     67 
     68    def category(self): 
     69        return self.parent().category() 
     70 
     71    def is_endomorphism(self): 
     72        return self.parent().is_endomorphism_set() 
     73 
     74    def _composition_(self, right, homset): 
     75        return FormalCompositeMorphism(homset, right, self) 
     76 
     77    def __pow__(self, n, dummy): 
     78        if not self.is_endomorphism(): 
     79            raise TypeError, "self must be an endomorphism." 
     80        # todo -- what about the case n=0 -- need to specify the identity map somehow. 
     81        import sage.rings.arith as arith 
     82        return arith.generic_power(self, n) 
     83 
     84 
     85 
     86class SchemeMorphism(PyMorphism): 
    3487    """ 
    3588    A scheme morphism 
    3689    """ 
    3790    def __init__(self, parent): 
    38         Morphism.__init__(self, parent) 
     91        PyMorphism.__init__(self, parent) 
    3992 
    4093    def _repr_type(self): 
     
    149202    """ 
    150203    def __init__(self, parent, phi, check=True): 
    151         Morphism.__init__(self, parent) 
     204        SchemeMorphism.__init__(self, parent) 
    152205        if check: 
    153206            if not is_RingHomomorphism(phi): 
     
    159212                raise TypeError, "phi (=%s) must have codomain %s"%(phi, 
    160213                                                 parent.domain().coordinate_ring()) 
    161         self.__ring_homomorphism = phi 
     214        self.__ring_homomorphism = phi 
    162215 
    163216    def __call__(self, P): 
  • sage/structure/coerce.pxi

    r5465 r5497  
    3838    if PY_TYPE_CHECK(x,Element): 
    3939        return (<Element>x)._parent 
    40     try: 
    41         # TODO: should the _parent attribute be moved up the tree? 
     40    elif hasattr(x, 'parent'): 
    4241        return x.parent() 
    43     except AttributeError: 
     42    else: 
    4443        return <object>PY_TYPE(x) 
    4544 
Note: See TracChangeset for help on using the changeset viewer.