Addy -

I am not deeply familiar with the PP internals, but I believe I know enough
to answer your questions.  Others on this list know more and hopefully can
address any errors or clarify any ambiguities of mine.

How can i get address for a row (column in PDL's case) from PDL::PP??
>
> For Example, the following C code
>    int a[10][10];
>    getdata(a);
>    int *row=a[5];
> row should contain the address of the 5th row.
>
> This brings up two questions:
>
> In PDL::PP module, can this be done???
> Can Slices be used inside PP code??
>

There is a mechanism in PDL::PP for getting a representation like this, but
you shouldn't use it for your own PDL::PP code.  I say 'getting a
representation' because there's no way to guarantee the form of your data's
internal representation: your function could be operating on data for which
dimensions have been exchanged or moved at the Perl level.  In that case,
consecutive elements in the data may not be consecutive elements in the
first specified dimension.  PDL::PP handles all of the addressing for you
(thankfully), and you would do best to not mess with it.  To put it a little
differently, if you're trying to access slices in PDL::PP, you're probably
not doing it right.

Of course, I said that you can get a representation like this, which would
be necessary if you're trying to interface with a C function that wants a
C-style array.  In that case, there is a way to tell PDL::PP to make such a
representation for your function.  You would use $P(varname).  Check it out
in the PDL::PP docs.

I want to reiterate that you shouldn't operate on your data like that in
your own PP code.  You should use the loop construction instead:

loop(DIMEN) %{
    /* Mess with data in here */
%}

or if you need tighter controls on the bounds of your loop, write your own
for-loop like so:

int end = $SIZE(N) - 5;
int start = 4;
for(int i = start; i < end; i++) {
    $pdl(N => i) = ...
}

To access the (i,j) element of a piddle, you would say either of these two:

$pdl(m => i, n => j) = ...
$pdl(n => j, m => i) = ...

Notice the order of m and n don't matter.

I believe that most of PDL::PP's processing advantages over plain Perl code
comes in higher efficiency for its loops.  If you don't need to worry about
looping in your algorithm, you should probably just code it at the Perl
level.  Trying to code it at the PP level would probably be an example of
premature optimization, and nobody wants to be guilty of that.  :-)

Also, is there a way for OtherPars to be made Global Variables (like
> OtherPars => 'global static int T;')??
>

You wouldn't want to do that in a pp_def call because that's for function
definitions, and global variables shouldn't be declared in function
definitions.  Instead, you should probably declare your global variable in a
pp_add_boot section.  The BOOT section (quoting Inline::Pdlpp) is "often
used to execute code only once at load time of the module, e.g. a library
initialization call."

I hope I've adequately answered your questions.  The correct answer for your
first pair of questions depends on what you're trying to do, so if you I
didn't give a useful answer, feel free to post a more specific question
and/or example.

David
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to