Skip to content

Commit

Permalink
extra copy of output trans.pdls so CopyBadStatusCode hits original ou…
Browse files Browse the repository at this point in the history
…tputs
  • Loading branch information
mohawk2 committed Apr 16, 2022
1 parent f0591c9 commit bcd4ea3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Basic/Core/pdlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ pdl_error pdl_make_trans_mutual(pdl_trans *trans)
pdl_transvtable *vtable = trans->vtable;
pdl **pdls = trans->pdls;
PDL_Indx i, npdls=vtable->npdls, nparents=vtable->nparents;
PDL_Indx nchildren = npdls - nparents;
/* copy the converted outputs from the end-area to use as actual
outputs - cf type_coerce */
for (i=vtable->nparents; i<vtable->npdls; i++) pdls[i] = pdls[i+nchildren];
PDL_TR_CHKMAGIC(trans);
int pfflag=0;
PDL_err = pdl_trans_flow_null_checks(trans, &pfflag);
Expand Down Expand Up @@ -1066,7 +1070,9 @@ PDL_Anyval pdl_get_pdl_badvalue( pdl *it ) {
}

pdl_trans *pdl_create_trans(pdl_transvtable *vtable) {
size_t it_sz = sizeof(pdl_trans)+sizeof(pdl *)*vtable->npdls;
size_t it_sz = sizeof(pdl_trans)+sizeof(pdl *)*(
vtable->npdls + (vtable->npdls - vtable->nparents) /* outputs twice */
);
pdl_trans *it = malloc(it_sz);
if (!it) return it;
memset(it, 0, it_sz);
Expand Down Expand Up @@ -1104,6 +1110,11 @@ pdl_error pdl_type_coerce(pdl_trans *trans) {
char p2child_has_badvalue = (vtable->npdls == 2 && pdls[0]->has_badvalue
&& (vtable->par_flags[1] & PDL_PARAM_ISCREATEALWAYS));
PDL_Anyval parent_badvalue = p2child_has_badvalue ? pdls[0]->badvalue : (PDL_Anyval){PDL_INVALID, {0}};
PDL_Indx nchildren = vtable->npdls - vtable->nparents;
/* copy the "real" (passed-in) outputs to the end-area to use as actual
outputs, possibly after being converted, leaving the passed-in ones
alone to be picked up for use in CopyBadStatusCode */
for (i=vtable->nparents; i<vtable->npdls; i++) pdls[i+nchildren] = pdls[i];
for (i=0; i<vtable->npdls; i++) {
pdl *pdl = pdls[i];
short flags = vtable->par_flags[i];
Expand Down Expand Up @@ -1148,7 +1159,8 @@ pdl_error pdl_type_coerce(pdl_trans *trans) {
return pdl_make_error(PDL_EFATAL, "%s got NULL pointer from get_convertedpdl on param %s", vtable->name, vtable->par_names[i]);
if (pdl->datatype != new_dtype)
return pdl_make_error_simple(PDL_EFATAL, "type not expected value after get_convertedpdl\n");
pdls[i] = pdl;
/* if type-convert output, put in end-area */
pdls[i + (i >= vtable->nparents ? nchildren : 0)] = pdl;
}
}
return PDL_err;
Expand Down
12 changes: 12 additions & 0 deletions t/bad.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ use Test::Warn;
#
use constant ABSTOL => 1.0e-4;

{
my $a_bad = pdl double, '[1 BAD 3]';
my $b_double = zeroes double, 3;
$a_bad->assgn($b_double);
ok $b_double->badflag, 'b_double badflag set';
is $b_double.'', '[1 BAD 3]', 'b_double got badval';
my $b_float = zeroes float, 3;
$a_bad->assgn($b_float);
ok $b_float->badflag, 'b_float badflag set';
is $b_float.'', '[1 BAD 3]', 'b_float got badval';
}

# check default behaviour (ie no bad data)
# - probably overkill
#
Expand Down
4 changes: 4 additions & 0 deletions t/ufunc.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ my $p = pdl([]); $p->setdims([1,0]); $p->qsortvec; # shouldn't segfault!
my $p2d = pdl([[1,2],[3,4],[1,3],[1,2],[3,3]]);
is $p2d->dice_axis(1,$p2d->qsortveci).'', $p2d->qsortvec.'', "qsortveci";

my $ind_double = zeroes($p2d->dim(1));
$p2d->qsortveci($ind_double); # shouldn't segfault!
is $ind_double.'', '[3 0 2 4 1]';

eval { empty()->medover }; # shouldn't segfault
isnt $@, '', 'exception for percentile on empty ndarray';

Expand Down

1 comment on commit bcd4ea3

@mohawk2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests here (particularly in t/bad.t) capture the error found in the discussion of moocow-the-bovine/PDL-CCS#5 (and fix the most-important problem described therein) - the passed-in float-typed output was (as in current PDL::CCS with currently-released PDL) not getting its badflag set due to the wrong output ndarray getting its badflag set (and not propagated) by the CopyBadStatusCode in the ccs_accum_* operations.

Please sign in to comment.