Skip to content

Fix Typo In Matrix - #8272

Merged
poshul merged 2 commits into
developfrom
fix_matrix_bug
Oct 9, 2025
Merged

poshul merged 2 commits into
developfrom
fix_matrix_bug

Conversation

@t0mdavid-m

@t0mdavid-m t0mdavid-m commented Oct 9, 2025 •

Copy link
Copy Markdown
Member

Description

There was a typo in Matrix.h which caused issues with FLASHDeconv.

Due to operator precedence:

*this(i, j)

is parsed as:

*(this(i, j))

instead of the intended:

(*this)(i, j)

This PR replaces it with the more explicit:

this->operator()(i, j)

which also matches the style used in the rest of the header.

Credit goes to @KyowonJeong .

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • New Features

    • Matrix objects now provide a way to obtain and modify individual elements directly.
  • Refactor

    • Internal read-only access to matrix elements streamlined for safer, more consistent behavior.
  • Tests

    • New unit tests added to verify mutable and const element access and correct value propagation.

@coderabbitai

coderabbitai Bot commented Oct 9, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Added a non-const getValue(size_t, size_t) returning a modifiable reference and updated the const getValue implementation to call this->operator()(i, j). Added unit tests exercising both const and non-const getValue behavior.

Changes

Cohort / File(s) Summary
Matrix header
src/openms/include/OpenMS/DATASTRUCTURES/Matrix.h
Added new non-const Value& getValue(size_t const i, size_t const j); changed const getValue implementation to call this->operator()(i, j) directly.
C++ unit tests
src/tests/class_tests/openms/source/Matrix_test.cpp
Added tests verifying getValue returns a modifiable reference and that mutations through it update matrix values.
Python tests
src/pyOpenMS/tests/unittests/test000.py
Added a Python unit test creating a MatrixDouble, setting an element and asserting getValue returns the expected value.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Test / User
    participant Matrix as Matrix<T>
    participant Storage as internal data (operator())

    Note over Matrix: New API: getValue(i,j) -> Value&\nConst getValue calls this->operator()(i,j)

    Caller->>Matrix: getValue(i,j)
    alt non-const
        Matrix->>Storage: operator()(i,j) (returns reference)
        Storage-->>Matrix: Value& 
        Matrix-->>Caller: Value& (modifiable)
    else const
        Matrix->>Storage: this->operator()(i,j) (const access)
        Storage-->>Matrix: const Value&
        Matrix-->>Caller: const Value&
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble bytes beneath the moon,
A reference found, returned soon —
No pointer dance, just call it straight,
Matrix rows now tweak their fate.
A bunny cheers for tests that run, 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly indicates that the pull request addresses a typo in the Matrix class, which aligns with the change in Matrix.h correcting the ambiguous operator precedence. It is concise and directly related to the primary fix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_matrix_bug

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

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

@jpfeuffer

Copy link
Copy Markdown
Contributor

Could you add a line in the class and pyopenms test please?

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/pyOpenMS/tests/unittests/test000.py (1)

4100-4106: Consider expanding test to demonstrate modification through getValue.

The C++ test in Matrix_test.cpp (lines 159-180) demonstrates that the non-const getValue method returns a modifiable reference, allowing both assignment (getValue(0, 0) = 100) and modification (getValue(0, 0) += 5). This Python test only verifies read access by using setValue for writes and getValue for reads.

If the Python bindings expose a non-const getValue that supports modification, consider adding test cases that match the C++ test pattern:

# Test modification through getValue
test_matrix = pyopenms.MatrixDouble(2, 2, 0.0)
test_matrix.getValue(0, 0) = 100.0  # If supported
assert test_matrix.getValue(0, 0) == 100.0

If modification through getValue is not supported in Python, the current test is appropriate but could include a comment explaining this difference from the C++ API.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55f4d7e and 0d4ef93.

📒 Files selected for processing (2)
  • src/pyOpenMS/tests/unittests/test000.py (1 hunks)
  • src/tests/class_tests/openms/source/Matrix_test.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/tests/class_tests/openms/**/*.cpp

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for new functionality

Files:

  • src/tests/class_tests/openms/source/Matrix_test.cpp
src/pyOpenMS/tests/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write pyOpenMS tests for new Python bindings

Files:

  • src/pyOpenMS/tests/unittests/test000.py
🧬 Code graph analysis (1)
src/tests/class_tests/openms/source/Matrix_test.cpp (1)
src/openms/include/OpenMS/DATASTRUCTURES/Matrix.h (1)
  • getValue (76-79)
🔇 Additional comments (1)
src/tests/class_tests/openms/source/Matrix_test.cpp (1)

159-180: LGTM! Comprehensive test coverage for non-const getValue.

The test thoroughly verifies the non-const getValue method by:

  • Testing direct assignment through the returned reference (getValue(i, j) = value)
  • Testing in-place modification (getValue(i, j) += value)
  • Properly verifying the results using operator()

This aligns well with the C++ API design and ensures the new method works correctly.

@timosachsenberg timosachsenberg 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.

Great find!

@poshul
poshul enabled auto-merge (squash) October 9, 2025 12:19
@poshul
poshul merged commit 41e7756 into develop Oct 9, 2025
@poshul
poshul deleted the fix_matrix_bug branch October 9, 2025 16:34
@t0mdavid-m t0mdavid-m mentioned this pull request Oct 30, 2025
8 of 13 tasks
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.

4 participants