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

Commit 96e133e

Browse files
committed
Improve __cinit__ and add doctests
1 parent 6e10798 commit 96e133e

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/sage/numerical/linear_functions.pxd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ cdef class LinearFunctionOrConstraint(ModuleElement):
99
cdef class LinearFunctionsParent_class(Parent):
1010
cpdef _element_constructor_(self, x)
1111
cpdef _coerce_map_from_(self, R)
12-
cdef object _multiplication_symbol
13-
cpdef object _get_multiplication_symbol(self)
12+
cdef public _multiplication_symbol
1413

1514
cdef class LinearFunction(LinearFunctionOrConstraint):
1615
cdef dict _f

src/sage/numerical/linear_functions.pyx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,19 @@ cdef class LinearFunctionsParent_class(Parent):
523523
<type 'sage.numerical.linear_functions.LinearFunctionsParent_class'>
524524
"""
525525
def __cinit__(self):
526+
"""
527+
Cython initializer
528+
529+
TESTS::
530+
531+
sage: from sage.numerical.linear_functions import LinearFunctionsParent_class
532+
sage: LF = LinearFunctionsParent_class.__new__(LinearFunctionsParent_class)
533+
sage: LF._multiplication_symbol
534+
'*'
535+
"""
526536
# Do not use coercion framework for __richcmp__
527537
self.flags |= Parent_richcmp_element_without_coercion
538+
self._multiplication_symbol = '*'
528539

529540
def __init__(self, base_ring):
530541
"""
@@ -538,7 +549,6 @@ cdef class LinearFunctionsParent_class(Parent):
538549
"""
539550
from sage.categories.modules_with_basis import ModulesWithBasis
540551
Parent.__init__(self, base=base_ring, category=ModulesWithBasis(base_ring))
541-
self._multiplication_symbol = '*'
542552

543553
def set_multiplication_symbol(self, symbol='*'):
544554
"""
@@ -568,7 +578,7 @@ cdef class LinearFunctionsParent_class(Parent):
568578
"""
569579
self._multiplication_symbol = symbol
570580

571-
cpdef _get_multiplication_symbol(self):
581+
def _get_multiplication_symbol(self):
572582
"""
573583
Return the multiplication symbol.
574584
@@ -1074,7 +1084,7 @@ cdef class LinearFunction(LinearFunctionOrConstraint):
10741084
if constant_term:
10751085
return str(coeff)
10761086
else:
1077-
return str(coeff) + self.parent()._get_multiplication_symbol()
1087+
return str(coeff) + self.parent()._multiplication_symbol
10781088

10791089
def _repr_(self):
10801090
r"""
@@ -1187,7 +1197,23 @@ cdef class LinearConstraintsParent_class(Parent):
11871197
sage: LinearConstraintsParent(p.linear_functions_parent()) is LC
11881198
True
11891199
"""
1190-
def __cinit__(self):
1200+
def __cinit__(self, linear_functions_parent):
1201+
"""
1202+
Cython initializer
1203+
1204+
TESTS::
1205+
1206+
sage: from sage.numerical.linear_functions import LinearConstraintsParent_class
1207+
sage: from sage.numerical.linear_functions import LinearFunctionsParent
1208+
sage: LF = LinearFunctionsParent(RDF)
1209+
sage: LinearConstraintsParent_class.__new__(LinearConstraintsParent_class, LF)
1210+
Linear constraints over Real Double Field
1211+
sage: LinearConstraintsParent_class.__new__(LinearConstraintsParent_class, None)
1212+
Traceback (most recent call last):
1213+
...
1214+
TypeError: Cannot convert NoneType to sage.numerical.linear_functions.LinearFunctionsParent_class
1215+
"""
1216+
self._LF = <LinearFunctionsParent_class?>linear_functions_parent
11911217
# Do not use coercion framework for __richcmp__
11921218
self.flags |= Parent_richcmp_element_without_coercion
11931219

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

12171242
def linear_functions_parent(self):
12181243
"""

0 commit comments

Comments
 (0)