Skip to content

Commit d07a684

Browse files
committed
Typed loop variables
1 parent ba12195 commit d07a684

File tree

8 files changed

+123
-14
lines changed

8 files changed

+123
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
### Added
5+
- Added cdef to loop variables for slight speedup
56
- Added wrappers for setting and getting heuristic timing
67
- Added transformed option to getVarDict, updated test
78
- Added categorical data example

src/pyscipopt/benders.pxi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ cdef SCIP_RETCODE PyBendersSolvesub (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL
175175
cdef SCIP_RETCODE PyBendersPostsolve (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol,
176176
SCIP_BENDERSENFOTYPE type, int* mergecands, int npriomergecands, int nmergecands, SCIP_Bool checkint,
177177
SCIP_Bool infeasible, SCIP_Bool* merged) noexcept with gil:
178+
cdef int i
178179
cdef SCIP_BENDERSDATA* bendersdata
179180
bendersdata = SCIPbendersGetData(benders)
180181
PyBenders = <Benders>bendersdata

src/pyscipopt/conshdlr.pxi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ cdef SCIP_RETCODE PyConsFree (SCIP* scip, SCIP_CONSHDLR* conshdlr) noexcept with
169169

170170
cdef SCIP_RETCODE PyConsInit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
171171
PyConshdlr = getPyConshdlr(conshdlr)
172+
cdef int i
172173
cdef constraints = []
173174
for i in range(nconss):
174175
constraints.append(getPyCons(conss[i]))
@@ -178,6 +179,7 @@ cdef SCIP_RETCODE PyConsInit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** c
178179
cdef SCIP_RETCODE PyConsExit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
179180
PyConshdlr = getPyConshdlr(conshdlr)
180181
cdef constraints = []
182+
cdef int i
181183
for i in range(nconss):
182184
constraints.append(getPyCons(conss[i]))
183185
PyConshdlr.consexit(constraints)
@@ -186,6 +188,7 @@ cdef SCIP_RETCODE PyConsExit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** c
186188
cdef SCIP_RETCODE PyConsInitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
187189
PyConshdlr = getPyConshdlr(conshdlr)
188190
cdef constraints = []
191+
cdef int i
189192
for i in range(nconss):
190193
constraints.append(getPyCons(conss[i]))
191194
PyConshdlr.consinitpre(constraints)
@@ -194,6 +197,7 @@ cdef SCIP_RETCODE PyConsInitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*
194197
cdef SCIP_RETCODE PyConsExitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
195198
PyConshdlr = getPyConshdlr(conshdlr)
196199
cdef constraints = []
200+
cdef int i
197201
for i in range(nconss):
198202
constraints.append(getPyCons(conss[i]))
199203
PyConshdlr.consexitpre(constraints)
@@ -202,6 +206,7 @@ cdef SCIP_RETCODE PyConsExitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*
202206
cdef SCIP_RETCODE PyConsInitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
203207
PyConshdlr = getPyConshdlr(conshdlr)
204208
cdef constraints = []
209+
cdef int i
205210
for i in range(nconss):
206211
constraints.append(getPyCons(conss[i]))
207212
PyConshdlr.consinitsol(constraints)
@@ -210,6 +215,7 @@ cdef SCIP_RETCODE PyConsInitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*
210215
cdef SCIP_RETCODE PyConsExitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_Bool restart) noexcept with gil:
211216
PyConshdlr = getPyConshdlr(conshdlr)
212217
cdef constraints = []
218+
cdef int i
213219
for i in range(nconss):
214220
constraints.append(getPyCons(conss[i]))
215221
PyConshdlr.consexitsol(constraints, restart)
@@ -246,6 +252,7 @@ cdef SCIP_RETCODE PyConsTrans (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* s
246252
cdef SCIP_RETCODE PyConsInitlp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_Bool* infeasible) noexcept with gil:
247253
PyConshdlr = getPyConshdlr(conshdlr)
248254
cdef constraints = []
255+
cdef int i
249256
for i in range(nconss):
250257
constraints.append(getPyCons(conss[i]))
251258
result_dict = PyConshdlr.consinitlp(constraints)
@@ -255,6 +262,7 @@ cdef SCIP_RETCODE PyConsInitlp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
255262
cdef SCIP_RETCODE PyConsSepalp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss, SCIP_RESULT* result) noexcept with gil:
256263
PyConshdlr = getPyConshdlr(conshdlr)
257264
cdef constraints = []
265+
cdef int i
258266
for i in range(nconss):
259267
constraints.append(getPyCons(conss[i]))
260268
result_dict = PyConshdlr.conssepalp(constraints, nusefulconss)
@@ -265,6 +273,7 @@ cdef SCIP_RETCODE PyConsSepasol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*
265273
SCIP_SOL* sol, SCIP_RESULT* result) noexcept with gil:
266274
PyConshdlr = getPyConshdlr(conshdlr)
267275
cdef constraints = []
276+
cdef int i
268277
for i in range(nconss):
269278
constraints.append(getPyCons(conss[i]))
270279
solution = Solution.create(scip, sol)
@@ -276,6 +285,7 @@ cdef SCIP_RETCODE PyConsEnfolp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
276285
SCIP_Bool solinfeasible, SCIP_RESULT* result) noexcept with gil:
277286
PyConshdlr = getPyConshdlr(conshdlr)
278287
cdef constraints = []
288+
cdef int i
279289
for i in range(nconss):
280290
constraints.append(getPyCons(conss[i]))
281291
result_dict = PyConshdlr.consenfolp(constraints, nusefulconss, solinfeasible)
@@ -285,6 +295,7 @@ cdef SCIP_RETCODE PyConsEnfolp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
285295
cdef SCIP_RETCODE PyConsEnforelax (SCIP* scip, SCIP_SOL* sol, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss, SCIP_Bool solinfeasible, SCIP_RESULT* result) noexcept with gil:
286296
PyConshdlr = getPyConshdlr(conshdlr)
287297
cdef constraints = []
298+
cdef int i
288299
for i in range(nconss):
289300
constraints.append(getPyCons(conss[i]))
290301
solution = Solution.create(scip, sol)
@@ -296,6 +307,7 @@ cdef SCIP_RETCODE PyConsEnfops (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
296307
SCIP_Bool solinfeasible, SCIP_Bool objinfeasible, SCIP_RESULT* result) noexcept with gil:
297308
PyConshdlr = getPyConshdlr(conshdlr)
298309
cdef constraints = []
310+
cdef int i
299311
for i in range(nconss):
300312
constraints.append(getPyCons(conss[i]))
301313
result_dict = PyConshdlr.consenfops(constraints, nusefulconss, solinfeasible, objinfeasible)
@@ -306,6 +318,7 @@ cdef SCIP_RETCODE PyConsCheck (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
306318
SCIP_Bool checklprows, SCIP_Bool printreason, SCIP_Bool completely, SCIP_RESULT* result) noexcept with gil:
307319
PyConshdlr = getPyConshdlr(conshdlr)
308320
cdef constraints = []
321+
cdef int i
309322
for i in range(nconss):
310323
constraints.append(getPyCons(conss[i]))
311324
solution = Solution.create(scip, sol)
@@ -317,6 +330,7 @@ cdef SCIP_RETCODE PyConsProp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** c
317330
SCIP_PROPTIMING proptiming, SCIP_RESULT* result) noexcept with gil:
318331
PyConshdlr = getPyConshdlr(conshdlr)
319332
cdef constraints = []
333+
cdef int i
320334
for i in range(nconss):
321335
constraints.append(getPyCons(conss[i]))
322336
result_dict = PyConshdlr.consprop(constraints, nusefulconss, nmarkedconss, proptiming)
@@ -330,6 +344,7 @@ cdef SCIP_RETCODE PyConsPresol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
330344
int* ndelconss, int* naddconss, int* nupgdconss, int* nchgcoefs, int* nchgsides, SCIP_RESULT* result) noexcept with gil:
331345
PyConshdlr = getPyConshdlr(conshdlr)
332346
cdef constraints = []
347+
cdef int i
333348
for i in range(nconss):
334349
constraints.append(getPyCons(conss[i]))
335350
# dictionary for input/output parameters
@@ -403,6 +418,7 @@ cdef SCIP_RETCODE PyConsDisable (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*
403418
cdef SCIP_RETCODE PyConsDelvars (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
404419
PyConshdlr = getPyConshdlr(conshdlr)
405420
cdef constraints = []
421+
cdef int i
406422
for i in range(nconss):
407423
constraints.append(getPyCons(conss[i]))
408424
PyConshdlr.consdelvars(constraints)

src/pyscipopt/cutsel.pxi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ cdef SCIP_RETCODE PyCutselExitsol (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept wit
7272
cdef SCIP_RETCODE PyCutselSelect (SCIP* scip, SCIP_CUTSEL* cutsel, SCIP_ROW** cuts, int ncuts,
7373
SCIP_ROW** forcedcuts, int nforcedcuts, SCIP_Bool root, int maxnselectedcuts,
7474
int* nselectedcuts, SCIP_RESULT* result) noexcept with gil:
75+
cdef int i
7576
cdef SCIP_CUTSELDATA* cutseldata
7677
cdef SCIP_ROW* scip_row
7778
cutseldata = SCIPcutselGetData(cutsel)

src/pyscipopt/lp.pxi

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ cdef class LP:
6363
lb -- lower bound (default 0.0)
6464
ub -- upper bound (default infinity)
6565
"""
66+
cdef int i
6667
nnonz = len(entries)
6768

6869
cdef SCIP_Real* c_coefs = <SCIP_Real*> malloc(nnonz * sizeof(SCIP_Real))
@@ -95,7 +96,8 @@ cdef class LP:
9596
lbs -- lower bounds (default 0.0)
9697
ubs -- upper bounds (default infinity)
9798
"""
98-
99+
cdef int i
100+
99101
ncols = len(entrieslist)
100102
nnonz = sum(len(entries) for entries in entrieslist)
101103

@@ -158,6 +160,8 @@ cdef class LP:
158160
lhs -- left-hand side of the row (default 0.0)
159161
rhs -- right-hand side of the row (default infinity)
160162
"""
163+
cdef int i
164+
161165
beg = 0
162166
nnonz = len(entries)
163167

@@ -188,6 +192,8 @@ cdef class LP:
188192
lhss -- left-hand side of the row (default 0.0)
189193
rhss -- right-hand side of the row (default infinity)
190194
"""
195+
cdef int i
196+
191197
nrows = len(entrieslist)
192198
nnonz = sum(len(entries) for entries in entrieslist)
193199

@@ -232,6 +238,8 @@ cdef class LP:
232238
firstcol -- first column (default 0)
233239
lastcol -- last column (default ncols - 1)
234240
"""
241+
cdef int i
242+
235243
lastcol = lastcol if lastcol != None else self.ncols() - 1
236244

237245
if firstcol > lastcol:
@@ -261,6 +269,8 @@ cdef class LP:
261269
firstrow -- first row (default 0)
262270
lastrow -- last row (default nrows - 1)
263271
"""
272+
cdef int i
273+
264274
lastrow = lastrow if lastrow != None else self.nrows() - 1
265275

266276
if firstrow > lastrow:
@@ -363,6 +373,8 @@ cdef class LP:
363373

364374
def getPrimal(self):
365375
"""Returns the primal solution of the last LP solve."""
376+
cdef int i
377+
366378
ncols = self.ncols()
367379
cdef SCIP_Real* c_primalsol = <SCIP_Real*> malloc(ncols * sizeof(SCIP_Real))
368380
PY_SCIP_CALL(SCIPlpiGetSol(self.lpi, NULL, c_primalsol, NULL, NULL, NULL))
@@ -379,6 +391,8 @@ cdef class LP:
379391

380392
def getDual(self):
381393
"""Returns the dual solution of the last LP solve."""
394+
cdef int i
395+
382396
nrows = self.nrows()
383397
cdef SCIP_Real* c_dualsol = <SCIP_Real*> malloc(nrows * sizeof(SCIP_Real))
384398
PY_SCIP_CALL(SCIPlpiGetSol(self.lpi, NULL, NULL, c_dualsol, NULL, NULL))
@@ -395,6 +409,8 @@ cdef class LP:
395409

396410
def getPrimalRay(self):
397411
"""Returns a primal ray if possible, None otherwise."""
412+
cdef int i
413+
398414
if not SCIPlpiHasPrimalRay(self.lpi):
399415
return None
400416
ncols = self.ncols()
@@ -409,6 +425,8 @@ cdef class LP:
409425

410426
def getDualRay(self):
411427
"""Returns a dual ray if possible, None otherwise."""
428+
cdef int i
429+
412430
if not SCIPlpiHasDualRay(self.lpi):
413431
return None
414432
nrows = self.nrows()
@@ -429,6 +447,8 @@ cdef class LP:
429447

430448
def getRedcost(self):
431449
"""Returns the reduced cost vector of the last LP solve."""
450+
cdef int i
451+
432452
ncols = self.ncols()
433453

434454
cdef SCIP_Real* c_redcost = <SCIP_Real*> malloc(ncols * sizeof(SCIP_Real))
@@ -443,6 +463,8 @@ cdef class LP:
443463

444464
def getBasisInds(self):
445465
"""Returns the indices of the basic columns and rows; index i >= 0 corresponds to column i, index i < 0 to row -i-1"""
466+
cdef int i
467+
446468
nrows = self.nrows()
447469
cdef int* c_binds = <int*> malloc(nrows * sizeof(int))
448470

src/pyscipopt/reader.pxi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ cdef SCIP_RETCODE PyReaderWrite (SCIP* scip, SCIP_READER* reader, FILE* file,
4545
SCIP_VAR** fixedvars, int nfixedvars, int startnvars,
4646
SCIP_CONS** conss, int nconss, int maxnconss, int startnconss,
4747
SCIP_Bool genericnames, SCIP_RESULT* result) noexcept with gil:
48+
cdef int i
4849
cdef SCIP_READERDATA* readerdata
4950
readerdata = SCIPreaderGetData(reader)
5051
cdef int fd = fileno(file)

0 commit comments

Comments
 (0)