On Tue, May 5, 2009 at 7:00 AM, Christophe Oosterlynck <tif...@gmail.com> wrote: > > Hi, > > I'm writin a Cython module for Sage and at some point I want to > construct a random matrix with a certain density. But supplying the > density as a float to the random_matrix function will always become > 0... > > for example > > %cython > from sage.all import random_matrix,GF > cdef float d > d = <float>1/562
That 1/562 I think is just 0, since integer division is floor division in C=Cython. Instead write %cython from sage.all import random_matrix,GF,QQ cdef float d d = QQ((1,562)) > print random_matrix(GF(2),1024,562,density=d).is_zero() > > This will always construct a zero matrix because it acts as if density > = 0 ... > > What would be the correct way to pass the density argument to the > random_matrix function? > > Thanks, > > christophe > > > > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---