Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Improve __cinit__ and add doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Apr 25, 2016
1 parent 6e10798 commit 96e133e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/sage/numerical/linear_functions.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ cdef class LinearFunctionOrConstraint(ModuleElement):
cdef class LinearFunctionsParent_class(Parent):
cpdef _element_constructor_(self, x)
cpdef _coerce_map_from_(self, R)
cdef object _multiplication_symbol
cpdef object _get_multiplication_symbol(self)
cdef public _multiplication_symbol

cdef class LinearFunction(LinearFunctionOrConstraint):
cdef dict _f
Expand Down
35 changes: 30 additions & 5 deletions src/sage/numerical/linear_functions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,19 @@ cdef class LinearFunctionsParent_class(Parent):
<type 'sage.numerical.linear_functions.LinearFunctionsParent_class'>
"""
def __cinit__(self):
"""
Cython initializer
TESTS::
sage: from sage.numerical.linear_functions import LinearFunctionsParent_class
sage: LF = LinearFunctionsParent_class.__new__(LinearFunctionsParent_class)
sage: LF._multiplication_symbol
'*'
"""
# Do not use coercion framework for __richcmp__
self.flags |= Parent_richcmp_element_without_coercion
self._multiplication_symbol = '*'

def __init__(self, base_ring):
"""
Expand All @@ -538,7 +549,6 @@ cdef class LinearFunctionsParent_class(Parent):
"""
from sage.categories.modules_with_basis import ModulesWithBasis
Parent.__init__(self, base=base_ring, category=ModulesWithBasis(base_ring))
self._multiplication_symbol = '*'

def set_multiplication_symbol(self, symbol='*'):
"""
Expand Down Expand Up @@ -568,7 +578,7 @@ cdef class LinearFunctionsParent_class(Parent):
"""
self._multiplication_symbol = symbol

cpdef _get_multiplication_symbol(self):
def _get_multiplication_symbol(self):
"""
Return the multiplication symbol.
Expand Down Expand Up @@ -1074,7 +1084,7 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
if constant_term:
return str(coeff)
else:
return str(coeff) + self.parent()._get_multiplication_symbol()
return str(coeff) + self.parent()._multiplication_symbol

def _repr_(self):
r"""
Expand Down Expand Up @@ -1187,7 +1197,23 @@ cdef class LinearConstraintsParent_class(Parent):
sage: LinearConstraintsParent(p.linear_functions_parent()) is LC
True
"""
def __cinit__(self):
def __cinit__(self, linear_functions_parent):
"""
Cython initializer
TESTS::
sage: from sage.numerical.linear_functions import LinearConstraintsParent_class
sage: from sage.numerical.linear_functions import LinearFunctionsParent
sage: LF = LinearFunctionsParent(RDF)
sage: LinearConstraintsParent_class.__new__(LinearConstraintsParent_class, LF)
Linear constraints over Real Double Field
sage: LinearConstraintsParent_class.__new__(LinearConstraintsParent_class, None)
Traceback (most recent call last):
...
TypeError: Cannot convert NoneType to sage.numerical.linear_functions.LinearFunctionsParent_class
"""
self._LF = <LinearFunctionsParent_class?>linear_functions_parent
# Do not use coercion framework for __richcmp__
self.flags |= Parent_richcmp_element_without_coercion

Expand All @@ -1212,7 +1238,6 @@ cdef class LinearConstraintsParent_class(Parent):
TypeError: Cannot convert NoneType to sage.numerical.linear_functions.LinearFunctionsParent_class
"""
Parent.__init__(self)
self._LF = <LinearFunctionsParent_class?>linear_functions_parent

def linear_functions_parent(self):
"""
Expand Down

0 comments on commit 96e133e

Please sign in to comment.