Skip to content

Comments

Development#21

Merged
gjbex merged 9 commits intomasterfrom
development
Dec 9, 2024
Merged

Development#21
gjbex merged 9 commits intomasterfrom
development

Conversation

@gjbex
Copy link
Owner

@gjbex gjbex commented Dec 9, 2024

Summary by Sourcery

Refactor the convolution implementation in both C++ and Python for improved clarity and maintainability, and enhance the testing framework by integrating Catch2 for C++ and pytest for Python.

Enhancements:

  • Refactor the convolution function in both C++ and Python to improve clarity and maintainability by renaming variables and simplifying logic.

Documentation:

  • Update the Python convolution function's docstring to clarify that the output matrix shape is the same as the input.

Tests:

  • Replace the main function in the C++ test file with Catch2 test cases to improve test coverage and structure.
  • Add Python test cases using pytest to validate convolution functionality and error handling for even-sized kernels.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 9, 2024

Reviewer's Guide by Sourcery

This PR refactors the convolution implementation and testing infrastructure. The main changes include a rewrite of the convolution algorithm to maintain input dimensions, introduction of proper unit tests using Catch2 for C++ and pytest for Python, and improvements to the Matrix class implementation.

Updated class diagram for the Matrix class

classDiagram
    class Matrix {
        +int rows_
        +int cols_
        +std::unique_ptr<double[]> data_
        +Matrix(int rows, int cols)
        +Matrix(const Matrix& other)
        +Matrix& operator=(const Matrix& other)
        +Matrix(Matrix&& other) noexcept
        +Matrix& operator=(Matrix&& other) noexcept
        +double& operator()(int i, int j)
        +double operator()(int i, int j) const
        +int rows() const
        +int cols() const
        +bool operator==(const Matrix& other) const
        +bool operator!=(const Matrix& other) const
        +double* data()
        +const double* data() const
    }
    note for Matrix "Added equality operators == and !="
Loading

File-Level Changes

Change Details Files
Refactored convolution algorithm implementation
  • Changed output matrix to maintain same dimensions as input
  • Improved variable naming for better readability (e.g., s_mid to kernel_row_mid)
  • Simplified boundary condition handling logic
  • Updated algorithm to process kernel elements more efficiently
source-code/convolution/cpp/src/convolution/convolution.cpp
source-code/convolution/python/convolution.py
Implemented comprehensive test suite
  • Added Catch2 framework integration for C++ tests
  • Created test cases for 3x3 and 5x5 kernels
  • Added error testing for even-sized kernels
  • Implemented equivalent pytest-based tests for Python
source-code/convolution/cpp/src/test_convolution.cpp
source-code/convolution/python/test_convolution.py
source-code/convolution/cpp/src/CMakeLists.txt
Enhanced Matrix class functionality
  • Added equality comparison operators
  • Improved memory management in move operations
  • Added proper const correctness
source-code/convolution/cpp/src/convolution/matrices.cpp
source-code/convolution/cpp/src/convolution/matrices.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gjbex gjbex merged commit b4fc7fd into master Dec 9, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @gjbex - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Bug: max_kernel_row calculation uses kernel.cols() instead of kernel.rows() (link)

Overall Comments:

  • Please provide a more descriptive PR title and description explaining the changes (e.g., 'Add unit tests and improve convolution implementation')
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

// Do convolution.
for (int row = 0; row < input.rows(); ++row) {
auto min_kernel_row {std::max(0, kernel_row_mid - row)};
auto max_kernel_row {std::min(kernel.cols(), kernel_row_mid + input.rows() - row)};
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Bug: max_kernel_row calculation uses kernel.cols() instead of kernel.rows()

This will produce incorrect results for non-square kernels. Should use kernel.rows() to match the Python implementation.

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.

1 participant