.pptest/sub/tests.pd

filter: Statementstmt 100% 36 / 36 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 1 / 2 Podpod 0.0% 0 / 1 totaltotal 94.8% 37 / 39 CC 1 SCAR 0.0
CC
1
Cov
100%
__ANON__
1.0
myfunc
1.0
CRAP 1.0
« lib/PDL/Slices-pp-slice.c ↑ Summary .pptest/sub/Tests.pm »
1 # make sure the deprecation mechanism throws warnings
2 2 pp_deprecate_module( infavor => "PDL::Test::Fancy" );
3 2 our $VERSION = '0.01'; # so the Makefile.PL's VERSION_FROM picks it up
4 2 pp_setversion(qq{'0.01'}); # this doesn't use $VERSION only to check a bug is fixed
5 2 ▶pp_add_macros(SUCC => sub { "($_[0] + 1)" });
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 2 pp_addhdr('
8 void ppcp(PDL_Byte *dst, PDL_Byte *src, int len);
9 ');
10  
11 # test the $P vaffine behaviour
12 # when 'phys' flag is in.
13 2 pp_def('foop',
14 Pars => 'byte [phys]a1(n); byte [o,phys]b(n)',
15 GenericTypes => [B],
16 Code => 'ppcp($P(b),$P(a1),$SIZE(n));',
17 Doc => '
18  
19 =for ref
20  
21 Sample standard deviation.
22  
23 =cut
24 ',
25 );
26  
27 # test single-used phys dim of 1 ok
28 2 pp_def('foop1',
29 Pars => 'byte a1(z); byte [o,phys]b(n)',
30 GenericTypes => [B],
31 Code => 'ppcp($P(b),$P(a1),$SIZE(n));',
32 );
33  
34 # float qualifier
35 # and also test if numerals in variable name work
36 2 pp_def(
37 'fsumover',
38 Pars => 'a1(n); float [o]b();',
39 GenericTypes => ['D'],
40 Code => 'PDL_Float tmp = 0;
41 loop(n) %{ tmp += $a1(); %}
42 $b() = tmp;'
43 );
44  
45 # test GENERIC with type+ qualifier
46 2 pp_def(
47 'nsumover',
48 Pars => 'a(n); int+ [o]b();',
49 GenericTypes => [qw(B S U L F D)],
50 Code => '$GENERIC(b) tmp = 0;
51 loop(n) %{ tmp += $a(); %}
52 $b() = tmp;'
53 );
54  
55 2 pp_def("gelsd",
56 Pars => '[io,phys]A(m,n); [io,phys]B(p,q); [phys]rcond(); [o,phys]s(r=CALC(PDLMIN($SIZE(m),$SIZE(n)))); int [o,phys]rank();int [o,phys]info()',
57 GenericTypes => ['F'],
58 Code => '$CROAK("croaking");'
59 );
60  
61 2 pp_def('succ',
62 Pars => 'a(); [o] b()',
63 GenericTypes => ['F'],
64 Code => '$b() = $SUCC($a());',
65 );
66  
67 # test whitespace problem with POD and pp_addxs
68 2 pp_addxs( '', <<'EOXS' );
69  
70 int
71 just_one()
72 CODE:
73 RETVAL = 1;
74 OUTPUT:
75 RETVAL
76  
77 =pod
78  
79 =begin comment
80  
81 A comment.
82  
83 =end comment
84  
85 =cut
86  
87 EOXS
88  
89 # test whitespace problem with pp_line_numbers and pp_add_boot
90 2 pp_add_boot pp_line_numbers(__LINE__, q{
91 /* nothing happening here */
92 });
93  
94 # test XS args with OtherPars
95 2 pp_def('gl_arrows',
96 Pars => 'coords(tri=3,n); int indsa(); int indsb();',
97 GenericTypes => ['F'],
98 OtherPars => 'float headlen; float width;',
99 Code => ';', # do nothing
100 );
101  
102 # test XS args with funky Pars ordering
103 2 pp_def('polyfill_pp',
104 Pars => 'int [io] im(m,n); float ps(two=2,np); int col()',
105 GenericTypes => ['F'],
106 Code => ';', # do nothing
107 );
108  
109 # test valid non-single-letter GenericTypes arg
110 2 pp_def("rice_compress",
111 Pars => 'in(n); [o]out(m); int[o]len(); lbuf(n)',
112 GenericTypes =>['B','S','US','L'],
113 Code => ';', # do nothing
114 );
115  
116 2 pp_def('output_op',
117 Pars => 'in(n=2)',
118 OtherPars => '[o] PDL_Anyval v0; [o] PDL_Anyval v1',
119 GenericTypes => ['F'],
120 Code => '
121 pdl_datatypes dt = $PDL(in)->datatype;
122 ANYVAL_FROM_CTYPE($COMP(v0), dt, $in(n=>0));
123 ANYVAL_FROM_CTYPE($COMP(v1), dt, $in(n=>1));
124 ',
125 );
126 2 pp_def('output_op2',
127 Pars => 'in(n=2); [o] out()',
128 OtherPars => '[o] PDL_Anyval v0; [o] PDL_Anyval v1',
129 GenericTypes => ['F'],
130 Code => '
131 pdl_datatypes dt = $PDL(in)->datatype;
132 ANYVAL_FROM_CTYPE($COMP(v0), dt, $in(n=>0));
133 ANYVAL_FROM_CTYPE($COMP(v1), dt, $in(n=>1));
134 ',
135 );
136 2 pp_def('output_op3',
137 Pars => 'in(n=2); [o] out()',
138 OtherPars => '[o] PDL_Anyval v0; [o] PDL_Anyval v1',
139 GenericTypes => ['F'],
140 Code => '
141 pdl_datatypes dt = $PDL(in)->datatype;
142 ANYVAL_FROM_CTYPE($COMP(v0), dt, $in(n=>0));
143 ANYVAL_FROM_CTYPE($COMP(v1), dt, $in(n=>1));
144 ',
145 PMCode => 'sub PDL::output_op3 { goto &PDL::_output_op3_int }',
146 );
147  
148 2 pp_def('incomp_dim',
149 Pars => '[o] a();',
150 OtherPars => 'PDL_Indx d[];',
151 GenericTypes => ['F'],
152 Code => '$a() = $COMP(d_count);',
153 );
154  
155 2 pp_addhdr('
156 typedef NV NV_ADD1;
157 typedef HV* NV_HR;
158 typedef char thing;
159 ');
160 2 pp_add_typemaps(string=><<'EOT');
161 TYPEMAP
162 NV_ADD1 T_NV_ADD1
163 NV_HR T_HVREF
164 thing* T_PTROBJ
165  
166 INPUT
167 T_NV_ADD1
168 $var = SvNV($arg) + 1
169  
170 OUTPUT
171 T_NV_ADD1
172 sv_setnv($arg, $var - 1);
173 EOT
174  
175 2 pp_def('typem',
176 Pars => 'int [o] out()',
177 OtherPars => '[io] NV_ADD1 v1; NV_HR v2; thing *ptr',
178 GenericTypes => ['F'],
179 Code => '$out() = $COMP(v1); $COMP(v1) = 8;',
180 );
181  
182 2 pp_def('incomp_in',
183 Pars => '[o] out()',
184 OtherPars => 'pdl *ins[]',
185 GenericTypes => ['F'],
186 RedoDimsCode => <<'EOC',
187 pdl **ins = $COMP(ins);
188 PDL_Indx i;
189 for (i = 0; i < $COMP(ins_count); i++) {
190 pdl *in = ins[i];
191 PDL_RETERROR(PDL_err, PDL->make_physdims(in));
192 if (in->ndims != 1)
193 $CROAK("input ndarray %"IND_FLAG" has %"IND_FLAG" dims, not 1", i, in->ndims);
194 if (!$PRIV(bvalflag) && (in->state & PDL_BADVAL)) $PRIV(bvalflag) = 1;
195 }
196 EOC
197 Code => <<'EOC',
198 pdl **ins = $COMP(ins);
199 PDL_Indx i;
200 for (i = 0; i < $COMP(ins_count); i++)
201 PDL_RETERROR(PDL_err, PDL->make_physical(ins[i]));
202 $out() = 0;
203 for (i = 0; i < $COMP(ins_count); i++) {
204 pdl *in = ins[i];
205 PDL_Indx j;
206 #define X_CAT_INNER(datatype_in, ctype_in, ppsym_in, ...) \
207 PDL_DECLARE_PARAMETER_BADVAL(ctype_in, in, (in), 1, ppsym_in) \
208 for(j=0; j<in->nvals; j++) { \
209 if ($PRIV(bvalflag) && PDL_ISBAD2(in_datap[j], in_badval, ppsym_in, in_badval_isnan)) continue; \
210 $out() += in_datap[j]; \
211 }
212 PDL_GENERICSWITCH(PDL_TYPELIST_ALL, in->datatype, X_CAT_INNER, $CROAK("Not a known data type code=%d", in->datatype))
213 #undef X_CAT_INNER
214 }
215 EOC
216 );
217  
218 2 pp_def('incomp_out',
219 Pars => 'in(n)',
220 OtherPars => 'PDL_Indx howmany; [o] pdl *outs[]',
221 GenericTypes => ['F'],
222 HandleBad => 1,
223 CallCopy => 0,
224 GenericTypes => [PDL::Types::ppdefs_all()],
225 Code => <<'EOC',
226 pdl **outs = malloc(($COMP(outs_count) = $COMP(howmany)) * sizeof(pdl*));
227 $COMP(outs) = outs;
228 PDL_Indx i, ndims = $PDL(in)->ndims, dims[ndims];
229 for (i = 0; i < ndims; i++) dims[i] = $PDL(in)->dims[i];
230 for (i = 0; i < $COMP(outs_count); i++) {
231 pdl *o = outs[i] = PDL->pdlnew();
232 if (!o) { for (i--; i >= 0; i--) PDL->destroy(outs[i]); free(outs); $CROAK("Failed to create ndarray"); }
233 o->datatype = $PDL(in)->datatype;
234 PDL_err = PDL->setdims(o, dims, ndims);
235 if (PDL_err.error) { for (; i >= 0; i--) PDL->destroy(outs[i]); free(outs); return PDL_err; }
236 PDL_err = PDL->allocdata(o);
237 if (PDL_err.error) { for (; i >= 0; i--) PDL->destroy(outs[i]); free(outs); return PDL_err; }
238 PDL_DECLARE_PARAMETER_BADVAL($GENERIC(in), o, (o), 1, $PPSYM(in))
239 loop(n) %{ o_datap[n] = $in(); %}
240 }
241 EOC
242 );
243  
244 2 pp_def('index_prec', # check $a(n=>x+1) works
245 Pars => 'in(n); [o]out()',
246 GenericTypes => ['F'],
247 Code => 'loop (n) %{ if (n > 1) $out() += $in(n=>n-1); %}',
248 );
249  
250 2 pp_def("diff_central",
251 Pars => 'double x(); double [o] res();',
252 GenericTypes => ['F'],
253 OtherPars => 'SV* function;',
254 Code => ';',
255 );
256  
257 # previously in t/inline-comment-test.t
258 2 ▶pp_addpm(pp_line_numbers(__LINE__-1, q{ sub myfunc { } }));
Subroutine myfunc: not called CC=1 SCAR=0.0
Pod undocumented
259  
260 2 pp_def('testinc',
261 Pars => 'a(); [o] b()',
262 GenericTypes => ['F'],
263 Code => q{
264 /* emulate user debugging */
265 /* Why doesn't this work???!!!! */
266 threadloop %{
267 /* printf(" %f, %f\r", $a(), $b());
268 printf(" Here\n");
269 */
270 /* Sanity check */
271 $b() = $a() + 1;
272 %}
273 },
274 );
275  
276 # make sure that if the word "broadcastloop" appears, later automatic broadcastloops
277 # will not be generated, even if the original broadcastloop was commented-out
278  
279 2 pp_def('testinc2',
280 Pars => 'a(); [o] b()',
281 GenericTypes => ['F'],
282 Code => q{
283 /* emulate user debugging */
284 /* Why doesn't this work???!!!! */
285 /* threadloop %{
286 printf(" %f, %f\r", $a(), $b());
287 printf(" Here\n");
288 %}
289 */
290 /* Sanity check */
291 $b() = $a() + 1;
292 },
293 );
294  
295 2 pp_def('or2',
296 Pars => 'a(); b(); [o]c();',
297 OtherPars => 'int swap; char *ign; int ign2',
298 OtherParsDefaults => { swap => 0, ign=>'""', ign2=>0 },
299 GenericTypes => ['F'],
300 ArgOrder => 1,
301 Code => '$c() = $a() | $b();',
302 GenericTypes => [qw(A B S U L K N P Q)],
303 );
304  
305 # from HMM
306 2 pp_def('logadd',
307 Pars => 'a(); b(); [o]c()',
308 GenericTypes => [qw(F D LD)],
309 Inplace=>['a'], ##-- can run inplace on a()
310 Code => ';',
311 );
312  
313 2 pp_def('ftr',
314 Pars => 'a()',
315 GenericTypes => ['F'],
316 OtherPars => 'char* filename; int Loops; int Delay',
317 OtherParsDefaults => {Loops=>0, Delay=>4},
318 Code => 'sv_setiv(perl_get_sv("main::DelayVAL",TRUE), $COMP(Delay));',
319 FtrCode => " sv_setiv(perl_get_sv(\"main::FOOTERVAL\",TRUE), 1);\n",
320 );
321  
322 2 pp_def('ftrPM',
323 Pars => 'a(); [o]b()',
324 GenericTypes => ['F'],
325 Code => ';',
326 HdrCode => " sv_setiv(perl_get_sv(\"main::HEADERVAL\",TRUE), 1);\n",
327 FtrCode => " sv_setiv(perl_get_sv(\"main::FOOTERVAL\",TRUE), 1);\n",
328 PMCode => <<'EOPM',
329 sub PDL::ftrPM {
330 my ($a, $b) = @_;
331 $b //= PDL->null;
332 PDL::_ftrPM_int($a, $b);
333 $b;
334 }
335 EOPM
336 );
337  
338 1 pp_done;
339  
340 # this tests the bug with a trailing comment and *no* newline
« lib/PDL/Slices-pp-slice.c ↑ Summary .pptest/sub/Tests.pm »