Ask Your Question
1

I try to make a class derived from IntegerMod_abstract but simply calling the super().__init__ already fails.

asked 2024-11-29 09:33:04 +0100

Jan Peeters gravatar image

updated 2024-11-30 11:12:52 +0100

eric_g gravatar image

I don't know where to start. See the example code. Even when i implement set_from_mpz i get the same error.

from sage.rings.finite_rings.integer_mod import IntegerMod_abstract

class IntegerMod_centered(IntegerMod_abstract):
    def __init__(self, parent, value):
        super().__init__(parent, value)

R=Zmod(10)
IntegerMod_centered(R,5)

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
NotImplementedError: must be defined in child class
Exception ignored in: 'sage.rings.finite_rings.integer_mod.IntegerMod_abstract.set_from_mpz'
Traceback (most recent call last):
  File "<string>", line 5, in __init__
NotImplementedError: must be defined in child class
<repr(<__main__.IntegerMod_centered at 0x7f5caf4ad7c0>) failed: RecursionError: maximum recursion depth exceeded>
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2024-12-01 03:40:28 +0100

You need to define the method set_from_mpz in your new class: the __init__ method for IntegerMod_abstract calls it, but it's not defined in IntegerMod_abstract — it's defined separately in each class that inherits from that one. This is what the error message

Exception ignored in: 'sage.rings.finite_rings.integer_mod.IntegerMod_abstract.set_from_mpz'
Traceback (most recent call last):
  File "<string>", line 5, in __init__
NotImplementedError: must be defined in child class

means.

(I am not a Cython expert, so there may be other requirements in addition when trying to base a class on a Cython class.)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-11-29 09:33:04 +0100

Seen: 68 times

Last updated: Dec 01