How to calculate numpy arrays on galois field?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 07:25:16

The problem is that Python doesn't know how to index tuples when x is a GF4 object. You could do something like this to solve that:

def __add__(self, x):
    if isinstance(x, GF4):
        x = x.number
    return self.__addL__[self.number][x]

There is another potential issue you may want to look at, that explains why your third test case works: when you add an int to a GF4 what gets returned is an int, not a GF4. Unless this is a desired behavior, I think your code for __add__ should be more like:

def __add__(self, x):
    if isinstance(x, GF4):
        x = x.number
    return GF4(self.__addL__[self.number][x])

You may want to think over all the possibilities and decide if youneed to build more safeguards and throw a few errors of your own, e.g. what should be the return if you try to add a float to a GF4?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!