Home Man
Today's Posts

Linux & Unix Commands - Search Man Pages

RedHat 9 (Linux i386) - man page for pdl::tips (redhat section 1)

TIPS(1) 		       User Contributed Perl Documentation			  TIPS(1)

       PDL::Tips - Small tidbits of useful arcana. Programming tidbits and such.

	       use PDL;

	       # Whatever happens here.

       This page documents useful idioms, helpful hints and tips for using Perl Data Language


       Use "help help" within perldl or the "pdldoc" program from the command line for access to
       the PerlDL documentation.  HTML versions of the pages should also be present, in the Html-
       Docs/PDL directory of the PDL distribution. To find this directory, try the following

	perldl> foreach ( map{"$_/PDL/HtmlDocs"}@INC ) { p "$_\n" if -d $_ }

       Indexing idioms

       The following code normalizes a bunch of vectors in $a.	This works regardless of the
       dimensionality of $a.

	       $a /= $a->sumover->dummy(0);

       What is actually happening?

       If you want to see what the code is actually doing, try the command


       somewhere. This spews out a huge amount of debug info for PDL into STDOUT. It is planned
       to eventually make this redirectable and the messages selectable more accurately.

       Many of the messages come from "Basic/Core/pdlapi.c" and you can look at the source to see
       what is going on.

       If you have any extra time to work on these mechanisms, infrom the pdl-porters mailing

       Memory savings

       If you are running recursively something that selects certain indices of a large piddle,

	       while(1) {
		       $inds = where($a>0);
		       $a = $a->index($inds);
		       $b = $b->index($inds);

       If you are not writing to $b, it saves a lot of memory to change this to

		       $b = $b->index($inds)->sever;

       The new method "sever" is a causes the write-back relation to be forgotten. It is like
       copy except it changes the original piddle and returns it).

       Of course, the probably best way to do the above is

	       $inds = xvals ($a->long);
	       while(1) {
		       $inds0 = where($a>0);
		       $inds1 = $inds->index($inds)->sever;
		       $a = $a0->index($inds1);
		       $b = $b->index($inds1)->sever;

       which doesn't save all the temporary instances of $a in memory.	See "mandel.pl" in the
       Demos subdirectory of the PerlDL distribution for an example.

       PP speed

       If you really want to write speedy PP code, the first thing you need to do is to make sure
       that your C compiler is allowed to do the necessary optimizations.

       What this means is that you have to allow as many variables as possible to go into regis-

	       loop(a) %{
		       $a() += $COMP(foo_member) * $b()

       expands to

	       for(i=0; i<10000; i++) {
		       a[i] += __privtrans->foo_member * b[i];

       is about the worst you can do, since your C compiler is not allowed to assume that "a"
       doesn't clobber "foo_member" which completely inhibits vectorization. Instead, do

	       float foo = $COMP(foo_member);
	       loop(a) %{
		       $a() += foo * $b();

       This is not a restriction caused by PP but by ANSI C semantics.	Of course, we could copy
       the struct into local varibles and back but that could cause very strange things some-

       There are many other issues on organizing loops.

       We are currently planning to make PP able to do fixed-width things as well as physical
       piddles (where looping over the first dimensions would be cheaper as there are less dis-
       tinct increments, which might make a difference on machines with a small number of regis-

       Copyright (C) Tuomas J. Lukka 1997. All rights reserved.  Duplication in the same form and
       printing a copy for yourself allowed.

perl v5.8.0				    2000-06-01					  TIPS(1)

All times are GMT -4. The time now is 11:41 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password