-
Notifications
You must be signed in to change notification settings - Fork 0
/
real-compare
executable file
·47 lines (40 loc) · 1.07 KB
/
real-compare
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
use strict;
use warnings;
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> };
$contents =~ s/\[.*\]//sg;
close $file or warn $!;
my $number_re = qr{
(
\b\d+[^\s,()]*
| \.\d[^\s,()]*
)
}x;
while ($contents =~ m/$number_re/g){
push @list, $1;
}
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";
#print Dumper [\@a, \@b] => [qw($a $b)];
my $n = @a;
my $diffs = 0;
for (0..$n - 1) {
my $diff = abs($a[$_] - $b[$_]);
if ($diff > 1e-5) {
printf "Index %d (%d, %d): got %s, expected %s\n",
$_, $_ % sqrt($n), int($_ / sqrt($n)), $a[$_], $b[$_];
$diffs++;
}
}
print "Matrices identical\n" if $diffs == 0 && @a == @b;
# vim: ft=perl expandtab ts=4 sw=4