Skip to content

Fixes incorrect behaviour when taking the derivative of a constant matrix #39451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 10, 2025

Conversation

pyrusbrawler64
Copy link
Contributor

@pyrusbrawler64 pyrusbrawler64 commented Feb 4, 2025

Fixes #15067.

Fixed error in the _derivative methods of matrix_dense.pyx and matrix_sparse.pyx. These functions attempted to call the derivative method belonging to each element of the matrix. This caused incorrect behaviour when the element did not have a derivative method. This was fixed by altering the code to call the derivative function defined in /src/sage/calculus/functional.py with the element as a parameter, instead of the derivative method belonging to the element. Doctests were added to verify this change.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@DaveWitteMorris
Copy link
Member

Thanks for the bug fix.

After "Verify that :issue:`15067` is fixed::" in matrix_dense.pyx, there is a line that is supposed to be blank, but has some spaces in it. This line needs to be emptied.

After you make that correction, I will run make ptestlong. If that comes back clean, and nobody else has comments, I will set to positive review on Friday.

Copy link

github-actions bot commented Feb 5, 2025

Documentation preview for this PR (built with commit 8cecf8c; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@DaveWitteMorris
Copy link
Member

There is no need for make ptestlong, because the CI workflow ran on this. However,Lint failed because of the non-blank line that I pointed out:

./sage/matrix/matrix_dense.pyx:283:1: W293 blank line contains whitespace
1       W293 blank line contains whitespace

That needs to be fixed.

@DaveWitteMorris DaveWitteMorris self-requested a review February 5, 2025 18:00
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 9, 2025
sagemathgh-39451: Fixes incorrect behaviour when taking the derivative of a constant matrix
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Fixes sagemath#15067.

Fixed error in the _derivative methods of matrix_dense.pyx and
matrix_sparse.pyx. These functions attempted to call the derivative
method belonging to each element of the matrix. This caused incorrect
behaviour when the element did not have a derivative method. This was
fixed by altering the code to call the derivative function defined in
/src/sage/calculus/functional.py with the element as a parameter,
instead of the derivative method belonging to the element. Doctests were
added to verify this change.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [X] The title is concise and informative.
- [X] The description explains in detail what this PR is about.
- [X] I have linked a relevant issue or discussion.
- [X] I have created tests covering the changes.
- [X] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39451
Reported by: Caleb Van't Land
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 9, 2025
sagemathgh-39451: Fixes incorrect behaviour when taking the derivative of a constant matrix
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Fixes sagemath#15067.

Fixed error in the _derivative methods of matrix_dense.pyx and
matrix_sparse.pyx. These functions attempted to call the derivative
method belonging to each element of the matrix. This caused incorrect
behaviour when the element did not have a derivative method. This was
fixed by altering the code to call the derivative function defined in
/src/sage/calculus/functional.py with the element as a parameter,
instead of the derivative method belonging to the element. Doctests were
added to verify this change.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [X] The title is concise and informative.
- [X] The description explains in detail what this PR is about.
- [X] I have linked a relevant issue or discussion.
- [X] I have created tests covering the changes.
- [X] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39451
Reported by: Caleb Van't Land
Reviewer(s):
@vbraun vbraun merged commit 90a1d21 into sagemath:develop Feb 10, 2025
22 checks passed
@pyrusbrawler64 pyrusbrawler64 deleted the 15067_derivative branch March 9, 2025 19:27
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.

derivative(constant vector, x) returns the scalar 0
3 participants