Skip to content

Commit

Permalink
more qsort tests with badvals, zap now-in-core output-dim check
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 1, 2024
1 parent ec346f1 commit b0b1b99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
18 changes: 5 additions & 13 deletions Basic/Ufunc/ufunc.pd
Original file line number Diff line number Diff line change
Expand Up @@ -981,14 +981,7 @@ sub PDL::$_->[0]pct {
EOD
}

sub qsort_croak {
my ($out, $insizedim, $outsizedim) = @_;
'if ($PDL(a)->dims['.$insizedim.'] != $PDL('.$out.')->dims['.$outsizedim.'] && $PDL(a)->dims['.$insizedim.'] > 1)
/* last term detects non-trivial sort */
$CROAK("You likely passed a scalar argument, when you should have passed an ndarray (or nothing at all)");
if ($PDL(a)->nvals == 0) return PDL_err;
'
}
sub qsort_returnempty { 'if ($PDL(a)->nvals == 0) return PDL_err;' }

# move all bad values to the end of the array
pp_def(
Expand All @@ -999,7 +992,7 @@ pp_def(
Code =>
'register PDL_Indx nn = 0;
PDL_IF_BAD(register PDL_Indx nb = $SIZE(n) - 1;,)
'.qsort_croak('b',0,0).'
'.qsort_returnempty().'
loop(n) %{
PDL_IF_BAD(if ($ISBAD(a())) { $SETBAD(b(n=>nb)); nb--; }
else,) { $b(n=>nn) = $a(); nn++; }
Expand Down Expand Up @@ -1040,8 +1033,7 @@ pp_def(
Pars => 'a(n); indx [o]indx(n);',
Code =>
'register PDL_Indx nn = PDL_IF_BAD(0,$SIZE(n)-1), nb = $SIZE(n) - 1;
if ($SIZE(n) == 0) return PDL_err;
'.qsort_croak('indx',0,0).'
'.qsort_returnempty().'
loop(n) %{
PDL_IF_BAD(if ($ISBAD(a())) { $indx(n=>nb) = n; nb--; }
else { $indx(n=>nn) = n; nn++; } /* play safe since nn used more than once */
Expand Down Expand Up @@ -1082,7 +1074,7 @@ pp_def(
'register PDL_Indx nn = PDL_IF_BAD(0,$SIZE(m)-1), nb = $SIZE(m) - 1;
char is_inplace = ($P(a) == $P(b));
PDL_Indx nd = $SIZE(n);
'.qsort_croak('b',1,1).'
'.qsort_returnempty().'
PDL_IF_BAD(loop(m) %{
char allgood_a = 1;
loop(n) %{ if ( $ISBAD(a()) ) { allgood_a = 0; break; } %}
Expand Down Expand Up @@ -1165,7 +1157,7 @@ pp_def(
Code =>
'register PDL_Indx nn = PDL_IF_BAD(0,$SIZE(m)-1), nb = $SIZE(m) - 1;
PDL_Indx nd = $SIZE(n);
'.qsort_croak('indx',1,0).'
'.qsort_returnempty().'
loop(m) %{
PDL_IF_BAD(
char allgood_a = 1;
Expand Down
4 changes: 4 additions & 0 deletions Basic/t/ufunc.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ my $c = cat($x,$x);
my $c_sort = $c->qsort;
my $d = sequence(10)->rotate(1);
my $d_sort = $d->qsort;
is_pdl $d_sort, sequence(10);
my $e = pdl([[1,2],[0,500],[2,3],[4,2],[3,4],[3,5]]);
my $e_sort = $e->qsortvec;

Expand All @@ -51,7 +52,10 @@ ok( ( eval { pdl([])->qsorti }, $@ eq '' ), "qsorti coredump,[SF bug 2110074]");
$d->inplace->qsort;
is_pdl $d, $d_sort, "inplace sorting";
$d->setbadat(3);
is_pdl $d, pdl('0 1 2 BAD 4 5 6 7 8 9');
$d_sort = $d->qsort;
is_pdl $d_sort, pdl('0 1 2 4 5 6 7 8 9 BAD');
is_pdl $d_sort->qsort, pdl('0 1 2 4 5 6 7 8 9 BAD'), 'qsort with bad already end';
$d->inplace->qsort;
ok(all($d == $d_sort), "inplace sorting with bad values");

Expand Down
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3554,7 +3554,7 @@ Summary of Changes:
(help setops).

* PDL::IO::GD module interface to the GD runtime image
libaray (http://www.boutell.com/gd/) has been integrated.
library (http://www.boutell.com/gd/) has been integrated.

* The PDL::GIS::Proj and PDL::Transform::Proj4 modules
to interface to the PROJ4 Cartographic Projections
Expand Down

0 comments on commit b0b1b99

Please sign in to comment.