http://www.perlmonks.org?node_id=1047514


in reply to Optimization Help

Your first problem is that your posted code doesn't compile. You have unbalanced parens and mismatched curlies:

if (grep { $$self{Matrix}[$row_index][$_] != $$other{Matrix}[$$mapping +[$row_index]][$$mapping[$_]]); } (0..$#$mapping)); ( { + ^ } ( ))

What are the dimensions of your matrices and the mapping array?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

Replies are listed 'Best First'.
Re^2: Optimization Help
by jmmitc06 (Beadle) on Aug 01, 2013 at 23:30 UTC

    Sorry, I typed it in by hand, here is the correct code ;)

    sub equate2 { my ($self, $other, $mapping) = @_; foreach my $row_index (0..$#$mapping) { return 0 if (grep { ($$self{Matrix}[$row_index][$_] != $$other{Mat +rix}[$$mapping[$row_index]][$$mapping[$_]]); } (0..$#$mapping)); } return 1; }
Re^2: Optimization Help
by jmmitc06 (Beadle) on Aug 01, 2013 at 23:33 UTC
    Oh and all the matrices are 2D and the mapping vector is 1D

      Try:

      sub equate2 { my ($self, $other, $mapping) = @_; my $sm = $self->{Matrix}; my $om = $other->{Matrix}; for my $row ( 0 .. $#$mapping ) { my $smrow = $sm->[ $row ]; my $omrow = $om->[ $mapping->[ $row ] ]; for my $col ( 0 .. $#$mapping ) { return 0 if $smrow->[ $col ] != $omrow->[ $mapping->[ $col + ] ]; } } return 1; }

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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 am in your debt!!!!! In my test case this is 40% faster, that's going to save me a couple of days right there.