diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2023-12-27 17:46:18 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2023-12-27 17:46:18 -0600 |
| commit | 840f463239073514527d59737eaf24e45b5ff5ab (patch) | |
| tree | 21377f5866ca7cd028adba03345c230a8ddfb82b | |
| parent | f9c88dbbb1e13bfb63f40d0dd3b8630850655d7b (diff) | |
| download | perlweeklychallenge-club-840f463239073514527d59737eaf24e45b5ff5ab.tar.gz perlweeklychallenge-club-840f463239073514527d59737eaf24e45b5ff5ab.tar.bz2 perlweeklychallenge-club-840f463239073514527d59737eaf24e45b5ff5ab.zip | |
Yet another solution using FFT
| -rwxr-xr-x | challenge-248/wlmb/perl/ch-2b.pl | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/challenge-248/wlmb/perl/ch-2b.pl b/challenge-248/wlmb/perl/ch-2b.pl new file mode 100755 index 0000000000..1640bcddd7 --- /dev/null +++ b/challenge-248/wlmb/perl/ch-2b.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +use v5.36; +use PDL; +use PDL::FFT; +my $matrix=pdl(shift); +my $width=my $w=shift; +my $height=my $h=shift; +my $small=ones($w%2?$w:$w+1, $h%2?$h:$h+1); +$small->slice(-1).=0, ++$w unless $w%2; # zero row and/or column for even kernels +$small->slice([],-1).=0, ++$h unless $h%2; +my $kernel=kernctr($matrix, $small); #full kernel +my $result=$matrix->copy; +$result->fftconvolve($kernel); +say "$matrix $width $height -> ", +$result->slice([floor(($width-1)/2),floor(-($width+1)/2)], + [floor(($height-1)/2),floor(-($height+1)/2)]); |
