Weird! OverflowError: cannot convert float infinity to integer

908 views
Skip to first unread message

David Hoo

unread,
Jul 8, 2014, 10:21:06 AM7/8/14
to sage-s...@googlegroups.com

I happened to meet a overflow error, I install sage 6.2 both on a 64-bit macbook running MacOS 10.9 and 32-bit Dell Desktop running Ubuntu 12.04.

The error message goes like this:

OverflowError                             Traceback (most recent call last)

<ipython-input-7-8d411648858e> in <module>()

----> 1 get_ipython().magic(u'runfile DataCollecctionScript.py')

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)

   2163         magic_name, _, magic_arg_s = arg_s.partition(' ')

   2164         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)

-> 2165         return self.run_line_magic(magic_name, magic_arg_s)

   2166

   2167     #-------------------------------------------------------------------------

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)

   2084                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals

   2085             with self.builtin_trap:

-> 2086                 result = fn(*args,**kwargs)

   2087             return result

   2088

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/repl/ipython_extension.pyc in runfile(self, s)

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)

    189     # but it's overkill for just that one bit of state.

    190     def magic_deco(arg):

--> 191         call = lambda f, *a, **k: f(*a, **k)

    192

    193         if callable(arg):

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/repl/ipython_extension.pyc in runfile(self, s)

    108             2

    109         """

--> 110         return self.shell.ex(preparser.load_wrap(s, attach=False))

    111

    112     @line_magic

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in ex(self, cmd)

   2437         """Execute a normal python statement in user namespace."""

   2438         with self.builtin_trap:

-> 2439             exec cmd in self.user_global_ns, self.user_ns

   2440

   2441     def ev(self, expr):

 

<string> in <module>()

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/misc/preparser.pyc in load(filename, globals, attach)

   1757     if fpath.endswith('.py'):

   1758         exec_file_is(fpath)

-> 1759         execfile(fpath, globals)

   1760     elif fpath.endswith('.sage'):

   1761         from sage.misc.attached_files import load_attach_mode

 

/Users/David/Desktop/src/DataCollecctionScript.py in <module>()

     95

     96                 elif option == 'NiedereiterCryptosystem':

---> 97                         crypto = NiederreiterCryptosystem(n,m,irr_poly);

     98                         #Encrypt & Decrypt

     99                         #Get m*t-bits random message weighing at most t and encrypt it.

 

<string> in __init__(self, n, m, g)

 

<string> in __init__(self, n, m, g)

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/matrix/matrix0.so in sage.matrix.matrix0.Matrix.__getitem__ (sage/matrix/matrix0.c:5871)()

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/matrix/matrix_mod2e_dense.so in sage.matrix.matrix_mod2e_dense.Matrix_mod2e_dense.get_unsafe (sage/matrix/matrix_mod2e_dense.c:4199)()

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/matrix/matrix_mod2e_dense.so in sage.matrix.matrix_mod2e_dense.word_to_poly (sage/matrix/matrix_mod2e_dense.c:3090)()

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/rings/finite_rings/finite_field_ntl_gf2e.pyc in fetch_int(self, number)

    277             [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]

    278         """

--> 279         return self._cache.fetch_int(number)

    280

    281     def polynomial(self, name=None):

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/rings/finite_rings/element_ntl_gf2e.so in sage.rings.finite_rings.element_ntl_gf2e.Cache_ntl_gf2e.fetch_int (sage/rings/finite_rings/element_ntl_gf2e.cpp:6011)()

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/rings/finite_rings/element_ntl_gf2e.so in sage.rings.finite_rings.element_ntl_gf2e.Cache_ntl_gf2e.fetch_int (sage/rings/finite_rings/element_ntl_gf2e.cpp:5808)()

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/rings/real_double.so in sage.rings.real_double.RealDoubleElement.__int__ (sage/rings/real_double.c:13090)()

 

OverflowError: cannot convert float infinity to integer

 

It appears I collect this error because I am using very large matrices. In my case, I used a matrix with 144*10^16 of size and then I met this error. However, when I shrink it to be 144*10^15, everything just goes fine!

I have attached my codes and hopefully, someone here could help me with this problem. Thanks in advance.

 

Some more details for debugging:

1. DataCollecctionScript.py is the main function, in this script, I set at line 46-48: m=16, n=2^16 and t=9. With these parameters I would encounter an error in CopaCode.sage, line 59: H_check_poly is a (m*t) * n matrix with GF(2^m) element as its entry. But if I set n to be 2^15 or smaller, there would be no error any more. This is why I doubt it is a potential bug here.

 

 

DataCollecctionScript.py
GoppaCode.sage
McElieceCryptosystem.sage
NiederreiterCryptosystem.sage

