Ask Your Question

Revision history [back]

TypeError with graphs.RandomGNP

I tried calling gnp = graphs.RandomGNP(20, .1, algorithm = 'sage') and it gave me the following error

TypeError                                 Traceback (most recent call last)
<ipython-input-147-7915a3a5dbc9> in <module>()
----> 1 gnp = graphs.RandomGNP(Integer(20), RealNumber('.1'), algorithm = 'sage')

/anaconda3/envs/graphs/lib/python3.6/site-packages/sage/graphs/generators/random.py in RandomGNP(n, p, seed, fast, algorithm)
    122         # We use the Sage generator
    123         from sage.graphs.graph_generators_pyx import RandomGNP as sageGNP
--> 124         return sageGNP(n, p)
    125     else:
    126         raise ValueError("'algorithm' must be equal to 'networkx' or to 'Sage'.")

/anaconda3/envs/graphs/lib/python3.6/site-packages/sage/graphs/graph_generators_pyx.pyx in sage.graphs.graph_generators_pyx.RandomGNP (build/cythonized/sage/graphs/graph_generators_pyx.c:1366)()
     68     # integers are on 31 bits. We thus set the pivot value to p*2^31
     69     cdef float RAND_MAX_f = (1<<31)*1.0
---> 70     cdef int pp = int(round(p*(1<<31)))
     71 
     72     if directed:

TypeError: type sage.rings.real_mpfr.RealNumber doesn't define __round__ method

Not sure what went wrong here.. Appreciate any help! Thank you!