From 840f463239073514527d59737eaf24e45b5ff5ab Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Wed, 27 Dec 2023 17:46:18 -0600 Subject: Yet another solution using FFT --- challenge-248/wlmb/perl/ch-2b.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 challenge-248/wlmb/perl/ch-2b.pl 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)]); -- cgit