Why does @parallel change my outputs?

Can someone explain this behavior to me:

sage: @parallel
....: def foo(n):
....:         return str(factor(n))
....:
sage: foo(10)
'2 * 5'
sage: for x in foo([1..10]):
....:         print x[0][0][0]
....:
1
2
3
4
5
6
7
8
9
10


I expected to get the factorizations of 1 .. 10, not the numbers 1 .. 10. It seems like the output of foo() is getting evaluated somehow when it goes through the @parallel decorator. Is this a bug?

edit retag close merge delete

Sort by ยป oldest newest most voted

x[0] holds the arguments to foo, x[1] holds the output :) Try

sage: @parallel
....: def foo(n):
....:         return str(factor(n))
....:
sage: foo(10)
'2 * 5'
sage: for x in foo([1..10]):
....:         print x[0][0][0],'->', x[1]
....:
2 -> 2
1 -> 1
3 -> 3
4 -> 2^2
5 -> 5
6 -> 2 * 3
7 -> 7
8 -> 2^3
9 -> 3^2
10 -> 2 * 5

more

Of course! Thanks, that was a dumb question.

( 2011-08-12 06:52:29 -0500 )edit

Ha! No worries :)

( 2011-08-12 07:00:49 -0500 )edit

I totally missed this when I was looking at it the other day - good thing Niles is on the job :)

( 2011-08-13 14:05:08 -0500 )edit

Sorry, why are you printing x[0][0][0], why doesn't x[0] suffice?

( 2011-08-13 14:59:33 -0500 )edit

As @niles says, x[0] contains the inputs to the parallel function, but the decorator puts them in a normal form which involves a triple nested tuple. That's what I was getting inside of with x[0][0][0].

( 2011-08-13 16:00:49 -0500 )edit