-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Added Jacobian Features in Calculus functions.py #39283
base: develop
Are you sure you want to change the base?
Conversation
@tscrim (since I know you have the permission to approve workflows from first-time contributors) would you be willing to take a look at this? Or approve the CI workflows so I can review it? |
Documentation preview for this PR (built with commit ec51fc1; changes) is ready! 🎉 |
@vincentmacri It has been done by someone else. Please go ahead and do the review. I can re-approve workflows as needed. |
src/sage/calculus/functions.py
Outdated
@@ -147,4 +147,16 @@ def jacobian(functions, variables): | |||
if not isinstance(variables, (tuple, list, Vector)): | |||
variables = [variables] | |||
|
|||
return matrix([[diff(f, v) for v in variables] for f in functions]) | |||
jacobian_matrix([[diff(f, v) for v in variables] for f in functions]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant:
jacobian_matrix([[diff(f, v) for v in variables] for f in functions]) | |
jacobian_matrix = matrix([[diff(f, v) for v in variables] for f in functions]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But with the other changes I suggested you should just revert the jacobian
function back to how it was, and add a hessian
function for that functionality.
src/sage/calculus/functions.py
Outdated
@@ -106,7 +106,7 @@ def row(n): | |||
return matrix([row(r) for r in range(len(fs))]).determinant() | |||
|
|||
|
|||
def jacobian(functions, variables): | |||
def jacobian(functions, variables, hessian=False, sparse=False, rank=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that hessian
should be its own function unless you have a good reason for it not to be separate.
I don't think we need the rank
option since the returns matrix already has a .rank()
method that can be called on it.
I also don't see why the |
@Kritika75 In summary, unless there is some good reason I'm missing for why you implemented things the way you did, can you make these three changes?
Since you're a first-time contributor, GitHub is kind of annoying about running the CI tests on your PR and someone needs to approve every test run manually. To speed things up, please test things locally and make sure your tests pass before requesting another review. |
You don't want to create a dense matrix just to make it sparse. This is wasteful in both memory and computation time. |
That being said, the code itself should directly create thr sparse matrix, otherwise it should not have such an option as @vincentmacri said. Although in nearly all cases, this will not be a sparse matrix. So there might not be much practicality in having it (and hence, the maintenance burden of such code). |
Apologies for the delay in getting back to you. I had my exams, but I completely understand your concern and will address it promptly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small change request. Looks good otherwise!
@Kritika75 also make sure to pull the latest changes from |
Co-authored-by: Vincent Macri <[email protected]>
@Kritika75 you need to merge the changes from develop into your |
If you need a quick
|
Enhanced the jacobian function to include additional features: computation of Hessian matrices for single functions, optional sparse matrix representation for large systems, and the ability to calculate the rank of the Jacobian matrix.
Fixes #39218
📝 Checklist
⌛ Dependencies