Skip to content

Commit

Permalink
prevent type-conversion of output ndarray with parent already
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Dec 18, 2024
1 parent b113868 commit 5e7f2a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/PDL/Core/pdlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,14 +1081,13 @@ pdl_trans *pdl_create_trans(pdl_transvtable *vtable) {

pdl_error pdl_type_coerce(pdl_trans *trans) {
pdl_error PDL_err = {0, NULL, 0};
PDL_Indx i;
pdl_transvtable *vtable = trans->vtable;
pdl **pdls = trans->pdls;
trans->__datatype = -1;
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;
PDL_Indx i, nparents = vtable->nparents, nchildren = vtable->npdls - 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 */
Expand Down Expand Up @@ -1132,6 +1131,8 @@ pdl_error pdl_type_coerce(pdl_trans *trans) {
pdl->datatype = new_dtype;
} else if (new_dtype != pdl->datatype) {
PDLDEBUG_f(printf("pdl_type_coerce (%s) pdl=%"IND_FLAG" from %d to %d\n", vtable->name, i, pdl->datatype, new_dtype));
if (i >= nparents && pdl->trans_parent && pdl->trans_parent != trans)
return pdl_make_error(PDL_EFATAL, "%s: cannot convert output ndarray %s from type %d to %d with parent", vtable->name, vtable->par_names[i], pdl->datatype, new_dtype);
pdl = pdl_get_convertedpdl(pdl, new_dtype);
if (!pdl)
return pdl_make_error(PDL_EFATAL, "%s got NULL pointer from get_convertedpdl on param %s", vtable->name, vtable->par_names[i]);
Expand Down
10 changes: 8 additions & 2 deletions t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,14 @@ my $oneway_slice = $y->slice('0:1');
is_pdl $oneway_slice, pdl '[4 5]';
eval {$oneway_slice .= 11};
isnt $@, '', 'error on assigning into one-way slice';
my $c = $y->flowing->_convert_int(cdouble->enum);
ok $c->fflows, 'flowing -> converted has "flowing" on';
ok $y->flowing->_convert_int(cdouble->enum)->fflows, 'flowing -> converted has "flowing" on';
}

{
eval {czip(float(3), float(2), cdouble(0)->slice(''))};
like $@, qr/convert output ndarray.*with.*parent/;
czip(float(3), float(2), my $out_cd = cdouble(0));
is_pdl $out_cd, cdouble('3+2i');
}

{
Expand Down

0 comments on commit 5e7f2a6

Please sign in to comment.