From fee8947bf66ec0f2715d814fd85a4aabadee4c7e Mon Sep 17 00:00:00 2001 From: Ed J Date: Mon, 12 Feb 2024 18:07:34 +0000 Subject: [PATCH] not do mv if no-op --- Basic/Core/Basic.pm | 7 +++---- Libtmp/FFT/fft.pd | 8 ++++---- Libtmp/ImageND/imagend.pd | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Basic/Core/Basic.pm b/Basic/Core/Basic.pm index bf625b544..354957891 100644 --- a/Basic/Core/Basic.pm +++ b/Basic/Core/Basic.pm @@ -354,14 +354,13 @@ sub PDL::ndcoords { unshift(@d,$type) if defined($type); my $out = PDL->zeroes(@d); for my $d(0..$#dims) { - my $w = $out->index($d)->mv($d,0); + my $w = $out->index($d); + $w = $w->mv($d,0) if $d != 0; $w .= xvals($w); } $out; } -*ndcoords = \&PDL::ndcoords; -*allaxisvals = \&PDL::ndcoords; -*PDL::allaxisvals = \&PDL::ndcoords; +*ndcoords = *allaxisvals = *PDL::allaxisvals = \&PDL::ndcoords; =head2 hist diff --git a/Libtmp/FFT/fft.pd b/Libtmp/FFT/fft.pd index df9f8fe6f..10b60a9b7 100644 --- a/Libtmp/FFT/fft.pd +++ b/Libtmp/FFT/fft.pd @@ -289,8 +289,8 @@ sub PDL::fftnd { $i = $i->copy; foreach (0..$n) { fft($r,$i); - $r = $r->mv(0,$n); - $i = $i->mv(0,$n); + $r = $r->mv(0,$n) if 0 != $n; + $i = $i->mv(0,$n) if 0 != $n; } if (!$_[0]->type->real) { $_[0]= czip($r, $i); @@ -332,8 +332,8 @@ sub PDL::ifftnd { $n--; foreach (0..$n) { ifft($r,$i); - $r = $r->mv(0,$n); - $i = $i->mv(0,$n); + $r = $r->mv(0,$n) if 0 != $n; + $i = $i->mv(0,$n) if 0 != $n; } if (!$_[0]->type->real) { $_[0]= czip($r, $i); diff --git a/Libtmp/ImageND/imagend.pd b/Libtmp/ImageND/imagend.pd index 7afad1c2b..ed9542f98 100644 --- a/Libtmp/ImageND/imagend.pd +++ b/Libtmp/ImageND/imagend.pd @@ -317,10 +317,10 @@ sub PDL::rebin { } elsif ($odims[$i] != $idims[$i]) { # If something changes if (!($odims[$i] % $idims[$i])) { # Cells map 1 -> n my ($r) = $odims[$i]/$idims[$i]; - $y = $x->mv($i,0)->dupN($r); + $y = ($i==0 ? $x : $x->mv($i,0))->dupN($r); } elsif (!($idims[$i] % $odims[$i])) { # Cells map n -> 1 my ($r) = $idims[$i]/$odims[$i]; - $x = $x->mv($i,0); + $x = $x->mv($i,0) if $i != 0; # -> copy so won\'t corrupt input PDL $y = $x->slice("0:-1:$r")->copy; foreach (1..$r-1) { @@ -328,7 +328,7 @@ sub PDL::rebin { } $y /= $r; } else { # Cells map n -> m - &PDL::_rebin_int($x->mv($i,0), $y = null, $odims[$i]); + &PDL::_rebin_int(($i==0 ? $x : $x->mv($i,0)), $y = null, $odims[$i]); } $x = $y->mv(0,$i); }