1TIPS(1)               User Contributed Perl Documentation              TIPS(1)
2
3
4

NAME

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

SYNOPSIS

10               use PDL;
11
12               # Whatever happens here.
13

DESCRIPTION

15       This page documents useful idioms, helpful hints and tips for using
16       Perl Data Language v2.0.
17
18       Help
19
20       Use "help help" within perldl or the "pdldoc" program from the command
21       line for access to the PerlDL documentation.  HTML versions of the
22       pages should also be present, in the HtmlDocs/PDL directory of the PDL
23       distribution. To find this directory, try the following
24
25        perldl> foreach ( map{"$_/PDL/HtmlDocs"}@INC ) { p "$_\n" if -d $_ }
26
27       Indexing idioms
28
29       The following code normalizes a bunch of vectors in $a.  This works
30       regardless of the dimensionality of $a.
31
32               $a /= $a->sumover->dummy(0);
33
34       What is actually happening?
35
36       If you want to see what the code is actually doing, try the command
37
38               PDL::Core::set_debugging(1);
39
40       somewhere. This spews out a huge amount of debug info for PDL into STD‐
41       OUT. It is planned to eventually make this redirectable and the mes‐
42       sages selectable more accurately.
43
44       Many of the messages come from "Basic/Core/pdlapi.c" and you can look
45       at the source to see what is going on.
46
47       If you have any extra time to work on these mechanisms, infrom the pdl-
48       porters mailing list.
49
50       Memory savings
51
52       If you are running recursively something that selects certain indices
53       of a large piddle, like
54
55               while(1) {
56                       $inds = where($a>0);
57                       $a = $a->index($inds);
58                       $b = $b->index($inds);
59                       func($b,$a);
60               }
61
62       If you are not writing to $b, it saves a lot of memory to change this
63       to
64
65                       $b = $b->index($inds)->sever;
66
67       The new method "sever" is a causes the write-back relation to be for‐
68       gotten. It is like copy except it changes the original piddle and
69       returns it).
70
71       Of course, the probably best way to do the above is
72
73               $inds = xvals ($a->long);
74               while(1) {
75                       $inds0 = where($a>0);
76                       $inds1 = $inds->index($inds)->sever;
77                       $a = $a0->index($inds1);
78                       $b = $b->index($inds1)->sever;
79                       func($b,$a);
80               }
81
82       which doesn't save all the temporary instances of $a in memory.  See
83       "mandel.pl" in the Demos subdirectory of the PerlDL distribution for an
84       example.
85
86       PP speed
87
88       If you really want to write speedy PP code, the first thing you need to
89       do is to make sure that your C compiler is allowed to do the necessary
90       optimizations.
91
92       What this means is that you have to allow as many variables as possible
93       to go into registers:
94
95               loop(a) %{
96                       $a() += $COMP(foo_member) * $b()
97               %}
98
99       expands to
100
101               for(i=0; i<10000; i++) {
102                       a[i] += __privtrans->foo_member * b[i];
103               }
104
105       is about the worst you can do, since your C compiler is not allowed to
106       assume that "a" doesn't clobber "foo_member" which completely inhibits
107       vectorization. Instead, do
108
109               float foo = $COMP(foo_member);
110               loop(a) %{
111                       $a() += foo * $b();
112               %}
113
114       This is not a restriction caused by PP but by ANSI C semantics.  Of
115       course, we could copy the struct into local varibles and back but that
116       could cause very strange things sometimes.
117
118       There are many other issues on organizing loops.
119
120       We are currently planning to make PP able to do fixed-width things as
121       well as physical piddles (where looping over the first dimensions would
122       be cheaper as there are less distinct increments, which might make a
123       difference on machines with a small number of registers).
124

AUTHOR

126       Copyright (C) Tuomas J. Lukka 1997. All rights reserved.  Duplication
127       in the same form and printing a copy for yourself allowed.
128
129
130
131perl v5.8.8                       2003-05-21                           TIPS(1)
Impressum