Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with GF.Elements() with dtype=object #186

Closed
mhostetter opened this issue Oct 18, 2021 · 1 comment
Closed

Error with GF.Elements() with dtype=object #186

mhostetter opened this issue Oct 18, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@mhostetter
Copy link
Owner

As discovered in #185, calling GF.Elements() (or GF.Range()) on a "large" finite field, with dtype=object, results in an error. While GF.Elements() wouldn't want to be called on such a large field, GF.Range() might.

In [1]: import galois                                                                                                                        

In [2]: GF = galois.GF(2**100)                                                                                                               

In [3]: GF.Elements()                                                                                                                        
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-d052cf0ab5c9> in <module>
----> 1 GF.Elements()

~/repos/galois/galois/_fields/_array.py in Elements(cls, dtype)
    451             GF.display();
    452         """
--> 453         return cls.Range(0, cls.order, step=1, dtype=dtype)
    454 
    455     @classmethod

~/repos/galois/galois/_fields/_array.py in Range(cls, start, stop, step, dtype)
    365             array = np.array(range(start, stop, step), dtype=dtype)
    366 
--> 367         return array.view(cls)
    368 
    369     @classmethod

~/repos/galois/galois/_fields/_array.py in __array_finalize__(self, obj)
   1009             if obj.dtype not in type(self).dtypes:
   1010                 raise TypeError(f"{type(self).name} can only have integer dtypes {type(self).dtypes}, not {obj.dtype}.")
-> 1011             self._check_array_values(obj)
   1012 
   1013     def __getitem__(self, key):

~/repos/galois/galois/_fields/_array.py in _check_array_values(cls, array)
    252 
    253         # Check the value of the "field elements" and make sure they are valid
--> 254         if np.any(array < 0) or np.any(array >= cls.order):
    255             idxs = np.logical_or(array < 0, array >= cls.order)
    256             values = array if array.ndim == 0 else array[idxs]

TypeError: '<' not supported between instances of 'range' and 'int'
@mhostetter mhostetter added the bug Something isn't working label Oct 18, 2021
@mhostetter mhostetter self-assigned this Oct 18, 2021
mhostetter added a commit that referenced this issue Oct 19, 2021
@mhostetter
Copy link
Owner Author

After #189, the above returns this, which is expected. It doesn't error where it did before. Instead, it complains that it doesn't have enough RAM, which it doesn't.

In [1]: import galois                                                                                                                                                                      

In [2]: GF = galois.GF(2**100)                                                                                                                                                             

In [3]: GF.Elements()                                                                                                                                                                      
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-d052cf0ab5c9> in <module>
----> 1 GF.Elements()

~/repos/galois/galois/_fields/_array.py in Elements(cls, dtype)
    446             GF.display();
    447         """
--> 448         return cls.Range(0, cls.order, step=1, dtype=dtype)
    449 
    450     @classmethod

~/repos/galois/galois/_fields/_array.py in Range(cls, start, stop, step, dtype)
    359             raise ValueError(f"The stopping value must be less than the field order of {cls.order}, not {stop}.")
    360         dtype = cls._get_dtype(dtype)
--> 361         array = np.arange(start, stop, step=step, dtype=dtype)
    362         return array.view(cls)
    363 

ValueError: Maximum allowed size exceeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant