@@ -3644,7 +3644,7 @@ sub PDL::where_both {
36443644*where_both = \&PDL::where_both;
36453645EOD
36463646
3647- pp_add_exported("", 'whereND');
3647+ pp_add_exported("", 'whereND whereND_both ');
36483648pp_addpm(<<'EOD');
36493649=head2 whereND
36503650
@@ -3670,7 +3670,7 @@ to the original data PDLs, for the purpose of dataflow.
36703670 $sdata = whereND $data, $mask
36713671 ($s1, $s2, ..., $sn) = whereND $d1, $d2, ..., $dn, $mask
36723672
3673- where
3673+ where
36743674
36753675 $data is M dimensional
36763676 $mask is N < M dimensional
@@ -3727,6 +3727,35 @@ sub PDL::whereND :lvalue {
37273727}
37283728*whereND = \&PDL::whereND;
37293729
3730+ =head2 whereND_both
3731+
3732+ =for ref
3733+
3734+ C<where_both> with support for ND masks and broadcasting
3735+
3736+ This works like L</whichND_both>, but data-flowing slices
3737+ rather than index-sets are returned.
3738+
3739+ C<whereND_both> differs from C<where_both> in that the mask
3740+ dimensionality is preserved which allows for
3741+ proper broadcasting of the selection operation over
3742+ higher dimensions.
3743+
3744+ As with C<where_both> the output PDLs are still connected
3745+ to the original data PDLs, for the purpose of dataflow.
3746+
3747+ =for usage
3748+
3749+ ($match_vals, $non_match_vals) = whereND_both($pdl, $mask);
3750+
3751+ =cut
3752+
3753+ sub PDL::whereND_both :lvalue {
3754+ barf "Usage: whereND_both(\$pdl, \$mask)\n" if @_ != 2;
3755+ my ($arr, $mask) = @_; # $mask has 0==false, 1==true
3756+ map $arr->indexND($_), PDL::whichND_both($mask);
3757+ }
3758+ *whereND_both = \&PDL::whereND_both;
37303759EOD
37313760
37323761pp_add_exported("", 'whichND whichND_both');
0 commit comments