Ask Your Question

Pelonza1's profile - activity

2021-06-08 10:45:01 +0200 received badge  Famous Question (source)
2021-05-02 20:54:30 +0200 received badge  Notable Question (source)
2021-05-02 20:54:30 +0200 received badge  Popular Question (source)
2014-09-14 01:53:12 +0200 received badge  Nice Question (source)
2014-09-12 15:52:14 +0200 received badge  Student (source)
2014-09-10 01:07:11 +0200 commented question Defining functions error?

The indentation was standardized where I wrote the code. I copy and pasted from wordpad, which lost the tab's for the posting screen. These are fixed now. After some more investigation, I'm not entirely sure this is a "sage" error, so much as a "cloud.sagemath.com" error. That is, I only generate this behavior in the cloud version of sage, when I actually use a sage implementation, this works fine. Perhaps "parallel" is not properly implemented in the cloud.

2014-09-10 01:06:00 +0200 received badge  Editor (source)
2014-09-09 18:28:59 +0200 asked a question Defining functions error?

I've got some code I've been using to test stuff... and I know python/sage doesn't have explicit function ends (it is white-space determined) but I can't for the life of me figure out what is going on with this code:

#A dummy parallel function to count elements in a generator/iterator.
@parallel(6)
def dummy_look(grpit):
      cntrdmy=0
      looptre=True
      while looptre:
           try:
                 grpit.next()
                 cntrdmy+=1
           except StopIteration:
                 looptre = False

      return cntrdmy

#print 1

def myfirstn(n):
      num = 0
      while num<n:
           yield num
           num += 1
      return

(any executable line)

When I leave "print 1" commented out, it raises an error on the 2nd definition.

When I uncomment "print 1" it excecutes just fine. (and correctly runs the parallel-ness, though that isn't demonstrated in this code)

I'm running this on cloud.sagemath.com

2014-09-05 00:37:34 +0200 asked a question How to slice an unknown length iterator

I'm trying to take chunks of an iterator, for which I don't know the length of. The underlying goal is that I have a generator function which makes piles and piles of graphs (via a generator/iterator) that I want to try and test for a property in parallel (because serially testing each element is fast, but the list is really long).

Here's the code I'm working with right now:

#Slice Size:
slsize=500

grpgen=graphs.nauty_geng("10 -c 33:39 -d6")
start=0
stop=slsize

grplst=list()
loopcnt=0
loopt=True
while loopt:

   grplst.append(itertools.islice(grpgen,start,stop))
   #print loopcnt

   try:     
       g=grplst[loopcnt].next()
       print g
   except StopIteration:
       loopt=False
       print "got except"

   start+=slsize+1
   stop+=slsize
   loopcnt+=1

print loopcnt
#print grplst

This snippet will run ok. But as soon as I uncomment the "print grplst" at the end, it raises a strange 'resource unavailable' error. The error is raised on the 'try command' (g=grplst[loopcnt].next()) .... not when I actually print the grplst. And, it happens while _preparsing_ my file. (I'm loading this from a separate file).

When I leave it commented out though, it's clearly going through the 'try' command several times successfully before correctly catching the exception. It just seems that when I want to USE the list I've been creating of iterators, then it doesn't like it!