Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: floating point capture and tolerance. #190

Open
rainwoodman opened this issue Apr 18, 2022 · 1 comment
Open

Enhancement: floating point capture and tolerance. #190

rainwoodman opened this issue Apr 18, 2022 · 1 comment

Comments

@rainwoodman
Copy link

We'd like to use FileCheck to check log files with floating point numbers (in scientific computing). Apparently neither the C++ filecheck nor the FileCheck.py knows about floating point numbers.

Here I propose a capture based syntax for checking if floating points numbers are within a tolerance range:

inlined tolerance check:

Pass:

# CHECK: A + B = [[.*:VAR:tolerance(1.0,0,0.1)]]
echo "A + B = 1.0 extra text"

Fail:

# CHECK: A + B = [[.*:VAR:tolerance(1.0,0,0.1)]]
echo "A + B = 1.2 extra text"

The capture expression is extended with an extra ":" segment, where if the segment is

  • tolerance(val, atol, rtol) then the captured string is converted to floating point and checked against val with the given tolerance Refer to numpy.allclose().

full tolerance check:

A new CHECK-TOLERANCE check for captured variables, The right hand side of = can be several tolerance expressions joined by or.

# CHECK: A + B = [[.*:VAR]]
# CHECK-TOLERANCE: [[VAR]] = tolerance(1.0, 0, 0.1) or tolerance(2.0, 0, 0.1)
echo "A + B = 1.0"
# CHECK: A + B = [[.*:VAR]]
# CHECK-TOLERANCE: [[VAR]] = tolerance(1.0, 0, 0.1) or tolerance(2.0, 0, 0.1)
echo "A + B = 2.0"

Implementation:
I think it is relatively easy to add both or either form of floating point checks to FileCheck.py, but doing so will break the compatibility with LLVM filecheck. What is FileCheck.py's policy on this?

@stanislaw
Copy link
Member

The policy is very simple: there are very minor differences so far but the Python version is definitely ok to diverge further as long as the documentation clearly explains it. I was recently thinking of adding a CHECK-ONCE option, for example, so we definitely are not bound to the LLVM version.

I like both of your options but if I had to choose one, I would probably implement your full version. But having both implemented is certainly great to have too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants