Skip to content
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

python_builtins: follow python signature #503

Merged
merged 2 commits into from
Jul 18, 2024
Merged

python_builtins: follow python signature #503

merged 2 commits into from
Jul 18, 2024

Conversation

tias
Copy link
Collaborator

@tias tias commented Jul 16, 2024

our 'min' and 'max' didn't allow multiple arguments, while Python's does

in general we were hesitating whether our min/max/sum should mimic Python's or NumPys. Now it was a mix in the middle... we were somewhat like Python but did np.max() inside (same for sum, messing up the return type); and we didnt yet get to implementing 'axis' like numpy either.

With this pull request, I propose that the least confusing thing for people that do from cpmpy import * is to not break any existing python code... that is, follow the Python signature of min/max/sum (and fall back to that built-in when no decision variables are given).

our 'min' and 'max' didn't allow multiple arguments, while Python's
does

in general we were hesitating whether our min/max/sum should mimic
Python's or NumPys. Now it was a mix in the middle... we were somewhat
like Python but did np.max() inside (same for sum, messing up the return
type); and we didnt yet get to implementing 'axis' like numpy either.

With this pull request, I propose that the least confusing thing for
people that do `from cpmpy import *` is to not break any existing
python code... that is, follow the Python signature of min/max/sum
(and fall back to that built-in when no decision variables are given).
@tias
Copy link
Collaborator Author

tias commented Jul 16, 2024

something to maybe add to this...

we don't overwrite 'abs', but using abs(decis_var) just works. However, if you do import cpmpy as cp then cp.abs() does not work, which is very very odd.

So maybe we should fake-override abs too, e.g. just def abs(*args, **kwargs): builtins.abs(*args, **kwargs) ?

@Wout4
Copy link
Collaborator

Wout4 commented Jul 18, 2024

looks good, I think this pr adresses the axis arguments: #492

@Wout4 Wout4 merged commit 26bc446 into master Jul 18, 2024
1 check failed
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.

2 participants