Skip to content

Commit

Permalink
simplify topdl
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Feb 14, 2024
1 parent e81397a commit 0901fe9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Basic/Core/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,18 @@ below for usage).
$y = topdl $ndarray; # fall through
$x = topdl (1,2,3,4); # Convert 1D array
=cut

# Convert numbers to PDL if not already
sub PDL::topdl {
return $_[0]->new(@_[1..$#_]) if
@_ > 2 # PDLify a list
or ref(\$_[1]) eq 'SCALAR'
or ref($_[1]) eq 'ARRAY';
return $_[1] if blessed($_[1]); # Fall through
barf("Can not convert a ".ref($_[1])." to a ".$_[0]);
0;}

=head2 set_datatype
=for ref
Expand Down Expand Up @@ -2508,18 +2520,7 @@ sub PDL::nslice_if_pdl {
goto &PDL::slice;
}

# Convert numbers to PDL if not already

sub PDL::topdl {
return $_[0]->new(@_[1..$#_]) if($#_ > 1); # PDLify an ARRAY
return $_[1] if blessed($_[1]); # Fall through
return $_[0]->new($_[1]) if ref(\$_[1]) eq 'SCALAR' or
ref($_[1]) eq 'ARRAY';
barf("Can not convert a ".ref($_[1])." to a ".$_[0]);
0;}

# Convert everything to PDL if not blessed

sub alltopdl {
if (ref $_[2] eq 'PDL::Type') {
return convert($_[1], $_[2]) if blessed($_[1]);
Expand Down

0 comments on commit 0901fe9

Please sign in to comment.