Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Yes, I have. His solution and my sms_2x2_PDL look almost the same, but there's a difference: he supplies a list of slices as argument to pdl() constructor. Such list, regardless of its length, uses almost zero resources, because slice, as many other e.g. PDL::Slice functions, creates virtual ndarray i.e. header pointing to original data. The constructor, however, builds fresh new ndarray -- and that even before any summation has begun. Probably, temporary pike in memory usage is negligible (*) in case of 2x2 submatrices. Usage for WxH case is perhaps impractical and only speculative, but, suppose 1500x1500 data, 10x10 frame -- which means 100 slices 1490*1490 each i.e. ~1,7 Gb temporary monster.

*: but why not measure its impact:

sub sms_2x2_PDL_wlmb ( $m ) { pdl( $m-> slice( '0:-2,0:-2' ), $m-> slice( '1:-1,0:-2' ), $m-> slice( '0:-2,1:-1' ), $m-> slice( '1:-1,1:-1' ), )-> mv( -1, 0 )-> sumover } __END__ Time (s) vs. N (2x2 submatrix, NxN matrix) +-----------------------------------------------------------+ |+ + + + + + | | B | | | | | | | 1.5 |-+ +-| | | | | | | | B | | | 1 |-+ +-| | | | | | | | A | | | | B | 0.5 |-+ +-| | A | | | | B | | B A | | B A | | B A A | 0 |-+ B A +-| |+ + + + + + | +-----------------------------------------------------------+ 0 1000 2000 3000 4000 5000 sms_2x2_PDL A sms_2x2_PDL_wlmb B +------+-------+-------+ | N | A | B | +------+-------+-------+ | 400 | 0.002 | 0.011 | | 800 | 0.006 | 0.041 | | 1200 | 0.023 | 0.098 | | 1600 | 0.061 | 0.180 | | 2000 | 0.109 | 0.273 | | 3000 | 0.238 | 0.613 | | 4000 | 0.433 | 1.148 | | 5000 | 0.738 | 1.758 | +------+-------+-------+

In reply to Re^2: Fast sliding submatrix sums with PDL (inspired by PWC 248 task 2) by Anonymous Monk
in thread Fast sliding submatrix sums with PDL (inspired by PWC 248 task 2) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-06-19 03:10 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.