Skip to content

Commit

Permalink
replace PDL::Lvalue pure-Perl entries with ":lvalue" decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 24, 2024
1 parent 0c78d13 commit 6a0fd8d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
14 changes: 5 additions & 9 deletions Basic/lib/PDL/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ positive indices.
=cut

sub PDL::dummy($$;$) {
sub PDL::dummy($$;$) :lvalue {
my ($pdl,$dim,$size) = @_;
barf("Missing position argument to dummy()") unless defined $dim; # required argument
$dim = $pdl->getndims+1+$dim if $dim < 0;
Expand Down Expand Up @@ -1737,7 +1737,7 @@ Data flows back and forth as usual with slicing routines.
=cut

sub PDL::clump {
sub PDL::clump :lvalue {
goto &PDL::_clump_int if @_ < 3;
my ($this,@dims) = @_;
my $ndims = $this->getndims;
Expand Down Expand Up @@ -1898,10 +1898,6 @@ Explicit broadcasting over specified dims using broadcast id 1.
$xx = $x->broadcast1(3,1)
=for example
Wibble
Convenience function interfacing to
L<PDL::Slices::broadcastI|PDL::Slices/broadcastI>.
Expand Down Expand Up @@ -2469,7 +2465,7 @@ and/or changed to "slice_if_pdl" for PDL 3.0.
=cut

sub PDL::nslice_if_pdl {
sub PDL::nslice_if_pdl :lvalue {
my ($pdl) = shift;
my ($orig_args) = pop;

Expand Down Expand Up @@ -2982,7 +2978,7 @@ then the connection is first severed.
=cut

*reshape = \&PDL::reshape;
sub PDL::reshape {
sub PDL::reshape :lvalue {
my $pdl = topdl($_[0]);
if (@_ == 2 && $_[1] == -1) { # a slicing reshape that drops 1-dims
return $pdl->slice( map $_==1 ? [0,0,0] : [], $pdl->dims);
Expand Down Expand Up @@ -3042,7 +3038,7 @@ Falls through if argument already == 1D.
=cut

*flat = \&PDL::flat;
sub PDL::flat { # fall through if < 2D
sub PDL::flat :lvalue { # fall through if < 2D
return my $dummy = $_[0]->getndims != 1 ? $_[0]->clump(-1) : $_[0];
}

Expand Down
4 changes: 1 addition & 3 deletions Basic/lib/PDL/Dbg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ For historical reasons C<vars> is an alias for C<px>.
=cut

sub px {
sub px :lvalue {
my $arg = shift;
my $str="";

Expand Down Expand Up @@ -145,8 +145,6 @@ Alias for C<px>
=cut

# make vars an alias
# I hope this works with inheritance
*vars = \&px;

1; # return success
Expand Down
9 changes: 4 additions & 5 deletions Basic/lib/PDL/Lvalue.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ use warnings;

# list of functions that can be used as lvalue subs
# extend as necessary
my @funcs = qw/ clump diagonal dice dice_axis dummy flat
index index2d indexND mv
my @funcs = qw/
index index2d mv
broadcast unbroadcast
nslice_if_pdl px
range rangeb reorder reshape sever slice
where whereND xchg /;
rangeb sever
xchg /;

my $prots = join "\n", map {"use attributes 'PDL', \\&PDL::$_, 'lvalue';"}
@funcs;
Expand Down
2 changes: 1 addition & 1 deletion Basic/lib/PDL/Primitive.pd
Original file line number Diff line number Diff line change
Expand Up @@ -3677,7 +3677,7 @@ broadcast over a smaller mask, for example.
=cut
sub PDL::where {
sub PDL::where :lvalue {
barf "Usage: where( \$pdl1, ..., \$pdlN, \$mask )\n" if @_ == 1;
my $mask = pop->flat->which;
@_ == 1 ? $_[0]->flat->index($mask) : map $_->flat->index($mask), @_;
Expand Down
14 changes: 7 additions & 7 deletions Basic/lib/PDL/Slices.pd
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ PDL, suitable for feeding to this.
=cut
sub PDL::indexND {
sub PDL::indexND :lvalue {
my($source,$index, $boundary) = @_;
return PDL::range($source,$index,undef,$boundary);
}
*PDL::indexNDb = \&PDL::indexND;
sub PDL::range {
sub PDL::range :lvalue {
my($source,$ind,$sz,$bound) = @_;
# Convert to indx type up front (also handled in rangeb if necessary)
my $index = (ref $ind && UNIVERSAL::isa($ind,'PDL') && $ind->type eq 'indx') ? $ind : indx($ind);
Expand Down Expand Up @@ -1545,7 +1545,7 @@ result PDL will change the parent.
=cut
sub PDL::reorder {
sub PDL::reorder :lvalue {
my ($pdl,@newDimOrder) = @_;
my $arrayMax = $#newDimOrder;
Expand Down Expand Up @@ -2036,7 +2036,7 @@ slice will change the parent (use the C<.=> operator).
=cut
sub PDL::dice {
sub PDL::dice :lvalue {
my $self = shift;
my @dim_indexes = @_; # array of dimension indexes
Expand Down Expand Up @@ -2112,7 +2112,7 @@ slice will change the parent.
=cut
sub PDL::dice_axis {
sub PDL::dice_axis :lvalue {
my($self,$axis,$idx) = @_;
my $ix = PDL->topdl($idx);
barf("dice_axis: index must be <=1D") if $ix->getndims > 1;
Expand Down Expand Up @@ -2287,7 +2287,7 @@ direct slicing even though the syntax is convenient.
$x->slice([-2,1]);
EOD-slice
PMCode => pp_line_numbers(__LINE__, <<'EOD-slice'),
sub PDL::slice {
sub PDL::slice :lvalue {
my ($source, @others) = @_;
for my $i(0..$#others) {
my $idx = $others[$i];
Expand Down Expand Up @@ -2502,7 +2502,7 @@ END
$SETDIMS();
'),
PMCode =>pp_line_numbers(__LINE__, <<'EOD'),
sub PDL::diagonal { shift->_diagonal_int(my $o=PDL->null, \@_); $o }
sub PDL::diagonal :lvalue { shift->_diagonal_int(my $o=PDL->null, \@_); $o }
EOD
Doc => <<'EOD',
=for ref
Expand Down

0 comments on commit 6a0fd8d

Please sign in to comment.