aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-12-28 00:41:28 +0000
committerGitHub <noreply@github.com>2023-12-28 00:41:28 +0000
commitec31914b19127e2702dcf4f105d307e8dd436235 (patch)
treeb513240a8d0d43af75e168687106e46b170db879
parent45ff3f1f9c53fbdbeb2d1b4a901a15717552fa82 (diff)
parent840f463239073514527d59737eaf24e45b5ff5ab (diff)
downloadperlweeklychallenge-club-ec31914b19127e2702dcf4f105d307e8dd436235.tar.gz
perlweeklychallenge-club-ec31914b19127e2702dcf4f105d307e8dd436235.tar.bz2
perlweeklychallenge-club-ec31914b19127e2702dcf4f105d307e8dd436235.zip
Merge pull request #9305 from wlmb/challenges
Challenges
-rwxr-xr-xchallenge-248/wlmb/perl/ch-2a.pl16
-rwxr-xr-xchallenge-248/wlmb/perl/ch-2b.pl16
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-248/wlmb/perl/ch-2a.pl b/challenge-248/wlmb/perl/ch-2a.pl
new file mode 100755
index 0000000000..f0dfe67719
--- /dev/null
+++ b/challenge-248/wlmb/perl/ch-2a.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+use v5.36;
+use PDL;
+use PDL::Image2D;
+die <<~"FIN" unless @ARGV==3;
+ Usage: $0 M W H
+ where M is a matrix "[[m11,m22...],[m21,m22....],...]"
+ and W and H are the size of a sliding window to make a matrix of HxW submatrices
+ and sum the submatrix matrix elements.
+ FIN
+my $m=pdl(shift);
+my $w=shift;
+my $h=shift;
+say "Input: $m Width $w, Height $h -> ",
+ $m->conv2d(ones($w,$h))->slice([floor(($w-1)/2),floor(-($w+1)/2)],
+ [floor(($h-1)/2),floor(-($h+1)/2)]);
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)]);