Skip to content

Enhancement: floating point capture and tolerance. #190

Open
@rainwoodman

Description

@rainwoodman

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions