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

Add type to loop variables only #947

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Add type to loop variables only #947

wants to merge 9 commits into from

Conversation

Joao-Dionisio
Copy link
Collaborator

Similar to #946, but without adding types to the arguments, as it was controversial.

We should probably also add a performance test at some point. Naturally, SCIP should be where the majority of time is spent, but maybe someone is doing a lot of stuff on the Python side.

The performance gain of this is probably marginal, but faster is better than slower, I suppose.

@@ -63,6 +63,7 @@ cdef class LP:
lb -- lower bound (default 0.0)
ub -- upper bound (default infinity)
"""
cdef int i
nnonz = len(entries)
Copy link
Contributor

@DominikKamp DominikKamp Jan 25, 2025

Choose a reason for hiding this comment

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

This must then also be an int, similar further down.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can do this (did so for the examples you pointed out), but I think there's no gain from Cython's POV.

Copy link
Contributor

Choose a reason for hiding this comment

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

Depends on how range works. For me it would be just more consistent. At some point it needs to be converted and maybe it is better to do it only once.

@@ -981,6 +984,7 @@ cdef class Solution:

def __getitem__(self, Expr expr):
# fast track for Variable
cdef SCIP_Real coeff
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a new line after each cdef block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did this, but it does look a bit unnatural in some places

Copy link
Contributor

Choose a reason for hiding this comment

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

If the function block is not divided by newlines already, this can also be omitted.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -168,6 +168,8 @@ cdef SCIP_RETCODE PyConsFree (SCIP* scip, SCIP_CONSHDLR* conshdlr) noexcept with
return SCIP_OKAY

cdef SCIP_RETCODE PyConsInit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
cdef int i

PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm I don't know, actually

src/pyscipopt/lp.pxi Outdated Show resolved Hide resolved
src/pyscipopt/scip.pxi Outdated Show resolved Hide resolved
src/pyscipopt/scip.pxi Outdated Show resolved Hide resolved
src/pyscipopt/scip.pxi Outdated Show resolved Hide resolved
src/pyscipopt/scip.pxi Outdated Show resolved Hide resolved
src/pyscipopt/scip.pxi Outdated Show resolved Hide resolved
@@ -4880,6 +4920,7 @@ cdef class Model:
"""
cdef SCIP_Bool success
cdef int _nvars
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use _nvars instead of nvars here? Why below not? Could this be made consistent as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would you rather it being all _nvars or all nvars?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the scope allows, nvars. At some spots _nvars seems to be not even used afterwards.

Copy link
Collaborator Author

@Joao-Dionisio Joao-Dionisio Jan 27, 2025

Choose a reason for hiding this comment

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

I suppose the same argument goes for _vars.

EDIT: Actually, I guess not, since it seems to be used whenever it's referring to scip variables. The same might have been true for _nvars.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think everything should be done now, @DominikKamp

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