diff --git a/Basic/Ops/ops.pd b/Basic/Ops/ops.pd index b71459300..1f2130494 100644 --- a/Basic/Ops/ops.pd +++ b/Basic/Ops/ops.pd @@ -121,13 +121,12 @@ EOF delete $extra{Comparison}; } - pp_addpm(make_overload($op, $name, $mutator)); my $bitwise = delete $extra{Bitwise}; + pp_addpm(make_overload($op, $name, $mutator, $bitwise)); pp_def($name, Pars => 'a(); b(); [o]c();', - OtherPars => 'int $swap'.($bitwise ? '; SV *$ign; int $ign2' : ''), - OtherParsDefaults => { swap => 0, ($bitwise ? (ign=>'&PL_sv_undef', ign2=>0) : ()) }, - ArgOrder => 1, + OtherPars => 'int $swap', + OtherParsDefaults => { swap => 0 }, HandleBad => 1, NoBadifNaN => 1, Inplace => [ 'a' ], # quick and dirty solution to get ->inplace do its job @@ -151,6 +150,9 @@ $doc \$c = PDL::$name(\$x, \$y); # explicit call with default swap of 0 \$c = PDL::$name(\$x, \$y, 0); # explicit call with explicit swap of 0 \$c = PDL::$name(\$x, \$y, 1); # explicit call with trailing 1 to swap args + PDL::$name(\$x, \$y, \$c, 1); # all params given + \$x->$name(\$y, \$c, 0); # method call, all params given + \$c = \$x->$name(\$y); # method call \$x->inplace->$name(\$y); # modify \$x inplace It can be made to work inplace with the C<< \$x->inplace >> syntax. @@ -164,8 +166,9 @@ EOD } # sub: biop() sub make_overload { - my ($op, $name, $mutator, $one_arg) = @_; + my ($op, $name, $mutator, $bitwise, $one_arg) = @_; my $ret; + my $bitwise_passon = $bitwise ? '$_[2]?@_[1,0]:@_[0,1]' : '@_'; if ($one_arg) { $ret = pp_line_numbers(__LINE__, < 'a(); b(); [o]c();', OtherPars => 'int $swap', OtherParsDefaults => { swap => 0 }, - ArgOrder => 1, Inplace => [ 'a' ], Code => pp_line_numbers(__LINE__-1, <ppsym.') %{$b() = c'.$func.$_->floatsuffix.'($a());%}', @Ctypes), ; } - pp_addpm(make_overload($funcov, $name, 0, 1)) if $overload; + pp_addpm(make_overload($funcov, $name, 0, 0, 1)) if $overload; # do not have to worry about propagation of the badflag when # inplace since only input ndarray is a, hence its badflag # won't change @@ -569,7 +571,7 @@ Returns the absolute value of a number. sub PDL::abs { $_[0]->type->real ? goto &PDL::_rabs : goto &PDL::_cabs } EOPM -pp_addpm(make_overload(qw(abs abs), 0, 1)); +pp_addpm(make_overload(qw(abs abs), 0, 0, 1)); pp_addpm(<<'EOPM'); diff --git a/Changes b/Changes index 4bf6ab0ae..8050aedb9 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ - add whichover, inspired by https://stackoverflow.com/questions/77551179/perl-pdl-indexing-and-which - random/randsym only produce real data - fix dataflow when vaffine ndarray is between modified and downstream (#461) - thanks @vadim-160102 for continued reporting +- revert the use of ArgOrder for PDL::Ops so op($a,$b,$c,$swap) works again as pre 2.082_01 2.085_01 2024-02-10 - test, document PDL::string, make more consistent (#459) - thanks @vadim-160102 for report diff --git a/t/ops.t b/t/ops.t index bdea63725..ae5c96484 100644 --- a/t/ops.t +++ b/t/ops.t @@ -21,6 +21,8 @@ for ( [$pa,$pb,\$pc, sub { ${$_[2]} = PDL::minus($_[0], $_[1]) }, [1,-1]], [$pa,$pb,\$pc, sub { ${$_[2]} = PDL::minus($_[0], $_[1], 0) }, [1,-1]], [$pa,$pb,\$pc, sub { ${$_[2]} = PDL::minus($_[0], $_[1], 1) }, [-1,1]], + [$pa,$pb,\$pc, sub { PDL::minus($_[0], $_[1], ${$_[2]}, 0) }, [1,-1]], + [$pa,$pb,\$pc, sub { PDL::minus($_[0], $_[1], ${$_[2]}, 1) }, [-1,1]], ) { my ($in1, $in2, $outref, $sub, $exp) = @$_; $sub->($in1, $in2, $outref);