### Fast sliding submatrix sums with PDL (inspired by PWC 248 task 2)

 on Dec 26, 2023 at 00:51 UTC Need Help??

```Task 2: Submatrix Sum
Submitted by: Jorg Sommrey
...
[30, 34, 38]
]
```
```sub sms_WxH_Perl_4loops( \$m, \$w, \$h ) {
my ( \$W, \$H ) = ( scalar \$m-> [0]-> @*, scalar @\$m );
...
| 140 | 0.284 | 0.022 |
+-----+-------+-------+
```
```sub sms_2x2_PDL ( \$m ) {
\$m-> slice( '0:-2', '0:-2' ) +
...
\$m-> slice( '1:-1', '1:-1' )
}
```
```sub sms_WxH_PDL_naive ( \$m, \$w, \$h ) {
my \$ret = 0;
...
}
return \$ret
}
```
```use Inline Pdlpp => <<'EOPP';

...

EOPP
```
```sub sms_WxH_PDL_lags ( \$m, \$w, \$h ) {
my ( \$W, \$H ) = \$m-> dims;
...
[ 5  6  7  8]
[ 9 10 11 12]
]
```
```+
Time (s) vs. N (NxN submatrix, PDL: Double D [1500,1500] matrix)
...
| 1400 |       |       | 0.291 | 0.272 |
+------+-------+-------+-------+-------+
```
```sub _do_dimension ( \$m, \$w ) {
\$m -> slice([ 0, \$w - 1 ], [])
...
| 1400 | 0.275 | 0.003 |
+------+-------+-------+
```
```use PDL::Apply 'apply_rolling';

...
3.20836806297302
1.28170394897461
```

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://11156532]
Approved by Athanasius
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-06-25 01:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?
 • erzuuli ‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.