Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Performance problem with Clone Method

by dwm042 (Priest)
on Jul 27, 2011 at 21:40 UTC ( [id://917140]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Performance problem with Clone Method
in thread Performance problem with Clone Method

PDL(i,j) manipulation:

Look at the get and set functions in PDL::Func.

To note, the difference between column and row operations are the difference between 0 transpose operations and 2 of them. That said, between PDL::Slices and PDL::NiceSlice there are so many ways to skin this cat I'm surprised people worry about the issue of column/row operations in PDL.

#! /usr/bin/perl use PDL; my $M = sequence(10,10); print $M; my $row = $M->slice(':,3'); my $col = $M->slice('4,:'); my $col2 = $M->slice('5,:'); my $deep_col = $col->copy; $col .= $col2; $col2 .= $deep_col; print $M;


See also reorder, dice, range etc. Update:original code example broken.

If you're doing lots of row or column manipulations, perhaps better to keep a 1d piddle of index values and manipulate those.

Replies are listed 'Best First'.
Re^4: Performance problem with Clone Method
by BrowserUk (Patriarch) on Jul 27, 2011 at 23:53 UTC
    there are so many ways to skin this cat I'm surprised people worry about the issue of column/row operations in PDL.

    The problem is not "can it be done with PDL", more "do you gain anything by using PDL to do it"? Ie. Is it more efficient?

    This iterates through all the row and column permutations of a 10x10 matrix in 82 seconds:

    #! perl -slw use strict; use Data::Dump qw[ pp ]; use Time::HiRes qw[ time ]; #$Data::Dump::WIDTH = 1000; use Algorithm::Combinatorics qw[ permutations ]; my @a = map[ 10 *$_ .. 10 *$_ + 9 ], 0 .. 9; ## rows my $start = time; my $perms = permutations( [ 0 .. 9 ] ); while( my $p = $perms->next ) { my @perm = @a[ @$p ]; } printf "All row permutations took %f seconds\n", time - $start; ## cols $start = time; $perms = permutations( [ 0 .. 9 ] ); while( my $p = $perms->next ) { my @perm = map[ @{$_}[ @$p ] ], @a; } printf "All column permutations took %f seconds\n", time - $start; __END__ C:\test>PermsMatrix.pl All row permutations took 17.198000 seconds All column permutations took 65.284842 seconds

    The OP mentioned matrices of "hundreds x hundreds".

    As I understand the brute force algorithm for the Subgraph Isomorphism Problem, it requires performing all the row permutations for all the column permutations of the smaller of the two adjacency matrix graphs for every equal sized subgraph of the larger adjacency matrix. Ullmann trims the tree somewhat, but essentially still requires many of the iterations and all the transformations to be performed.

    I've no doubts that this can be done with PDL; I just wonder if you gain much performance?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I read this thread through 3-4 times before I "got it", which is that PDL is really a floating point engine that makes things like singular value decomposition a one liner.

      And that back in 1983, the kind of programming the OP is interested in would have been written in assembler and/or C, and so bitwise efficiency is to be optimized here.

      D-
        PDL is really a floating point engine that makes things like singular value decomposition a one liner
        This is not and never was correct. PDL has always been a numerical processing library (or engine, if you prefer), which has both bindings to various external libraries which can do linear algebra in a highly-optimised way, or read images, or search for Ngrams in DNA, etc, and also includes built-in operations for floating-point linear-algebra stuff like SVD, and operations on integers. This includes bitwise operations on integers, which is nearly the most efficient way to do boolean stuff (the most efficient way would be to treat each of the application's data items as a bit, and compact those 8 per byte, but your code has to do that itself, at least for now).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://917140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-28 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found