Re: run-time function creation [message #83867] |
Thu, 11 April 2013 09:28 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Wednesday, April 10, 2013 3:57:17 PM UTC-4, Paul Mallas wrote:
> On Wednesday, April 10, 2013 1:04:49 PM UTC-4, Craig Markwardt wrote:
>
>> On Wednesday, April 10, 2013 10:33:31 AM UTC-4, Paul Mallas wrote:
>
>>
>
>>> I know this is a bit off the wall, but I was wondering if there is a technique or method for doing run-time function creation.
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> The reason I ask is I was looking at the IDL integration routines (e.g., qsimp) and this requires a singular argument function name as input. My problem is I have a function with several parameters I need to integrate, but don't have these parameters until I calculate them at run time. If I could somehow create the function dynamically, I could create a function that would satisfy the the qsimp requirement for a single argument function, but prior to run-time I can't.
>
>>
>
>>
>
>>
>
>> Well, I have two answers for you.
>
>>
>
>>
>
>>
>
>> The first answer is that you can use my QPINT1D which is a better integrator than the IDL-standard quadrature functions. Plus, it allows you to enter in a private variable (a structure) for other parameters.
>
>>
>
>>
>
>>
>
>> If you really want run-time functions, then FILE_COMPILE will do that for you. You need to write out a scratch file with the function you want, and then FILE_COMPILE will do the tricky part of compiling it. (not so tricky, but getting the paths right is more work than you might think)
>
>>
>
>>
>
>>
>
>> Craig
>
>>
>
>>
>
>>
>
>> QPINT1D
>
>>
>
>> http://cow.physics.wisc.edu/~craigm/idl/math.html#QPINT1D
>
>>
>
>>
>
>>
>
>> FILE_COMPILE
>
>>
>
>> http://cow.physics.wisc.edu/~craigm/idl/introspect.html#FILE _COMPILE
>
>
>
> Craig - I used your qpint1. Excellent! It was just what I needed and it worked great. I even have the imsl lib and qpint1 worked much better than the imsl_intfcn. imsl_intfcn is fast and gives the right answer, but gives tons of floating point warnings and - for some reason - it kills the workbench when I run it. qpint1 appears slightly faster and does not deleterious side effects. Thank you!
You're welcome. It's kind of funny because both QPINT1D and IMSL_INTFCN have the same heritage (the QUADPACK package).
Craig
|
|
|
Re: run-time function creation [message #83868 is a reply to message #83867] |
Thu, 11 April 2013 08:35  |
rtk
Messages: 22 Registered: September 2008
|
Junior Member |
|
|
With IDL 8.x's new list and hash routines the idea of dynamically defined functions makes sense (consider implementing higher-order functions, like Python's map and reduce).
I have a lambda.pro routine, and a make_function routine, that pull off the trick Craig mentioned. What would be best is to define a function from a string and to be able to remove that function from memory. Still, dumping to a temporary file and compiling it on the fly is really quite fast with modern OSes. A couple of milliseconds typically.
Send me an email (rkneusel at exelisvis com) and I'll send them out to whoever is interested along with some higher-order function routines.
|
|
|
Re: run-time function creation [message #83882 is a reply to message #83868] |
Wed, 10 April 2013 12:57  |
PMan
Messages: 61 Registered: January 2011
|
Member |
|
|
On Wednesday, April 10, 2013 1:04:49 PM UTC-4, Craig Markwardt wrote:
> On Wednesday, April 10, 2013 10:33:31 AM UTC-4, Paul Mallas wrote:
>
>> I know this is a bit off the wall, but I was wondering if there is a technique or method for doing run-time function creation.
>
>>
>
>>
>
>>
>
>> The reason I ask is I was looking at the IDL integration routines (e.g., qsimp) and this requires a singular argument function name as input. My problem is I have a function with several parameters I need to integrate, but don't have these parameters until I calculate them at run time. If I could somehow create the function dynamically, I could create a function that would satisfy the the qsimp requirement for a single argument function, but prior to run-time I can't.
>
>
>
> Well, I have two answers for you.
>
>
>
> The first answer is that you can use my QPINT1D which is a better integrator than the IDL-standard quadrature functions. Plus, it allows you to enter in a private variable (a structure) for other parameters.
>
>
>
> If you really want run-time functions, then FILE_COMPILE will do that for you. You need to write out a scratch file with the function you want, and then FILE_COMPILE will do the tricky part of compiling it. (not so tricky, but getting the paths right is more work than you might think)
>
>
>
> Craig
>
>
>
> QPINT1D
>
> http://cow.physics.wisc.edu/~craigm/idl/math.html#QPINT1D
>
>
>
> FILE_COMPILE
>
> http://cow.physics.wisc.edu/~craigm/idl/introspect.html#FILE _COMPILE
Craig - I used your qpint1. Excellent! It was just what I needed and it worked great. I even have the imsl lib and qpint1 worked much better than the imsl_intfcn. imsl_intfcn is fast and gives the right answer, but gives tons of floating point warnings and - for some reason - it kills the workbench when I run it. qpint1 appears slightly faster and does not deleterious side effects. Thank you!
|
|
|
Re: run-time function creation [message #83887 is a reply to message #83882] |
Wed, 10 April 2013 11:07  |
PMan
Messages: 61 Registered: January 2011
|
Member |
|
|
On Wednesday, April 10, 2013 10:33:31 AM UTC-4, Paul Mallas wrote:
> I know this is a bit off the wall, but I was wondering if there is a technique or method for doing run-time function creation.
>
>
>
> The reason I ask is I was looking at the IDL integration routines (e.g., qsimp) and this requires a singular argument function name as input. My problem is I have a function with several parameters I need to integrate, but don't have these parameters until I calculate them at run time. If I could somehow create the function dynamically, I could create a function that would satisfy the the qsimp requirement for a single argument function, but prior to run-time I can't.
>
>
>
> Anyway, I know this is a wacky and maybe even a silly question, but can't hurt to ask.
>
>
>
> Regards,
>
> Paul
Thanks for the tips
|
|
|
Re: run-time function creation [message #83894 is a reply to message #83887] |
Wed, 10 April 2013 10:04  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Wednesday, April 10, 2013 10:33:31 AM UTC-4, Paul Mallas wrote:
> I know this is a bit off the wall, but I was wondering if there is a technique or method for doing run-time function creation.
>
>
>
> The reason I ask is I was looking at the IDL integration routines (e.g., qsimp) and this requires a singular argument function name as input. My problem is I have a function with several parameters I need to integrate, but don't have these parameters until I calculate them at run time. If I could somehow create the function dynamically, I could create a function that would satisfy the the qsimp requirement for a single argument function, but prior to run-time I can't.
Well, I have two answers for you.
The first answer is that you can use my QPINT1D which is a better integrator than the IDL-standard quadrature functions. Plus, it allows you to enter in a private variable (a structure) for other parameters.
If you really want run-time functions, then FILE_COMPILE will do that for you. You need to write out a scratch file with the function you want, and then FILE_COMPILE will do the tricky part of compiling it. (not so tricky, but getting the paths right is more work than you might think)
Craig
QPINT1D
http://cow.physics.wisc.edu/~craigm/idl/math.html#QPINT1D
FILE_COMPILE
http://cow.physics.wisc.edu/~craigm/idl/introspect.html#FILE _COMPILE
|
|
|
Re: run-time function creation [message #83895 is a reply to message #83894] |
Wed, 10 April 2013 07:56  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Paul Mallas writes:
> Actually, I think I just answered my own question. I could use the "common" block to pass the other parameters, huh? I have thought about this problem for a day or two, and as soon as I post the question, I come up with a solution myself. I guess I can't think straight until I clutter up the mail boxes of others :)
This is the Standard Operating Procedure in newsgroups, and one of their
biggest benefits. In my case, I normally recognize what a fool I am a
half second after I hit the Send button. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: run-time function creation [message #83896 is a reply to message #83895] |
Wed, 10 April 2013 07:55  |
Brian Daniel
Messages: 80 Registered: July 2009
|
Member |
|
|
Another option would be to populate a structure full of the parameters needed and send that to the function. If the dimensions or data types change of the parameters you're specifying, then use a pointer to a structure. Lists or hashes may also be useful, but I have no experience with them.
-Brian
On Wednesday, April 10, 2013 10:33:31 AM UTC-4, Paul Mallas wrote:
> I know this is a bit off the wall, but I was wondering if there is a technique or method for doing run-time function creation.
>
>
>
> The reason I ask is I was looking at the IDL integration routines (e.g., qsimp) and this requires a singular argument function name as input. My problem is I have a function with several parameters I need to integrate, but don't have these parameters until I calculate them at run time. If I could somehow create the function dynamically, I could create a function that would satisfy the the qsimp requirement for a single argument function, but prior to run-time I can't.
>
>
>
> Anyway, I know this is a wacky and maybe even a silly question, but can't hurt to ask.
>
>
>
> Regards,
>
> Paul
|
|
|
Re: run-time function creation [message #83897 is a reply to message #83896] |
Wed, 10 April 2013 07:47  |
PMan
Messages: 61 Registered: January 2011
|
Member |
|
|
On Wednesday, April 10, 2013 10:33:31 AM UTC-4, Paul Mallas wrote:
> I know this is a bit off the wall, but I was wondering if there is a technique or method for doing run-time function creation.
>
>
>
> The reason I ask is I was looking at the IDL integration routines (e.g., qsimp) and this requires a singular argument function name as input. My problem is I have a function with several parameters I need to integrate, but don't have these parameters until I calculate them at run time. If I could somehow create the function dynamically, I could create a function that would satisfy the the qsimp requirement for a single argument function, but prior to run-time I can't.
>
>
>
> Anyway, I know this is a wacky and maybe even a silly question, but can't hurt to ask.
>
>
>
> Regards,
>
> Paul
Actually, I think I just answered my own question. I could use the "common" block to pass the other parameters, huh? I have thought about this problem for a day or two, and as soon as I post the question, I come up with a solution myself. I guess I can't think straight until I clutter up the mail boxes of others :)
If there are other suggestions, let me know.
|
|
|