ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 09 Jun 2011 10:07:33 -0500passing multiple variables and @parallelhttp://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/The @parallel examples all show f(x).
Is it possible to use f(x,y,z) where x is the list to be iterated over?
Are there any examples of @parallel that do not use list?
Tue, 25 Jan 2011 14:24:27 -0600http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/Comment by Shashank for <p>The @parallel examples all show f(x). <br/>
Is it possible to use f(x,y,z) where x is the list to be iterated over? <br/>
Are there any examples of @parallel that do not use list?</p>
http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/?comment=22248#post-id-22248Can you post a sample code to explain what you are trying to do? The most natural solution would be to pass an array. Tue, 25 Jan 2011 14:34:22 -0600http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/?comment=22248#post-id-22248Answer by niles for <p>The @parallel examples all show f(x). <br/>
Is it possible to use f(x,y,z) where x is the list to be iterated over? <br/>
Are there any examples of @parallel that do not use list?</p>
http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/?answer=12425#post-id-12425Indeed, this is missing from the documentation, and I found it confusing. With some fiddling, I learned that `@parallel` will pass tuples as arguments:
@parallel
def func(n,color='red'):
sleep(2)
return [n^2,color]
L=[2,(4,'blue'),5,(6,'green'),7]
r = func(L)
The output is as expected:
for s in r:
print "func(%s) = %s"%(s[0][0][0],s[1])
func((2,)) = [4, 'red']
func((4, 'blue')) = [16, 'blue']
func((5,)) = [25, 'red']
func((6, 'green')) = [36, 'green']
func((7,)) = [49, 'red']
<br>
----
UPDATE: Ok, I guess I have time to at least *create* the ticket ;) This is now ticket 11462!Wed, 08 Jun 2011 23:39:51 -0500http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/?answer=12425#post-id-12425Comment by kcrisman for <p>Indeed, this is missing from the documentation, and I found it confusing. With some fiddling, I learned that <code>@parallel</code> will pass tuples as arguments:</p>
<pre><code>@parallel
def func(n,color='red'):
sleep(2)
return [n^2,color]
L=[2,(4,'blue'),5,(6,'green'),7]
r = func(L)
</code></pre>
<p>The output is as expected:</p>
<pre><code>for s in r:
print "func(%s) = %s"%(s[0][0][0],s[1])
func((2,)) = [4, 'red']
func((4, 'blue')) = [16, 'blue']
func((5,)) = [25, 'red']
func((6, 'green')) = [36, 'green']
func((7,)) = [49, 'red']
</code></pre>
<h2><br/></h2>
<p>UPDATE: Ok, I guess I have time to at least <em>create</em> the ticket ;) This is now ticket 11462!</p>
http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/?comment=21599#post-id-21599So open a ticket for this doc patch! :) You will become the new @parallel expert :)Thu, 09 Jun 2011 10:03:50 -0500http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/?comment=21599#post-id-21599Comment by niles for <p>Indeed, this is missing from the documentation, and I found it confusing. With some fiddling, I learned that <code>@parallel</code> will pass tuples as arguments:</p>
<pre><code>@parallel
def func(n,color='red'):
sleep(2)
return [n^2,color]
L=[2,(4,'blue'),5,(6,'green'),7]
r = func(L)
</code></pre>
<p>The output is as expected:</p>
<pre><code>for s in r:
print "func(%s) = %s"%(s[0][0][0],s[1])
func((2,)) = [4, 'red']
func((4, 'blue')) = [16, 'blue']
func((5,)) = [25, 'red']
func((6, 'green')) = [36, 'green']
func((7,)) = [49, 'red']
</code></pre>
<h2><br/></h2>
<p>UPDATE: Ok, I guess I have time to at least <em>create</em> the ticket ;) This is now ticket 11462!</p>
http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/?comment=21598#post-id-21598ha! Yes I'd like to, but I don't quite have time for it right now -- maybe in a month or so . . .Thu, 09 Jun 2011 10:07:33 -0500http://ask.sagemath.org/question/7897/passing-multiple-variables-and-parallel/?comment=21598#post-id-21598