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

cover cp.abs() using the builtin #513

Merged
merged 13 commits into from
Oct 3, 2024
Merged

cover cp.abs() using the builtin #513

merged 13 commits into from
Oct 3, 2024

Conversation

Dimosts
Copy link
Collaborator

@Dimosts Dimosts commented Aug 28, 2024

To cover the case of cp.abs().

Currently, we do not override abs(), so it fails, although if we do from cpmpy import * just using directly abs() works (because we override it directly in the variables).

just including from builtins import abs in init.py of expressions tackles it

@IgnaceBleukx
Copy link
Collaborator

Maybe just put a comment on why specifically we import it here?
And ideally also a test : )

@tias
Copy link
Collaborator

tias commented Aug 30, 2024

this is too sneaky for me, it will be a hidden feature not present in our docs or visible to standard users.

The right way is a new function in python_builtins, with a one-liner documentation, that calls the Abs() global function directly.

Will also make it easier to (generate) tests for...

@Dimosts
Copy link
Collaborator Author

Dimosts commented Sep 9, 2024

Random not related test is failing .... Will dig into it

@Wout4
Copy link
Collaborator

Wout4 commented Sep 19, 2024

Looks good, thanks for adding tests as well, can be merged

remove redundant 'abs' code
@Wout4
Copy link
Collaborator

Wout4 commented Sep 20, 2024

Do we still want to allow using the builtin abs on our expressions, or should we enforce cpmpy.abs? I guess it's fine to allow it

@Wout4 Wout4 requested a review from tias October 3, 2024 09:40
@Wout4
Copy link
Collaborator

Wout4 commented Oct 3, 2024

@tias looks like you have to approve this now that the 'not' is added :)

bit more explicit...
Copy link
Collaborator

@tias tias left a comment

Choose a reason for hiding this comment

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

changed to make the global in the if (without not), seems more logical

also added a comment on the 'any_list', which I still find a bit weird but not a blocker : ) e.g. why it has to be a cpm_array... could have done map(abs, arg) or so, but maybe not worth any further thought

# Conflicts:
#	tests/test_globalconstraints.py
@Wout4 Wout4 merged commit 085d919 into master Oct 3, 2024
1 check passed
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.

4 participants