Skip to content

Conversation

@haarisr
Copy link
Contributor

@haarisr haarisr commented Oct 27, 2025

According to the docs, the least squares residual function can return a 1D array or scalar.

Added a test as well for the change

@github-actions
Copy link

mypy_primer results

No ecosystem changes detected ✅

@haarisr haarisr changed the title 🐛 optimize.least_squares: Allow scalar floating point return type in 🐛 optimize.least_squares: Allow scalar floating point return type in residual function Oct 27, 2025
@jorenham
Copy link
Member

jorenham commented Oct 27, 2025

Thanks for the PR!

Could you provide a (runtime) example of such usage? Just so that I understand a bit better what's going on.

edit: after looking a bit closer I realized this fixes a pretty obvious issue; so no need for that example

@jorenham jorenham added this to the 1.16.3.0 milestone Oct 27, 2025
@jorenham
Copy link
Member

Also, do you have any idea if this also is the case for the other callables (jac and loss)?

Copy link
Member

@jorenham jorenham left a comment

Choose a reason for hiding this comment

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

I've got nothing to complain here, and I really like the testcase; it's nice and robust.

So unless the jac or loss also need to be fixed, this should be good to merge, AFAIK.

@haarisr
Copy link
Contributor Author

haarisr commented Oct 27, 2025

So unless the jac or loss also need to be fixed, this should be good to merge, AFAIK.

It doesn't. jac needs to be at_least2d and if loss is a callable, it need to be of shape 3xM

@jorenham jorenham changed the title 🐛 optimize.least_squares: Allow scalar floating point return type in residual function 🐛 optimize.least_squares: Allow scalar floating point return type in residual function Oct 27, 2025
@jorenham jorenham merged commit 481e392 into scipy:master Oct 27, 2025
21 checks passed
@jorenham
Copy link
Member

Ok, in it goes then. Thanks @haarisr !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants