As the original poster wanted copies of all the matrices, I think this could be made to be as efficient as possible for their needs.
On Wed, Jul 27, 2011 at 4:23 PM, Chris Marshall <[email protected]> wrote: > What about something like this: > > pdl> $data = sequence(5,5) > > pdl> p $data > > [ > [ 0 1 2 3 4] > [ 5 6 7 8 9] > [10 11 12 13 14] > [15 16 17 18 19] > [20 21 22 23 24] > ] > > > pdl> $swapinds = pdl[1,3] > > pdl> $data($swapinds) .= $data($swapinds(-1:0))->copy > > pdl> p $data > > [ > [ 0 3 2 1 4] > [ 5 8 7 6 9] > [10 13 12 11 14] > [15 18 17 16 19] > [20 23 22 21 24] > ] > > and similarly for column exchanges. I'm not sure > how fast this is since an extra copy of the data is > made. > > --Chris > > > On Wed, Jul 27, 2011 at 5:01 PM, David Mertens <[email protected]> > wrote: >> Hey folks - >> >> I've been on PerlMonks today and found somebody playing with matrices. >> Somebody asked why they didn't use PDL and BrowserUK (not the OP) >> responded with this: >> >> --------%<-------- >> I think that if an algorithm requires access to individual elements of >> the piddles, rather than being able to apply single operations to >> whole piddles at a time, there is little to be gained. What you might >> gain from more efficient duplication, you lose by having to call one >> or two functions per element during calculation or conditional >> testing. >> >> From my very limited understanding of the OPs problem, much of the >> effort involved in the algorithm involves: >> >> * interchanging whole rows & whole columns in 2D arrays. >> I don't think that PDL is particularly efficient at performing >> these operations, especially the latter. >> >> * performing "bit-wise" boolean operations and >> 'counting-the-set-bits', on pairs of rows of zeros and ones. >> If the rows of 0s and 1s were encoded as simple bit-vectors, then >> not only can standard Perl can perform both these operations more >> efficiently than PDL, the storage requirements are 8x less. >> >> I'd be very happy to be wrong here, but I just don't think PDL suits >> these particular types of operations. >> -------->%-------- >> >> I responded saying that the second operation is easy, but I found the >> first operation to be surprisingly difficult. BrowserUK's query and my >> response are viewable here: http://www.perlmonks.org/?node_id=917089; >> the original discussion is this thread: >> http://www.perlmonks.org/?node_id=916850 >> >> If anybody who is more familiar with row and column exchanges to could >> clear this up, I'd greatly appreciate it. >> >> David >> >> -- >> Sent via my carrier pigeon. >> >> _______________________________________________ >> Perldl mailing list >> [email protected] >> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl >> > -- Sent via my carrier pigeon. _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
