Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Anonymous Monk
on Dec 26, 2023 at 00:51 UTC ( [id://11156532]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    Task 2: Submatrix Sum
    Submitted by: Jorg Sommrey
    ...
                   [30, 34, 38]
                 ]
    
  2. or download this
    sub sms_WxH_Perl_4loops( $m, $w, $h ) {
        my ( $W, $H ) = ( scalar $m-> [0]-> @*, scalar @$m );
    ...
      | 140 | 0.284 | 0.022 |
      +-----+-------+-------+
    
  3. or download this
    sub sms_2x2_PDL ( $m ) {
        $m-> slice( '0:-2', '0:-2' ) +
    ...
        $m-> slice( '1:-1', '1:-1' )
    }
    
  4. or download this
    sub sms_WxH_PDL_naive ( $m, $w, $h ) {
        my $ret = 0;
    ...
        }
        return $ret
    }
    
  5. or download this
    use Inline Pdlpp => <<'EOPP';
    
    ...
    
    EOPP
    
  6. or download this
    sub sms_WxH_PDL_lags ( $m, $w, $h ) {
        my ( $W, $H ) = $m-> dims;
    ...
     [ 5  6  7  8]
     [ 9 10 11 12]
    ]
    
  7. or download this
    +
        Time (s) vs. N (NxN submatrix, PDL: Double D [1500,1500] matrix)
    ...
      | 1400 |       |       | 0.291 | 0.272 |
      +------+-------+-------+-------+-------+
    
  8. or download this
    sub _do_dimension ( $m, $w ) {
        $m -> slice([ 0, $w - 1 ], [])
    ...
      | 1400 | 0.275 | 0.003 |
      +------+-------+-------+
    
  9. or download this
    use PDL::Apply 'apply_rolling';
    
    ...
    3.20836806297302
    1.28170394897461
    

Log In?
Username:
Password:

What's my password?
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.