Re: [Numpy-discussion] function name as parameter

2010-10-21 Thread Dag Sverre Seljebotn
Johann Cohen-Tanugi wrote: On 10/20/2010 11:10 PM, Robert Kern wrote: On Wed, Oct 20, 2010 at 15:58, Johann Cohen-Tanugico...@lpta.in2p3.fr wrote: On 10/20/2010 10:35 PM, Nathaniel Smith wrote: IMPORTANT USAGE NOTE: never do this :-)

Re: [Numpy-discussion] function name as parameter

2010-10-21 Thread Johann Cohen-Tanugi
On 10/20/2010 11:49 PM, Zachary Pincus wrote: Hi Robert, so in a big data analysis framework, that is essentially written in C ++, exposed to python with SWIG, plus dedicated python modules, the user performs an analysis choosing some given modules by name,as in : myOpt=foo

[Numpy-discussion] function name as parameter

2010-10-20 Thread Thomas Kirk Gamble
I'm trying to write an implementation of the amoeba function from numerical recipes and need to be able to pass a function name and parameter list to be called from within the amoeba function. Simply passing the name as a string doesn't work since python doesn't know it is a function and throws a

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Zachary Pincus
I'm trying to write an implementation of the amoeba function from numerical recipes and need to be able to pass a function name and parameter list to be called from within the amoeba function. Simply passing the name as a string doesn't work since python doesn't know it is a function and

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Johann Cohen-Tanugi
If you really need to pass the function name : In [3]: def my_func(x): ...: return 2*x In [4]: def caller(fname,x): ...: return eval(%s(%f)%(fname,x)) In [5]: caller(my_func,2) Out[5]: 4.0 On 10/20/2010 03:46 PM, Zachary Pincus wrote: I'm trying to write an implementation of

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread josef . pktd
On Wed, Oct 20, 2010 at 9:46 AM, Zachary Pincus zachary.pin...@yale.edu wrote: I'm trying to write an implementation of the amoeba function from numerical recipes and need to be able to pass a function name and parameter list to be called from within the amoeba function.  Simply passing the

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Thomas Kirk Gamble
On Wed, 2010-10-20 at 09:46 -0400, Zachary Pincus wrote: I'm trying to write an implementation of the amoeba function from numerical recipes and need to be able to pass a function name and parameter list to be called from within the amoeba function. Simply passing the name as a string

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Thomas Kirk Gamble
On Wed, 2010-10-20 at 13:18 -0400, Alan G Isaac wrote: On 10/20/2010 9:42 AM, Thomas Kirk Gamble wrote: I'm trying to write an implementation of the amoeba function from numerical recipes and need to be able to pass a function name and parameter list to be called from within the amoeba

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Nathaniel Smith
On Wed, Oct 20, 2010 at 6:51 AM, Johann Cohen-Tanugi co...@lpta.in2p3.fr wrote: If you really need to pass the function name : In [3]: def my_func(x):    ...:     return 2*x In [4]: def caller(fname,x):    ...:     return eval(%s(%f)%(fname,x)) In [5]: caller(my_func,2) Out[5]: 4.0 The

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Johann Cohen-Tanugi
On 10/20/2010 10:35 PM, Nathaniel Smith wrote: On Wed, Oct 20, 2010 at 6:51 AM, Johann Cohen-Tanugi co...@lpta.in2p3.fr wrote: If you really need to pass the function name : In [3]: def my_func(x): ...: return 2*x In [4]: def caller(fname,x): ...: return

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Robert Kern
On Wed, Oct 20, 2010 at 15:58, Johann Cohen-Tanugi co...@lpta.in2p3.fr wrote: On 10/20/2010 10:35 PM, Nathaniel Smith wrote: IMPORTANT USAGE NOTE: never do this :-) What would you recommand? I do encounter situations where I need instantiation based on the name of the thing to instantiate,

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Johann Cohen-Tanugi
On 10/20/2010 11:10 PM, Robert Kern wrote: On Wed, Oct 20, 2010 at 15:58, Johann Cohen-Tanugico...@lpta.in2p3.fr wrote: On 10/20/2010 10:35 PM, Nathaniel Smith wrote: IMPORTANT USAGE NOTE: never do this :-) What would you recommand? I do encounter situations where

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Zachary Pincus
Hi Robert, so in a big data analysis framework, that is essentially written in C ++, exposed to python with SWIG, plus dedicated python modules, the user performs an analysis choosing some given modules by name,as in : myOpt=foo my_analyse.perform(use_optimizer=myOpt) The attribute

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Robert Kern
On Wed, Oct 20, 2010 at 16:49, Zachary Pincus zachary.pin...@yale.edu wrote: But why not have the user just pass in the relevant optObject from the pyOpt namespace (or some restricted namespace that just has the relevant functions exposed)? E.g. my_analysis.perform(optimizer=pyOpt.Amoeba)