def __classcall_private__(cls, base_ring, dispatch=True): r""" Implement the dispatching of ``Modules(field)`` to ``VectorSpaces(field)``. This feature will later be extended, probably as a covariant functorial construction, to support modules over various kinds of rings (principal ideal domains, ...), or even over semirings. TESTS:: sage: C = Modules(ZZ); C Category of modules over Integer Ring sage: C is Modules(ZZ, dispatch = False) True sage: C is Modules(ZZ, dispatch = True) True sage: C._reduction (<class 'sage.categories.modules.Modules'>, (Integer Ring,), {'dispatch': False}) sage: TestSuite(C).run() sage: Modules(QQ) is VectorSpaces(QQ) True sage: Modules(QQ, dispatch = True) is VectorSpaces(QQ) True sage: C = Modules(NonNegativeIntegers()); C # todo: not implemented Category of semiring modules over Non negative integers sage: C = Modules(QQ, dispatch = False); C Category of modules over Rational Field sage: C._reduction (<class 'sage.categories.modules.Modules'>, (Rational Field,), {'dispatch': False}) sage: TestSuite(C).run() """ if dispatch: if base_ring in _Fields or (isinstance(base_ring, Category) and base_ring.is_subcategory(_Fields)): from vector_spaces import VectorSpaces return VectorSpaces(base_ring, check=False) result = super(Modules, cls).__classcall__(cls, base_ring) result._reduction[2]['dispatch'] = False return result
def __classcall_private__(cls, base_ring, dispatch = True): """ This method implements the default behavior of dispatching ``Modules(field)`` to ``VectorSpaces(field)``. This feature will later be extended to modules over a principal ideal domain/ring or over a semiring. TESTS:: sage: C = Modules(ZZ); C Category of modules over Integer Ring sage: C is Modules(ZZ, dispatch = False) True sage: C is Modules(ZZ, dispatch = True) True sage: C._reduction (<class 'sage.categories.modules.Modules'>, (Integer Ring,), {'dispatch': False}) sage: TestSuite(C).run() sage: Modules(QQ) is VectorSpaces(QQ) True sage: Modules(QQ, dispatch = True) is VectorSpaces(QQ) True sage: C = Modules(NonNegativeIntegers()); C # todo: not implemented Category of semiring modules over Non negative integers sage: C = Modules(QQ, dispatch = False); C Category of modules over Rational Field sage: C._reduction (<class 'sage.categories.modules.Modules'>, (Rational Field,), {'dispatch': False}) sage: TestSuite(C).run() """ if dispatch: if base_ring in _Fields: return VectorSpaces(base_ring, check=False) result = super(Modules, cls).__classcall__(cls, base_ring) result._reduction[2]['dispatch'] = False return result