I have a problem comparing two files. Basically, what I want to do is a UNIX-like diff between two files, for example:
$ diff -u left-file right-file
However, my two files contain a float; and since these files were generated on different architectures (but calculating the same things), the floating values โโare not exactly the same (they may differ, for example, from 1e-10). But what I'm trying to โdistinguishโ the files is to find what I consider to be significant differences (for example, the difference is greater than 1e-4); when using the diff command UNIX, I get almost all of my lines containing the values โโof a floating variable! This is my problem: how can I get the resulting diff, for example diff -u, but with less restrictions regarding the comparison of floats?
I thought I would write a Python script to do this, and recognized the difflib module, which provides a comparison with a similar comparison. But the documentation I found explains how to use it as is (using one method) and explains the internal objects, but I cannot find anything about how to configure the difflib object to meet my needs (for example, rewrite only the comparison method or such) ... I think that the solution may be to extract a unified difference and analyze it manually to remove my "false" differences, as this is not elegant; I would prefer to use the existing infrastructure.
So, does anyone know how to set up this library so that I can do what I'm looking for? Or at least point me in the right direction ... If not for Python, maybe the shell script might work?
Any help would be greatly appreciated! Thank you in advance for your answers!
python floating-point fuzzy-comparison
piwi
source share