1Pdlpp(3) User Contributed Perl Documentation Pdlpp(3)
2
3
4
6 Inline::Pdlpp - Write PDL Subroutines inline with PDL::PP
7
9 "Inline::Pdlpp" is a module that allows you to write PDL subroutines in
10 the PDL::PP style. The big benefit compared to plain "PDL::PP" is that
11 you can write these definitions inline in any old perl script (without
12 the normal hassle of creating Makefiles, building, etc). Since version
13 0.30 the Inline module supports multiple programming languages and each
14 language has its own support module. This document describes how to use
15 Inline with PDL::PP (or rather, it will once these docs are complete
16 ";)".
17
18 For more information on Inline in general, see Inline.
19
20 Some example scripts demonstrating "Inline::Pdlpp" usage can be found
21 in the Example/InlinePdlpp directory.
22
23 "Inline::Pdlpp" is a subclass of Inline::C. Most Kudos goes to Brian I.
24
26 You never actually use "Inline::Pdlpp" directly. It is just a support
27 module for using "Inline.pm" with "PDL::PP". So the usage is always:
28
29 use Inline Pdlpp => ...;
30
31 or
32
33 bind Inline Pdlpp => ...;
34
36 Pending availability of full docs a few quick examples that illustrate
37 typical usage.
38
39 A simple example
40 # example script inlpp.pl
41 use PDL; # must be called before (!) 'use Inline Pdlpp' calls
42
43 use Inline Pdlpp; # the actual code is in the __Pdlpp__ block below
44
45 $a = sequence 10;
46 print $a->inc,"\n";
47 print $a->inc->dummy(1,10)->tcumul,"\n";
48
49 __DATA__
50
51 __Pdlpp__
52
53 pp_def('inc',
54 Pars => 'i();[o] o()',
55 Code => '$o() = $i() + 1;',
56 );
57
58 pp_def('tcumul',
59 Pars => 'in(n);[o] mul()',
60 Code => '$mul() = 1;
61 loop(n) %{
62 $mul() *= $in();
63 %}',
64 );
65 # end example script
66
67 If you call this script it should generate output similar to this:
68
69 prompt> perl inlpp.pl
70 Inline running PDL::PP version 2.2...
71 [1 2 3 4 5 6 7 8 9 10]
72 [3628800 3628800 3628800 3628800 3628800 3628800 3628800 3628800 3628800 3628800]
73
74 Usage of "Inline::Pdlpp" in general is similar to "Inline::C". In the
75 absence of full docs for "Inline::Pdlpp" you might want to compare
76 Inline::C.
77
78 Code that uses external libraries, etc
79 The script below is somewhat more complicated in that it uses code from
80 an external library (here from Numerical Recipes). All the relevant
81 information regarding include files, libraries and boot code is
82 specified in a config call to "Inline". For more experienced Perl
83 hackers it might be helpful to know that the format is similar to that
84 used with ExtUtils::MakeMaker. The keywords are largely equivalent to
85 those used with "Inline::C". Please see below for further details on
86 the usage of "INC", "LIBS", "AUTO_INCLUDE" and "BOOT".
87
88 use PDL; # this must be called before (!) 'use Inline Pdlpp' calls
89
90 use Inline Pdlpp => Config =>
91 INC => "-I$ENV{HOME}/include",
92 LIBS => "-L$ENV{HOME}/lib -lnr -lm",
93 # code to be included in the generated XS
94 AUTO_INCLUDE => <<'EOINC',
95 #include <math.h>
96 #include "nr.h" /* for poidev */
97 #include "nrutil.h" /* for err_handler */
98
99 static void nr_barf(char *err_txt)
100 {
101 fprintf(stderr,"Now calling croak...\n");
102 croak("NR runtime error: %s",err_txt);
103 }
104 EOINC
105 # install our error handler when loading the Inline::Pdlpp code
106 BOOT => 'set_nr_err_handler(nr_barf);';
107
108 use Inline Pdlpp; # the actual code is in the __Pdlpp__ block below
109
110 $a = zeroes(10) + 30;;
111 print $a->poidev(5),"\n";
112
113 __DATA__
114
115 __Pdlpp__
116
117 pp_def('poidev',
118 Pars => 'xm(); [o] pd()',
119 GenericTypes => [L,F,D],
120 OtherPars => 'long idum',
121 Code => '$pd() = poidev((float) $xm(), &$COMP(idum));',
122 );
123
125 For information on how to specify Inline configuration options, see
126 Inline. This section describes each of the configuration options
127 available for Pdlpp. Most of the options correspond either to MakeMaker
128 or XS options of the same name. See ExtUtils::MakeMaker and perlxs.
129
130 AUTO_INCLUDE
131 Specifies extra statements to automatically included. They will be
132 added onto the defaults. A newline char will be automatically added.
133 Does essentially the same as a call to "pp_addhdr". For short bits of
134 code "AUTO_INCLUDE" is probably syntactically nicer.
135
136 use Inline Pdlpp => Config => AUTO_INCLUDE => '#include "yourheader.h"';
137
138 BLESS
139 Same as "pp_bless" command. Specifies the package (i.e. class) to which
140 your new pp_defed methods will be added. Defaults to "PDL" if omitted.
141
142 use Inline Pdlpp => Config => BLESS => 'PDL::Complex';
143
144 BOOT
145 Specifies C code to be executed in the XS BOOT section. Corresponds to
146 the XS parameter. Does the same as the "pp_add_boot" command. Often
147 used to execute code only once at load time of the module, e.g. a
148 library initialization call.
149
150 CC
151 Specify which compiler to use.
152
153 CCFLAGS
154 Specify extra compiler flags.
155
156 INC
157 Specifies an include path to use. Corresponds to the MakeMaker
158 parameter.
159
160 use Inline Pdlpp => Config => INC => '-I/inc/path';
161
162 LD
163 Specify which linker to use.
164
165 LDDLFLAGS
166 Specify which linker flags to use.
167
168 NOTE: These flags will completely override the existing flags, instead
169 of just adding to them. So if you need to use those too, you must
170 respecify them here.
171
172 LIBS
173 Specifies external libraries that should be linked into your code.
174 Corresponds to the MakeMaker parameter.
175
176 use Inline Pdlpp => Config => LIBS => '-lyourlib';
177
178 or
179
180 use Inline Pdlpp => Config => LIBS => '-L/your/path -lyourlib';
181
182 MAKE
183 Specify the name of the 'make' utility to use.
184
185 MYEXTLIB
186 Specifies a user compiled object that should be linked in. Corresponds
187 to the MakeMaker parameter.
188
189 use Inline Pdlpp => Config => MYEXTLIB => '/your/path/yourmodule.so';
190
191 OPTIMIZE
192 This controls the MakeMaker OPTIMIZE setting. By setting this value to
193 '-g', you can turn on debugging support for your Inline extensions.
194 This will allow you to be able to set breakpoints in your C code using
195 a debugger like gdb.
196
197 TYPEMAPS
198 Specifies extra typemap files to use. Corresponds to the MakeMaker
199 parameter.
200
201 use Inline Pdlpp => Config => TYPEMAPS => '/your/path/typemap';
202
203 NOISY
204 Show the output of any compilations going on behind the scenes. Turns
205 on "BUILD_NOISY" in Inline::C.
206
208 "do"ing inline scripts
209 Beware that there is a problem when you use the __DATA__ keyword style
210 of Inline definition and want to "do" your script containing inlined
211 code. For example
212
213 # myscript.pl contains inlined code
214 # in the __DATA__ section
215 perl -e 'do "myscript.pl";'
216 One or more DATA sections were not processed by Inline.
217
218 According to Brian Ingerson (of Inline fame) the workaround is to
219 include an "Inline->init" call in your script, e.g.
220
221 use PDL;
222 use Inline Pdlpp;
223 Inline->init;
224
225 # perl code
226
227 __DATA__
228 __Pdlpp__
229
230 # pp code
231
232 "PDL::NiceSlice" and "Inline::Pdlpp"
233 There is currently an undesired interaction between PDL::NiceSlice and
234 "Inline::Pdlpp". Since PP code generally contains expressions of the
235 type "$var()" (to access piddles, etc) PDL::NiceSlice recognizes those
236 incorrectly as slice expressions and does its substitutions. For the
237 moment (until hopefully the parser can deal with that) it is best to
238 explicitly switch PDL::NiceSlice off before the section of inlined
239 Pdlpp code. For example:
240
241 use PDL::NiceSlice;
242 use Inline::Pdlpp;
243
244 $a = sequence 10;
245 $a(0:3)++;
246 $a->inc;
247
248 no PDL::NiceSlice;
249
250 __DATA__
251
252 __C__
253
254 ppdef (...); # your full pp definition here
255
257 Brian Ingerson for creating the Inline infrastructure.
258
260 Christian Soeller <soellermail@excite.com>
261
263 PDL
264
265 PDL::PP
266
267 Inline
268
269 Inline::C
270
272 Copyright (c) 2001. Christian Soeller. All rights reserved.
273
274 This program is free software; you can redistribute it and/or modify it
275 under the same terms as PDL itself.
276
277 See http://pdl.perl.org
278
279
280
281perl v5.30.0 2019-09-05 Pdlpp(3)