Skip to content

Commit 91d04f4

Browse files
author
Matthias Koeppe
committed
Revert "Make FiniteFamily a Python subclass of FiniteFamily_base - so that EnumeratedSets mixins work correctly"
This reverts commit 450f9c6.
1 parent 4ef3f8f commit 91d04f4

File tree

4 files changed

+46
-51
lines changed

4 files changed

+46
-51
lines changed

src/sage/numerical/mip.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cdef extern from *:
33
cdef int REAL = -1
44
cdef int INTEGER = 0
55

6-
from sage.sets.family cimport FiniteFamily_base
6+
from sage.sets.family cimport FiniteFamily
77
from sage.structure.sage_object cimport SageObject
88
from sage.numerical.backends.generic_backend cimport GenericBackend
99

@@ -29,7 +29,7 @@ cdef class MixedIntegerLinearProgram(SageObject):
2929
cpdef sum(self, L) noexcept
3030

3131

32-
cdef class MIPVariable(FiniteFamily_base):
32+
cdef class MIPVariable(FiniteFamily):
3333
cdef MixedIntegerLinearProgram _p
3434
cdef int _vtype
3535
cdef str _name

src/sage/numerical/mip.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3237,7 +3237,7 @@ class MIPSolverException(RuntimeError):
32373237
pass
32383238

32393239

3240-
cdef class MIPVariable(FiniteFamily_base):
3240+
cdef class MIPVariable(FiniteFamily):
32413241
r"""
32423242
``MIPVariable`` is a variable used by the class
32433243
``MixedIntegerLinearProgram``.

src/sage/sets/family.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ cdef class AbstractFamily(Parent):
55
cdef public __custom_name
66

77

8-
cdef class FiniteFamily_base(AbstractFamily):
8+
cdef class FiniteFamily(AbstractFamily):
99
cdef public dict _dictionary
1010
cdef public object _keys

src/sage/sets/family.pyx

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,48 @@ cdef class AbstractFamily(Parent):
540540
541541
542542
543-
cdef class FiniteFamily_base(AbstractFamily):
543+
cdef class FiniteFamily(AbstractFamily):
544544
r"""
545-
Cython base class for :class:`FiniteFamily`.
545+
A :class:`FiniteFamily` is an associative container which models a finite
546+
family `(f_i)_{i \in I}`. Its elements `f_i` are therefore its
547+
values. Instances should be created via the :func:`Family` factory. See its
548+
documentation for examples and tests.
549+
550+
EXAMPLES:
551+
552+
We define the family `(f_i)_{i \in \{3,4,7\}}` with `f_3=a`,
553+
`f_4=b`, and `f_7=d`::
554+
555+
sage: from sage.sets.family import FiniteFamily
556+
sage: f = FiniteFamily({3: 'a', 4: 'b', 7: 'd'})
557+
558+
Individual elements are accessible as in a usual dictionary::
559+
560+
sage: f[7]
561+
'd'
562+
563+
And the other usual dictionary operations are also available::
564+
565+
sage: len(f)
566+
3
567+
sage: f.keys()
568+
[3, 4, 7]
569+
570+
However f behaves as a container for the `f_i`'s::
571+
572+
sage: list(f)
573+
['a', 'b', 'd']
574+
sage: [ x for x in f ]
575+
['a', 'b', 'd']
576+
577+
The order of the elements can be specified using the ``keys`` optional argument::
578+
579+
sage: f = FiniteFamily({"a": "aa", "b": "bb", "c" : "cc" }, keys = ["c", "a", "b"])
580+
sage: list(f)
581+
['cc', 'aa', 'bb']
582+
546583
"""
584+
547585
def __init__(self, dictionary, keys=None):
548586
"""
549587
TESTS::
@@ -679,8 +717,8 @@ cdef class FiniteFamily_base(AbstractFamily):
679717
False
680718
"""
681719
return (isinstance(other, self.__class__) and
682-
self._keys == (<FiniteFamily_base> other)._keys and
683-
self._dictionary == (<FiniteFamily_base> other)._dictionary)
720+
self._keys == (<FiniteFamily> other)._keys and
721+
self._dictionary == (<FiniteFamily> other)._dictionary)
684722
685723
def _repr_(self):
686724
"""
@@ -796,49 +834,6 @@ cdef class FiniteFamily_base(AbstractFamily):
796834
self.__init__(state['dictionary'], keys=state.get("keys"))
797835
798836
799-
class FiniteFamily(FiniteFamily_base):
800-
r"""
801-
A :class:`FiniteFamily` is an associative container which models a finite
802-
family `(f_i)_{i \in I}`. Its elements `f_i` are therefore its
803-
values. Instances should be created via the :func:`Family` factory. See its
804-
documentation for examples and tests.
805-
806-
EXAMPLES:
807-
808-
We define the family `(f_i)_{i \in \{3,4,7\}}` with `f_3=a`,
809-
`f_4=b`, and `f_7=d`::
810-
811-
sage: from sage.sets.family import FiniteFamily
812-
sage: f = FiniteFamily({3: 'a', 4: 'b', 7: 'd'})
813-
814-
Individual elements are accessible as in a usual dictionary::
815-
816-
sage: f[7]
817-
'd'
818-
819-
And the other usual dictionary operations are also available::
820-
821-
sage: len(f)
822-
3
823-
sage: f.keys()
824-
[3, 4, 7]
825-
826-
However f behaves as a container for the `f_i`'s::
827-
828-
sage: list(f)
829-
['a', 'b', 'd']
830-
sage: [ x for x in f ]
831-
['a', 'b', 'd']
832-
833-
The order of the elements can be specified using the ``keys`` optional argument::
834-
835-
sage: f = FiniteFamily({"a": "aa", "b": "bb", "c" : "cc" }, keys = ["c", "a", "b"])
836-
sage: list(f)
837-
['cc', 'aa', 'bb']
838-
839-
"""
840-
pass
841-
842837
class FiniteFamilyWithHiddenKeys(FiniteFamily):
843838
r"""
844839
A close variant of :class:`FiniteFamily` where the family contains some

0 commit comments

Comments
 (0)