I'd use PDL, with some overly-clever finagling to maximise locality:
- Get each string as columns 0 and 1 of a pdl(byte, 2, 1e8). With PDL's row-major storage, that would put each pair of characters next to each other in memory.
- Set its "badvalue" to be ord('N'), because the ne operator will ignore that pair if either value is "bad".
- Run PDL::any(PDL::ne($p->using(0,1)))
- Sadly this will currently not (yet) loop-fuse the ne and the any, but locality could be maintained by doing a splitdim into smaller chunks, and doing the any on each of those as you go.
Yes, I enjoy that in the third bit, "any" sounds like the normal pronunciation of "ne". I'm only human.
If you want to make a custom transformation that does loop-fusion manually, see the SYNOPSIS of Inline::Pdlpp for an also-bio-inspired example.
Edit: if one chooses to not loop-fuse, the ne produces a mask that is true for any non-matches; that can then be fed into which to give the positions of those.
Edit 2: the above should take a matter of minutes to write, which would be much quicker than writing it in C/C++, and should run pretty quickly. But the naive, 2,1e8 solution has the benefit of broadcasting, which would mean it would also benefit from auto-pthreading, which in C/C++ would be a lot of hard work.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.