← Back to Pull requests

Add custom operators .allclose. and .isclose. for test comparisons #647

Closed
unknown closed this pull request without merging on Oct 29, 2026 16:44 UTC
View on GitHub
unknown unknown commented on Oct 26, 2026 18:11 UTC
Author

Hi! 👋

I'm working on issue #606 which asked for custom operators to make test comparisons cleaner and more readable.

What this PR does

I've added two new Fortran operators that make it easier to compare values and arrays in tests. Instead of writing verbose function calls, you can now use a more natural operator syntax.

Before:

test_pass = allclose(output_array, expected_array, "my_test", rtol=1e-5)

After:

if (output_array .allclose. expected_array) then

Much cleaner. This is especially nice when you're writing quick checks or assertions where you don't need custom test names or tolerances.

What's included

I added support for:

  • .isclose. - for comparing single values (both real32 and real64)

  • .allclose. - for comparing arrays (1D, 2D, and 3D arrays, both precisions)
  • The operators use a sensible default tolerance (1e-5) and don't print output, making them perfect for inline conditionals. The original allclose() and isclose() functions are still there and unchanged - this just adds a more convenient alternative.

    Implementation details

  • Added 8 new operator functions in ftorch_test_utils (2 for isclose, 6 for allclose covering different array dimensions)

  • Updated both the .fypp template and regenerated the .f90 file

  • Made sure the operators are exported from the main ftorch module

  • Created a new test suite with 9 test cases covering all the different variants

  • Updated the CHANGELOG
  • Testing

    I wrote comprehensive tests that cover:

  • Scalar comparisons for both real32 and real64

  • Array comparisons for 1D, 2D, and 3D arrays

  • Proper handling of shape mismatches

  • Both cases where values match and where they don't
  • All tests check that the operators work correctly and return the expected true/false values.

    Backward compatibility

    This is purely additive - no existing code needs to change. The original allclose() and isclose() functions work exactly as before. Users can choose which style they prefer, or mix and match depending on what's clearer in each situation.

    AI Disclosure

    Developed with assistance from Claude (Anthropic AI). All code has been reviewed and verified for correctness.

    Files changed

  • src/ftorch_test_utils.fypp - added operator interfaces and implementations

  • src/ftorch_test_utils.f90 - regenerated from fypp

  • src/ftorch.f90 - exported the operators

  • test/unit/test_utils/ - new directory with test suite

  • test/unit/CMakeLists.txt - hooked up the new tests

  • CHANGELOG.md - documented the feature
  • Let me know if you'd like me to change anything or if you have questions about the implementation!

    Closes #606

    Diff: 335 lines (+251 / -84) across 4 files Reviewer: joewallwork Review duration: 4233m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 335 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #647"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%