William Stein

unread,
Jul 8, 2014, 4:02:57 PM7/8/14
to sage-support
He means 144*2^16, not 144*10^16...

>
> I have attached my codes and hopefully, someone here could help me with this
> problem. Thanks in advance.
>
>
>
> Some more details for debugging:
>
> 1. DataCollecctionScript.py is the main function, in this script, I set at
> line 46-48: m=16, n=2^16 and t=9. With these parameters I would encounter an
> error in CopaCode.sage, line 59: H_check_poly is a (m*t) * n matrix with
> GF(2^m) element as its entry. But if I set n to be 2^15 or smaller, there
> would be no error any more. This is why I doubt it is a potential bug here.
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.



--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Michiel Kosters

unread,
Sep 19, 2014, 12:25:46 AM9/19/14
to sage-s...@googlegroups.com
I have a similar bug with the following code:

n=16
F.<a>=GF(2^n)
print Matrix([a]), F(0)
print Matrix([F(0)])

The last print statement gives an error OverflowError: cannot convert float infinity to integer
For other n, the code does not give an error.

Yours,
Michiel




On Tuesday, July 8, 2014 10:21:06 PM UTC+8, David Hoo wrote:

I happened to meet a overflow error, I install sage 6.2 both on a 64-bit macbook running MacOS 10.9 and 32-bit Dell Desktop running Ubuntu 12.04.

The error message goes like this:

OverflowError                             Traceback (most recent call last)

<ipython-input-7-8d411648858e> in <module>()

----> 1 get_ipython().magic(u'runfile DataCollecctionScript.py')

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)

   2163         magic_name, _, magic_arg_s = arg_s.partition(' ')

   2164         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)

-> 2165         return self.run_line_magic(magic_name, magic_arg_s)

   2166

   2167     #-------------------------------------------------------------------------

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)

   2084                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals

   2085             with self.builtin_trap:

-> 2086                 result = fn(*args,**kwargs)

   2087             return result

   2088

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/repl/ipython_extension.pyc in runfile(self, s)

 

/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)

    189     # but it's overkill for just that one bit of state.

    190     def magic_deco(arg):

--> 191         call = lambda f, *a, **k: f(*a, **k)

<span style="font-size:14.0pt; font-family:&quot

...

Vincent Delecroix

unread,
Sep 19, 2014, 3:07:27 PM9/19/14
to sage-s...@googlegroups.com
There is definitely something wrong, but what would you expect from the command

sage: F[0]

Vincent

2014-09-19 6:25 UTC+02:00, Michiel Kosters <kos...@gmail.com>:
> I have a similar bug with the following code:
>
> n=16
> F.<a>=GF(2^n)
> print Matrix([a]), F(0)
> print Matrix([F(0)])
>
> The last print statement gives an error OverflowError: cannot convert float
>
> infinity to integer
> For other n, the code does not give an error.
>
> Yours,
> Michiel
>
>
>
> On Tuesday, July 8, 2014 10:21:06 PM UTC+8, David Hoo wrote:
>>
>> I happened to meet a overflow error, I install sage 6.2 both on a 64-bit
>> macbook running MacOS 10.9 and 32-bit Dell Desktop running Ubuntu 12.04.
>>
>> The error message goes like this:
>>
>> OverflowError Traceback (most recent call
>> last)
>>
>> <ipython-input-7-8d411648858e> in <module>()
>>
>> ----> 1 get_ipython().magic(u'runfile DataCollecctionScript.py')
>>
>>
>>
>>
>> /Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc
>>
>> in magic(self, arg_s)
>>
>> * 2163* magic_name, _, magic_arg_s = arg_s.partition(' ')
>>
>> * 2164* magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
>>
>> -> 2165 return self.run_line_magic(magic_name, magic_arg_s)
>>
>> * 2166*
>>
>> * 2167*
>> #-------------------------------------------------------------------------
>>
>>
>>
>>
>> /Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc
>>
>> in run_line_magic(self, magic_name, line)
>>
>> * 2084* kwargs['local_ns'] =
>> sys._getframe(stack_depth).
>> f_locals
>>
>> * 2085* with self.builtin_trap:
>>
>> -> 2086 result = fn(*args,**kwargs)
>>
>> * 2087* return result
>>
>> * 2088*
>> * 189* # but it's overkill for just that one bit of state.
>>
>> * 190* def magic_deco(arg):
>>
>> --> 191 call = lambda f, *a, **k: f(*a, **k)
>>
>> *<span style="font-size:14.0pt; font-family:&quot*
>> ...

P Purkayastha

unread,
Sep 19, 2014, 8:12:35 PM9/19/14
to sage-s...@googlegroups.com
It is not F[0] it is F(0). :-) The example cited is definitely a bug, perhaps from sage. Note the following:

sage: M = matrix(F, [[1],[0]])                                                  
sage
: type(M)
<type 'sage.matrix.matrix_mod2e_dense.Matrix_mod2e_dense'>
sage
: M
<repr(<sage.matrix.matrix_mod2e_dense.Matrix_mod2e_dense at 0x7fbcf6f65e20>) failed: OverflowError: cannot convert float infinity to integer>

So, sage doesn't even realize that the underlying library m4rie(?) crashed. For larger powers, sage uses some other library (what?). Maybe we should switch to that from 2^16 onwards


sage: F = GF(2**17, 'a')
sage
: M = matrix(F, [[1],[0]])
sage
: type(M)
<type 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'>

Volker Braun

unread,
Sep 20, 2014, 7:07:08 AM9/20/14
to sage-s...@googlegroups.com, Martin Albrecht
I still get the overflow with the m4ri update that is bound to be in 6.4.beta4. Martin, any ideas?

Martin Albrecht

unread,
Sep 22, 2014, 4:29:59 PM9/22/14
to sage-s...@googlegroups.com
This is a bug in Sage's finite field via NTL's GF2E implementation which is
triggered by M4RIE:

sage: K.<a> = GF(2^15)
sage: type(K), type(matrix(K))
(sage.rings.finite_rings.finite_field_givaro.FiniteField_givaro_with_category,
sage.matrix.matrix_mod2e_dense.Matrix_mod2e_dense)

sage: K.<a> = GF(2^16)
sage: type(K), type(matrix(K))
(sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category,
sage.matrix.matrix_mod2e_dense.Matrix_mod2e_dense)

sage: K.<a> = GF(2^17)
sage: type(K), type(matrix(K))
(sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category,
sage.matrix.matrix_generic_dense.Matrix_generic_dense)

I've fixed it at:

http://trac.sagemath.org/ticket/17027

Cheers,
Martin

On Saturday 20 Sep 2014 04:07:08 Volker Braun wrote:
> I still get the overflow with the m4ri update that is bound to be in
> 6.4.beta4. Martin, any ideas?
>
> On Friday, September 19, 2014 5:25:46 AM UTC+1, Michiel Kosters wrote:
> > I have a similar bug with the following code:
> >
> > n=16
> > F.<a>=GF(2^n)
> > print Matrix([a]), F(0)
> > print Matrix([F(0)])
> >
> > The last print statement gives an error OverflowError: cannot convert
> > float infinity to integer
> > For other n, the code does not give an error.
> >
> > Yours,
> > Michiel
> >
> > On Tuesday, July 8, 2014 10:21:06 PM UTC+8, David Hoo wrote:
> >> I happened to meet a overflow error, I install sage 6.2 both on a 64-bit
> >> macbook running MacOS 10.9 and 32-bit Dell Desktop running Ubuntu 12.04.
> >>
> >> The error message goes like this:
> >>
> >> OverflowError Traceback (most recent call
> >> last)
> >>
> >> <ipython-input-7-8d411648858e> in <module>()
> >>
> >> ----> 1 get_ipython().magic(u'runfile DataCollecctionScript.py')
> >>
> >>
> >>
> >>
> >> /Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/si
> >> te-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
> >>
> >> * 2163* magic_name, _, magic_arg_s = arg_s.partition(' ')
> >>
> >> * 2164* magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
> >>
> >> -> 2165 return self.run_line_magic(magic_name, magic_arg_s)
> >>
> >> * 2166*
> >>
> >> * 2167*
> >> #------------------------------------------------------------------------
> >> -
> >>
> >>
> >>
> >>
> >> /Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/si
> >> te-packages/IPython/core/interactiveshell.pyc in run_line_magic(self,
> >> magic_name, line)
> >>
> >> * 2084* kwargs['local_ns'] = sys._getframe(stack_depth
> >> ).f_locals
> >>
> >> * 2085* with self.builtin_trap:
> >>
> >> -> 2086 result = fn(*args,**kwargs)
> >>
> >> * 2087* return result
> >>
> >> * 2088*
> >>
> >>
> >>
> >>
> >> /Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/si
> >> te-packages/sage/repl/ipython_extension.pyc in runfile(self, s)
> >>
> >>
> >>
> >>
> >> /Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/si
> >> te-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
> >>
> >> * 189* # but it's overkill for just that one bit of state.
> >>
> >> * 190* def magic_deco(arg):
> >>
> >> --> 191 call = lambda f, *a, **k: f(*a, **k)
> >>
> >> *<span style="font-size:14.0pt; font-family:&quot*
> >> ...
signature.asc
Reply all
Reply to author
Forward
0 new messages