Skip to content

cleanup(scoring): remove deprecated C-array overloads (#9252) - #9255

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:cleanup/scoring-deprecated-overloads
May 1, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:cleanup/scoring-deprecated-overloads

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Removes the deprecated pointer-based OpenSwath::Scoring overloads (NormalizedManhattanDist, RootMeanSquareDeviation, SpectralAngle, normalize_sum) and calcxcorr_legacy_mquest_, which were the source of the 15 deprecation warnings reported in deprecation warnings in our own tests #9252.
  • Ports the formula docstrings (Manhattan / RMSD / Spectral angle) from the deprecated declarations onto the surviving std::vector& overloads, as @singjc requested in the issue thread.
  • Migrates the four pointer-based call sites in Scoring_test.cpp and the two in ConfidenceScoring.cpp to the vector overloads.
  • Repurposes test_MRMFeatureScoring_calcxcorr_legacy_mquest_ as test_MRMFeatureScoring_normalizedCrossCorrelation_full_range (per @jcharkow's suggestion to "rename to test the new function") — same reference values, full-range maxdelay coverage preserved.
  • Deletes test_calcxcorr_legacy_equivalence, test_legacy_vs_normalized_consistency, and the unused calcxcorr_legacy_ref helper, which only validated the legacy function against itself or against the modern API and have no purpose once the legacy function is gone. Edge-case tests for zeros / constant-value inputs are migrated to normalizedCrossCorrelation.

Net change: +23 / −296 lines.

Closes #9252.

Test plan

  • cmake --build OpenMS-build --target Scoring_test is clean of -Wdeprecated-declarations warnings from these symbols.
  • Scoring_test passes (all sections including the renamed full-range test).
  • ctest -R "Scoring|ConfidenceScoring|MRMScoring|MRMFeatureFinderScoring" — 20/20 pass.
  • CI green on all platforms.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Removed deprecated C-style array interfaces; vector-based APIs are now the standard approach for numerical scoring functions.
    • Eliminated a legacy cross-correlation function in favor of the modern implementation.
    • Updated all internal usage to use modern vector-based APIs consistently.

Removes the deprecated pointer-based overloads of NormalizedManhattanDist,
RootMeanSquareDeviation, SpectralAngle, normalize_sum, and
calcxcorr_legacy_mquest_ from OpenSwath::Scoring. Formula docstrings are
preserved on the surviving std::vector& overloads. The legacy mquest
equivalence/consistency tests (which only validated the removed function
against itself) are deleted, and the remaining deprecated test call sites
are migrated to the modern API.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR removes deprecated C-style raw pointer overloads from the OpenSwath Scoring module (NormalizedManhattanDist, RootMeanSquareDeviation, SpectralAngle, normalize_sum, and calcxcorr_legacy_mquest_) and updates all usages to modern std::vector-based APIs. Tests are refactored to eliminate deprecation warnings.

Changes

Cohort / File(s) Summary
Scoring API modernization
src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h, src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp
Removed deprecated C-style array function overloads and legacy calcxcorr_legacy_mquest_. Kept only modern std::vector-based implementations. Updated documentation wording to describe operations "between two vectors".
Usage migration
src/openms/source/ANALYSIS/OPENSWATH/ConfidenceScoring.cpp, src/tests/class_tests/openswathalgo/Scoring_test.cpp
Updated callsites to use vector-based normalize_sum() and scoring functions. Replaced legacy cross-correlation tests with normalizedCrossCorrelation equivalents and removed test code for deprecated functions.

Possibly related PRs

  • PR #8849: Also modifies OpenSwath::Scoring by removing raw-pointer C-array overloads and transitioning implementations to vector/Eigen-based approaches.

Poem

🐰 Vectors dance where pointers used to creep,
Deprecated shadows fade away so deep,
Old arrays vanish, modern code takes flight,
The warnings gone—our tests shine clean and bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main objective: removing deprecated C-array overloads from the scoring module.
Linked Issues check ✅ Passed The PR successfully eliminates all 15 deprecation warnings from issue #9252 by removing deprecated C-array overloads and migrating call sites to std::vector& overloads.
Out of Scope Changes check ✅ Passed All changes are directly scoped to removing deprecated overloads and their usages; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).

View plan for ticket: #9252

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp (1)

119-145: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Guard lag before the cross-correlation loop.

lag == 0 makes delay += lag an infinite loop and also divides by zero in the reserve expression. Please add an OPENSWATH_PRECONDITION(lag > 0, ...) here; if you want the reservation to stay accurate for lag > 1, cast the numerator to double before ceil.

🔧 Proposed fix
     OPENSWATH_PRECONDITION(data1.size() == data2.size(), "Both data vectors need to have the same length");
+    OPENSWATH_PRECONDITION(lag > 0, "lag must be positive");
 
     XCorrArrayType result;
-      result.data.reserve( (size_t)std::ceil((2*maxdelay + 1) / lag));
+    result.data.reserve(static_cast<size_t>(std::ceil((2.0 * maxdelay + 1) / lag)));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp` around lines 119 -
145, In calculateCrossCorrelation, guard against a non-positive lag by adding
OPENSWATH_PRECONDITION(lag > 0, "lag must be > 0") before the loop to prevent an
infinite loop and divide-by-zero; also fix the reserve calculation by casting
the numerator to double (e.g., std::ceil((2.0 * maxdelay + 1.0) / lag)) so the
reservation is correct for lag > 1.
src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h (1)

63-103: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the migrated formulas before the docs go public.

The Manhattan-distance doc still shows a square root, which doesn't match the implementation, and the spectral-angle equation still has a stray parenthesis. That will generate misleading API docs for the surviving overloads.

♻️ Proposed doc cleanup
-       d = \sqrt{\frac{1}{N}  \sum_{i=0}^N |\frac{x_i}{\mu_x} - \frac{y_i}{\mu_y}|) }
+       d = \frac{1}{N} \sum_{i=0}^{N-1} \left|\frac{x_i}{\mu_x} - \frac{y_i}{\mu_y}\right|

-       \theta = acos \left( \frac{\sum_{i=0}^N (x_i * y_i))}{\sqrt{\sum_{i=0}^N (x_i * x_i) \sum_{i=0}^N (y_i * y_i)} }  \right)
+       \theta = \arccos \left( \frac{\sum_{i=0}^{N-1} x_i y_i}{\sqrt{\sum_{i=0}^{N-1} x_i^2 \sum_{i=0}^{N-1} y_i^2}} \right)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h` around lines
63 - 103, The docs contain incorrect LaTeX for NormalizedManhattanDist (shows an
unnecessary square root) and a mismatched parenthesis in SpectralAngle; update
the comment for NormalizedManhattanDist to show the mean absolute difference
without sqrt (d = (1/N) sum |x_i/μ_x - y_i/μ_y|) and fix the SpectralAngle
formula to remove the stray parenthesis and ensure the fraction is written
correctly (acos( (sum x_i*y_i) / sqrt((sum x_i^2)*(sum y_i^2)) ) ), making sure
these docstrings for NormalizedManhattanDist and SpectralAngle exactly match the
implemented behavior and compile as valid Doxygen/LaTeX.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h`:
- Around line 63-103: The docs contain incorrect LaTeX for
NormalizedManhattanDist (shows an unnecessary square root) and a mismatched
parenthesis in SpectralAngle; update the comment for NormalizedManhattanDist to
show the mean absolute difference without sqrt (d = (1/N) sum |x_i/μ_x -
y_i/μ_y|) and fix the SpectralAngle formula to remove the stray parenthesis and
ensure the fraction is written correctly (acos( (sum x_i*y_i) / sqrt((sum
x_i^2)*(sum y_i^2)) ) ), making sure these docstrings for
NormalizedManhattanDist and SpectralAngle exactly match the implemented behavior
and compile as valid Doxygen/LaTeX.

In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp`:
- Around line 119-145: In calculateCrossCorrelation, guard against a
non-positive lag by adding OPENSWATH_PRECONDITION(lag > 0, "lag must be > 0")
before the loop to prevent an infinite loop and divide-by-zero; also fix the
reserve calculation by casting the numerator to double (e.g., std::ceil((2.0 *
maxdelay + 1.0) / lag)) so the reservation is correct for lag > 1.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1e384906-a9b2-47a0-946c-c80449eb2562

📥 Commits

Reviewing files that changed from the base of the PR and between 4f05d38 and a2ec6d3.

📒 Files selected for processing (4)
  • src/openms/source/ANALYSIS/OPENSWATH/ConfidenceScoring.cpp
  • src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h
  • src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp
  • src/tests/class_tests/openswathalgo/Scoring_test.cpp

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

@CodeRabbit looks like a cwiseAbs was removed

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check current state of Scoring.cpp for cwiseAbs and surrounding context
rg -n "cwiseAbs" --type cpp -C5

# Also check git diff for the Scoring.cpp file to see what changed
git diff origin/develop...HEAD -- src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp | head -300

Length of output: 9694


@timosachsenberg The cwiseAbs removal is expected and intentional. Here's what happened:

The only cwiseAbs that was deleted was inside the deprecated C-array overload NormalizedManhattanDist(double x[], double y[], int n), which this PR removes entirely:

// REMOVED (deprecated array overload)
double NormalizedManhattanDist(double x[], double y[], int n)
{
  ...
  return (vx - vy).cwiseAbs().sum() / n;  // ← this cwiseAbs is gone
}

The surviving vector-based overload NormalizedManhattanDist(std::vector<double>&, std::vector<double>&) still correctly uses cwiseAbs at line 33 of Scoring.cpp:

// SURVIVES (vector overload) — cwiseAbs still present
double NormalizedManhattanDist(std::vector<double>& x, std::vector<double>& y)
{
  ...
  normalize_sum(x);
  normalize_sum(y);
  Eigen::Map<Eigen::VectorXd> vx(x.data(), x.size());
  Eigen::Map<Eigen::VectorXd> vy(y.data(), y.size());
  return (vx - vy).cwiseAbs().sum() / x.size();  // ← cwiseAbs still here
}

So there's no correctness regression — cwiseAbs only disappeared along with the deprecated function it lived in.

@timosachsenberg
timosachsenberg merged commit 24a18d7 into OpenMS:develop May 1, 2026
41 checks passed

@jcharkow jcharkow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

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

Successfully merging this pull request may close these issues.

deprecation warnings in our own tests

2 participants