Skip to content

Commit

Permalink
passing null as input param now an error
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Feb 2, 2022
1 parent 591ce77 commit 8af39ba
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions Basic/Core/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ a single Empty PDL, you get back the Empty PDL (no padding).
=for ref
Returns a 'null' ndarray.
It is an error to pass one of these as an input to a function.
=for usage
Expand Down
5 changes: 5 additions & 0 deletions Basic/Core/pdlthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ pdl_error pdl_dim_checks(
));
} else {
PDL_Indx *dims = pdl->dims;
if (pdl->state & PDL_NOMYDIMS)
return pdl_make_error(PDL_EUSERERROR,
"Error in %s: input parameter '%s' is null\n",
vtable->name, vtable->par_names[i]
);
if (ninds > 0 && ndims < ninds) {
/* Dimensional promotion when number of dims is less than required: */
for (j=0; j<ninds; j++) {
Expand Down
17 changes: 17 additions & 0 deletions Basic/Primitive/primitive.pd
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,23 @@ pp_def('append',
# note that ideally we want to say '$SIZE(mn) = $SIZE(m)+$SIZE(n);'
# but that requires placing RedoDimsParsedCode *after* assignment of
# childdims to $SIZE(XXX)!!! XXXXXmake that workXXXXX
PMCode => pp_line_numbers(__LINE__-1, '
sub PDL::append {
my ($i1, $i2, $o) = map PDL->topdl($_), @_;
if (grep $_->isempty, $i1, $i2) {
if (!defined $o) {
return $i2->copy if $i1->isempty;
return $i1->isnull ? PDL->zeroes(0) : $i1->copy;
} else {
$o .= $i2->isnull ? PDL->zeroes(0) : $i2, return $o if $i1->isempty;
$o .= $i1->isnull ? PDL->zeroes(0) : $i1, return $o;
}
}
$o //= PDL->null;
PDL::_append_int($i1, $i2, $o);
$o;
}
'),
RedoDimsCode => '
pdl * dpdla = $PDL(a);
pdl * dpdlb = $PDL(b);
Expand Down
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- PDL::Complex no longer undefs PDL::i
- passing null as input param now an error

2.072 2022-01-30
- fix bug in qsortveci that broke PDL::VectorValued - thanks @zmughal for report
Expand Down
14 changes: 12 additions & 2 deletions t/01-pptest.t
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ pp_deft('fooseg',
loop(n) %{ $b() = $a(); %}
');
# adapted from PDL::NDBin: if in=null and b is a scalar, was SEGV-ing
pp_deft( '_flatten_into',
Pars => "in(m); indx b(m); [o] idx(m)",
Code => '
loop(m) %{ $idx() = $in(); %}
',
);
pp_addhdr << 'EOH';
void tinplace_c1(int n, PDL_Float* data);
void tinplace_c2(int n, PDL_Float* data1, PDL_Float* data2);
Expand Down Expand Up @@ -300,16 +308,18 @@ is( join(',',$x->dims), "10" );
ok( tapprox($x,sequence(10)) );
# this used to segv under solaris according to Karl
{ no warnings 'uninitialized';
{
my $ny=7;
$x = double xvals zeroes (20,$ny);
test_fooseg $x, $y=null;
ok( 1 ); # if we get here at all that is alright
ok( tapprox($x,$y) )
or diag($x, "\n", $y);
}
eval { test__flatten_into(null, 2) };
ok 1; #was also segfaulting
# test the bug alluded to in the comments in
# pdl_changed (pdlapi.c)
# used to segfault
Expand Down
8 changes: 8 additions & 0 deletions t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ do {
$x = pdl(pdl(5));
ok all( $x== pdl(5)), "pdl() can piddlify an ndarray";

$x = pdl(null);
is_deeply [$x->dims], [0], 'pdl(null) gives empty' or diag "x(", $x->info, ")";
ok !$x->isnull, 'pdl(null) gives non-null' or diag "x(", $x->info, ")";

$x = pdl(null, null);
is_deeply [$x->dims], [0,2], 'pdl(null, null) gives empty' or diag "x(", $x->info, ")";
ok !$x->isnull, 'pdl(null, null) gives non-null' or diag "x(", $x->info, ")";

# pdl of mixed-dim pdls: pad within a dimension
$x = pdl( zeroes(5), ones(3) );
ok all($x == pdl([0,0,0,0,0],[1,1,1,0,0])),"Piddlifying two ndarrays concatenates them and pads to length" or diag("x=$x\n");
Expand Down
6 changes: 6 additions & 0 deletions t/primitive.t
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ ok($a1->at($x->list,$y->list,$z->list,$w->list) == 203, "whichND" );
$a1 = pdl(1,2,3,4);
my $b1 = append($a1,2);
ok(int(sum($b1))==12, "append");
$b1 = append(null, null);
ok !$b1->isnull, 'append(null, null) returns non-null';
ok $b1->isempty, 'append(null, null) returns an empty';
append(null, null, $b1);
ok !$b1->isnull, 'append(null, null, b1) sets non-null';
ok $b1->isempty, 'append(null, null, b1) sets an empty';

# clip tests
ok(tapprox($im->hclip(5)->sum,83), "hclip" );
Expand Down

0 comments on commit 8af39ba

Please sign in to comment.