Skip to content

Commit

Permalink
no typed outputs, and avail + non-avail typed inputs -> use last-give…
Browse files Browse the repository at this point in the history
…n - #511
  • Loading branch information
mohawk2 committed Jan 5, 2025
1 parent 82a9cd2 commit f749564
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- fix test that assumed acosh(0)->byte, i.e. nan()->byte, was always 0 (#514) - thanks @eserte for report
- separate PDL::Type POD documentation
- partly restoring pre-2.096 xform type-selection: if xform given no typed outputs, and non-available (greater than last-given type) typed inputs, use last-given (#511, https://github.com/moocow-the-bovine/PDL-CCS/issues/18)

2.098 2025-01-03
- fix Windows build problems
Expand Down
9 changes: 7 additions & 2 deletions lib/PDL/Core/pdlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,19 +1140,24 @@ static inline pdl_error pdl__transtype_select(
*retval = vtable->gentypes[0]; /* only one allowed type, use that */
return PDL_err;
}
char use_last_dtype = 0;
for (i=vtable->npdls-1; i>= 0; i--) {
pdl *pdl = trans->pdls[i];
short flags = vtable->par_flags[i];
if (!(pdl->state & PDL_NOMYDIMS) &&
!(flags & (PDL_PARAM_ISIGNORE|PDL_PARAM_ISTYPED|PDL_PARAM_ISCREATEALWAYS))
) {
pdl_datatypes new_transtype = PDL_TYPE_ADJUST_FROM_SUPPLIED(pdl->datatype, flags);
if (new_transtype != PDL_INVALID && PDL_BITFIELD_ISSET(type_avail, new_transtype) && *retval < new_transtype)
char newtype_is_avail = PDL_BITFIELD_ISSET(type_avail, new_transtype);
if (!newtype_is_avail && new_transtype > last_dtype)
use_last_dtype = 1;
if (new_transtype != PDL_INVALID && newtype_is_avail && *retval < new_transtype)
*retval = new_transtype;
}
if (i == vtable->nparents && *retval != PDL_INVALID) return PDL_err;
}
if (*retval == PDL_INVALID || !PDL_BITFIELD_ISSET(type_avail, *retval)) *retval = last_dtype;
if (use_last_dtype || *retval == PDL_INVALID || !PDL_BITFIELD_ISSET(type_avail, *retval))
*retval = last_dtype;
return PDL_err;
}

Expand Down
8 changes: 6 additions & 2 deletions t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ $double_mask &= double('1 1 1 1 1 0 0');
is_pdl $double_mask, double('0 0 1 1 1 0 0');

eval {PDL::eqvec(double([1,2]), double([1,2]), float(0)->slice(''))};
like $@, qr/cannot convert/, "error when flowing output to xform, out forcetype != supplied out type";
like $@, qr/cannot convert/, "error when flowing xform given non-available-typed output with parent";

PDL::eqvec(double([1,2])->flowing, double([1,2]), $o_float = float(0));
is 0+$o_float->trans_children, 0, 'converted output of flowing xform has no trans_children';
Expand All @@ -873,6 +873,10 @@ is_pdl $o_byte, byte([1,1,0]), 'converted output of flowing xform has right valu
is_pdl $got, byte('0 1 1 2 2 2 2 2 2 2'), "convert of thing with trans_children no NULL data";
}

is_pdl PDL::and2(byte(3), byte(1)), byte(1), 'both input available-typed';
is_pdl PDL::and2(double(3), double(1)), longlong(1), 'both input non-available-typed';
is_pdl PDL::and2(byte(3), double(1)), longlong(1), 'inputs one avail, one non-available-typed -> last-given type';

for ([\&float,\&cfloat,\&cdouble], [\&double,\&cdouble,\&cfloat], [\&ldouble,\&cldouble]) {
my ($rt, $ct, $other_ct) = @$_;
my $o_cmplx = czip($rt->(3), $rt->(2));
Expand All @@ -884,7 +888,7 @@ for ([\&float,\&cfloat,\&cdouble], [\&double,\&cdouble,\&cfloat], [\&ldouble,\&c
czip($rt->(3)->flowing, $rt->(2), $o_cmplx = $ct->(0));
is_pdl $o_cmplx, $ct->('3+2i'), 'right answer from flowing, supplied output '.$rt->();
eval {czip($rt->(3)->flowing, $rt->(2), $ct->(0)->slice(''))};
is $@, '', 'current wrongly no error when supply output with parent to flowing '.$rt->();
is $@, '', 'no error when supply right-typed output with parent to flowing '.$rt->();
next if !$other_ct;
czip($rt->(3)->flowing, $rt->(2), $o_cmplx = $other_ct->(0));
is_pdl $o_cmplx, $other_ct->('3+2i'), 'right answer from flowing, input '.$rt->().', supplied output '.$other_ct->();
Expand Down

0 comments on commit f749564

Please sign in to comment.