Skip to content

Commit

Permalink
Allow an ndarray as Center in rvals
Browse files Browse the repository at this point in the history
  • Loading branch information
wlmb committed Jan 31, 2025
1 parent a47768e commit a22bf7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/PDL/Basic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ our @EXPORT_OK = qw/ ndcoords rvals axisvals allaxisvals xvals yvals zvals sec i
our %EXPORT_TAGS = (Func=>[@EXPORT_OK]);

# Exportable functions
*axisvals = \&PDL::axisvals;
*allaxisvals = \&PDL::allaxisvals;
*sec = \&PDL::sec;
*ins = \&PDL::ins;
*hist = \&PDL::hist;
*whist = \&PDL::whist;
*axisvals = \&PDL::axisvals;
*allaxisvals = \&PDL::allaxisvals;
*sec = \&PDL::sec;
*ins = \&PDL::ins;
*hist = \&PDL::hist;
*whist = \&PDL::whist;
*similar_assign = \&PDL::similar_assign;
*transpose = \&PDL::transpose;
*xlinvals = \&PDL::xlinvals;
Expand Down Expand Up @@ -530,7 +530,7 @@ Fills an ndarray with radial distance values from some centre.
Centre => [$x,$y,$z...] # Specify centre
Center => [$x,$y.$z...] # synonym.
Center => $c # as 1d array
Squared => 1 # return distance squared (i.e., don't take the square root)
=for example
Expand All @@ -552,6 +552,10 @@ on an exact pixel point in the data. For dimensions of even size,
that means the midpoint is shifted by 1/2 pixel from the true center
of that dimension.
If C<Center> has less components than the number of dimensions of the
array, its remaining components are computed as above. If it has more,
a warning is issued.
Also note that the calculation for C<rvals> for integer values
does not promote the datatype so you will have wraparound when
the value calculated for C< r**2 > is greater than the datatype
Expand Down Expand Up @@ -588,9 +592,11 @@ sub PDL::rvals { # Return radial distance from given point and offset
}, $opt ) : ();
my $r = &PDL::Core::_construct;
my @pos;
@pos = @{$opt{CENTRE}} if defined $opt{CENTRE};
if(defined $opt{CENTRE}){
@pos = ref $opt{CENTRE} eq "ARRAY"? @{$opt{CENTRE}} : $opt{CENTRE}->list;
}
warn "Center has more coordinates than dimensions of ndarray" if @pos > $r->getndims;
my $offset;

$r .= 0.0;
my $tmp = $r->copy;
my $i;
Expand Down
1 change: 1 addition & 0 deletions t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ is_pdl rvals(3,3,{centre=>[2,2]}), $x1->sqrt, "non-centered rvals";
is_pdl rvals(3,3,{center=>[2,2]}), $x1->sqrt, "centre/center synonyms";
is_pdl rvals(3,3,{ceNteR=>[2,2]}), $x1->sqrt, "ceNteR option capitalization";
is_pdl rvals(3,3,{center=>[2,2],squared=>1}), $x1, "both center and squared options";
is_pdl rvals(3,3,{center=>pdl(2,2)}), $x1->sqrt, "rvals with center as ndarray";

is_pdl ndcoords(2,2), pdl('[0 0; 1 0] [0 1; 1 1]');
is_pdl PDL::Basic::ndcoords(2,2), pdl('[0 0; 1 0] [0 1; 1 1]');
Expand Down

0 comments on commit a22bf7a

Please sign in to comment.