#12823: Allow constants for objective function & deletion of rows in
MixedIntegerLinearProgram
--------------------------------------+-------------------------------------
       Reporter:  john_perry          |         Owner:  ncohen      
           Type:  defect              |        Status:  needs_review
       Priority:  major               |     Milestone:  sage-5.0    
      Component:  linear programming  |    Resolution:              
       Keywords:  solver objective    |   Work issues:              
Report Upstream:  N/A                 |     Reviewers:              
        Authors:  john_perry, ncohen  |     Merged in:              
   Dependencies:  12833               |      Stopgaps:              
--------------------------------------+-------------------------------------

Comment (by ncohen):

 > Why do you enumerate the constraints in coin_backend, maybe others? Why
 not simply loop i from 0 to len(constraints)?

 Oh. Because I have been told that "enumerate" had been "optimised", and
 that as "for i in range(n)" it was translated into "good C code".
 Actually, here is what it gives :

 {{{
   __pyx_t_4 = 0;
   __pyx_t_1 = ((PyObject *)__pyx_v_coeff); __Pyx_INCREF(__pyx_t_1);
 __pyx_t_5 = 0;
   for (;;) {
     if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
     __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5);
 __Pyx_INCREF(__pyx_t_2); __pyx_t_5++;
     __Pyx_XDECREF(__pyx_v_v);
     __pyx_v_v = __pyx_t_2;
     __pyx_t_2 = 0;
     __pyx_v_i = __pyx_t_4;
     __pyx_t_4 = (__pyx_t_4 + 1);
 }}}

 So it is more or less the same... In particular, when you have a "for i in
 range(len(something))" I guess the "len(something)" is evaluated many
 times.

 {{{
   __pyx_t_4 = PyObject_Length(__pyx_v_constraints); if (unlikely(__pyx_t_4
 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno =
 __LINE__; goto __pyx_L1_error;}
   for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
     __pyx_v_i = __pyx_t_5;
 }}}

 Oh. No, it is not. Ok well.. It looks like it is indeed better as an
 range(len(thing)) `:-D`
 And anyway it makes more sense this way... Of course there is no way to
 ensure that "len(thing)" does not change between the loops, but the
 meaning of "range(len(thing))" is clear, even if "thing" changed later on
 in the loop.

 Updated !

 > Seems to me the test should be
 > {{{
 >   if c < 0 or c >= nrows:
 > }}}
 > shouldn't it?

 Yeah totally.... Stupid me.

 Nathann

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12823#comment:12>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to