On Wed, Nov 18, 2009 at 4:36 AM, adithya <[email protected]> wrote:
> Working around this, i decided to rewrite some functions so that they can > accept the original values from a PDL and process in the integer array and > finally, i'll write the integer arrays into the output piddle; so the > problem will be solved. > > <snip> > Addy - You're suggesting a piddle -> int array -> piddle? Manually? Don't do that. PDL::PP was written explicitly so you wouldn't have to do that. For you to make any more progress with your function definition, I'm afraid you'll have to read the pod documentation for PDL::PP. It's pretty abstract stuff, but since you're actually trying to solve an immediate problem, I suspect you won't fall asleep as much as I did when I first read it. I've also supplied numerous example links, which should make the notation a bit more concrete. First of all, I wrote a wiki page introducing the basics of PDL::PP using Inline::Pdlpp. It was written with people like you in mind. Hopefully it will get you off to a good start: http://sourceforge.net/apps/mediawiki/pdl/index.php?title=How_to_Learn_PDL::PP_using_Inline::Pdlpp For the PDL::PP documentation, see this page: http://pdl.sourceforge.net/PDLdocs/PP.html Christian wrote some decent examples for using Inline::Pdlpp, both in the pod for Inline::Pdlpp and in an examples folder. Check out the following links: http://search.cpan.org/~chm/PDL-2.4.5/Basic/Gen/Inline/Pdlpp.pm http://cpansearch.perl.org/src/CHM/PDL-2.4.5_003/Example/InlinePdlpp/ For a good example of working PDL::PP code, the following may be instructive: http://cpansearch.perl.org/src/CHM/PDL-2.4.5_003/Basic/Primitive/primitive.pd I don't recommend that you write piddle -> int array -> piddle, but if you insist, you'll probably want to see PDL::PP code that interfaces with C functions. See the various GSL examples. Look for *.pd files in the subfolders of this link: http://cpansearch.perl.org/src/CHM/PDL-2.4.5_003/Lib/GSL/ I've partially rewritten your code for use with PDL::PP using Inline::Pdlpp, but it is not functional at the moment. You should notice that I've changed the looping construction (over j) to use the standard PP idiom. I believe the code should work as soon as you figure out how to pass in the parameters. --------%<-------- #!/usr/bin/perl use warnings; use strict; use PDL; # set up the PDL::PP environment with stdlib.h, needed for drand48. # drand48 generates uniformly distributed quasirandom numbers use Inline (Pdlpp => Config => AUTO_INCLUDE => "#include <stdlib.h>"); # Define the random_assignment function # Note I couldn't figure out what ntot was used for. In fact, I didn't # see it used. So, I removed it. :) use Inline Pdlpp => q{ pp_def 'random_assignment', Pars => 'short T_d(m); short T_w(m); short T_index(m); int T_range(); ', # $TD seemed to have a different lexical meaning for each of the m's, # so I've separated them with the following: # $TD(m => 0) --> $T_d # $TD(m => 1) --> $T_w # $TD(m => 2) --> $T_index # These parameters need to go in the Pars section. # int *z, int **wp, int **dp, int *ztot # I recommend something like this: # int z(n); int wp(o,p); int dp(o,p), int ztot(p) # Whether this is correct or not, as well as how you would modify your # code (ex: $wp( o => $T_w(), p => t) ) is an exercise left to the # reader. :) Code => q{ int i, t, sum = 0; loop(m) %{ for(i = sum; i - sum < $T_index(); i++) { t = (int)(T_range() * drand48()); z[i + sum] = t; /* !! are you sure this shouldn't be i - sum?? */ wp[$T_w()][t]++; dp[$T_p()][t]++; ztot[t]++; } sum += $T_index(); %} }, ); }; # At this point you need to set up your T_* and other piddles, at which # point you should be able to call PDL::random_assignment($T_d, $T_w, ...); --------%<-------- Hope that helps! David
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
