Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 46 lines (39 sloc) 1.03 KB
#!/usr/bin/perl
use strict;
use warnings;
use Math::Complex;
use Data::Dumper;
sub read_file {
# we ignore that the structure is a matrix, and just read it as if where a
# list
my $fn = shift;
open my $file, '<', $fn or die "Can't open file '$fn' for reading: $!";
my @list;
my $contents = do { local $/; <$file> };
close $file or warn $!;
my $number_re = qr{
\( \s*
([^\s(),]*) # real part
\s*,\s*
([^\s(),]*) # imaginary part
,?
\s*
\)
}x;
while ($contents =~ m/$number_re/g){
push @list, $1 + $2 * i;
}
return @list;
}
my @a = read_file($ARGV[0] || 'grinv-cpp');
my @b = read_file($ARGV[1] || 'grinv-nano');
print scalar(@a), "\t", scalar(@b), "\n";
my $n = @a;
for (0..$n - 1) {
my $diff = abs($a[$_] - $b[$_]);
if ($diff > 1e-4) {
printf "Index %d (%d, %d): got %s, expected %s\n",
$_, $_ % sqrt($n), int($_ / sqrt($n)), $a[$_], $b[$_];
}
}
# vim: ft=perl expandtab ts=4 sw=4