From 65cd714022e3e928929faaba9d344b7cded094ff Mon Sep 17 00:00:00 2001 From: Ed J Date: Mon, 23 Dec 2024 18:07:50 +0000 Subject: [PATCH] capture current wrong type-convert behaviour when flowing - #511 --- .github/workflows/cygwin.yml | 2 +- t/core.t | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cygwin.yml b/.github/workflows/cygwin.yml index 63207ca8b..7e0ef08aa 100644 --- a/.github/workflows/cygwin.yml +++ b/.github/workflows/cygwin.yml @@ -1,4 +1,4 @@ -name: perl +name: Cygwin on: push: branches: diff --git a/t/core.t b/t/core.t index 2f85fb06f..2673825f0 100644 --- a/t/core.t +++ b/t/core.t @@ -818,6 +818,54 @@ $cf++; is_pdl $x, pdl(2..4); } +{ +my $o_float = PDL::plus(float(1), float(2)); +is_pdl $o_float, float(3); +# 3-arg is (a,b,swap); 4-arg is (a,b,output,swap) +PDL::plus(float(1), float(2), $o_float = null, 0); +is_pdl $o_float, float(3); +PDL::plus(float(1), float(2), my $o_double = double(0), 0); +is_pdl $o_double, pdl(3); +is 0+$o_double->trans_children, 0, 'no trans_children from non-flowing'; + +PDL::plus(my $i_float = float(1)->flowing, float(2), $o_double = double(0), 0); +is +($i_float->trans_children)[0]->vtable->name, 'converttypei_new', 'input trans_children[0] is convert output type > inputs'; +is_pdl $o_double, pdl(3); +is $o_double->trans_parent->vtable->name, 'PDL::Ops::plus', 'right trans_parent from flowing output type > inputs'; +is 0+$o_double->trans_children, 0, '0 trans_children on output from flowing'; + +PDL::plus(my $i_double = double(1)->flowing, double(2), $o_float = float(0), 0); +is +($i_double->trans_children)[0]->vtable->name, 'PDL::Ops::plus', 'current trans_children[0] is NOT convert on input from flowing output type < inputs'; +is_pdl $o_float, float(0), 'current output wrongly 0 from flowing output type < inputs'; +is $o_float->trans_parent, undef, 'current no trans_parent from flowing output type < inputs'; +is 0+$o_float->trans_children, 1, 'current 1 trans_children from flowing output type < inputs'; +is +($o_float->trans_children)[0]->vtable->name, 'converttypei_new', 'current trans_children[0] is convert output type < inputs'; + +eval {PDL::plus(double(1)->flowing, double(2), float(0)->slice(''), 0)}; +is $@, '', "current no error when flowing output to flowing xform, out type < input"; + +for ([\&float,\&cfloat,\&cdouble], [\&double,\&cdouble,\&cfloat], [\&ldouble,\&cldouble]) { + my ($rt, $ct, $other_ct) = @$_; + my $o_cmplx = czip($rt->(3), $rt->(2)); + is_pdl $o_cmplx, $ct->('3+2i'), 'right answer from no supplied output '.$rt->(); + czip($rt->(3), $rt->(2), $o_cmplx = $ct->(0)); + is_pdl $o_cmplx, $ct->('3+2i'), 'right answer from supplied output '.$rt->(); + $o_cmplx = czip($rt->(3)->flowing, $rt->(2)); + is_pdl $o_cmplx, $ct->('3+2i'), 'right answer from flowing, no supplied output '.$rt->(); + czip($rt->(3)->flowing, $rt->(2), $o_cmplx = $ct->(0)); + if ($ct->() eq 'cldouble') { + is_pdl $o_cmplx, $ct->('3+2i'), 'right answer from flowing, supplied output '.$rt->(); + } else { + is_pdl $o_cmplx, $ct->(0), 'current wrong 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'; + next if !$other_ct; + czip($rt->(3)->flowing, $rt->(2), $o_cmplx = $other_ct->(0)); + is_pdl $o_cmplx, $other_ct->(0), 'current wrong answer from flowing, input '.$rt->().', supplied output '.$other_ct->(); +} +} + my $notouch = sequence(4); $notouch->set_donttouchdata; eval { $notouch->setdims([2,2]); $notouch->make_physical; };