ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 24 Apr 2014 09:54:32 +0200built in cython integration [beginner]https://ask.sagemath.org/question/11360/built-in-cython-integration-beginner/When I run a built-in sage function that is defined as cython code, does it automatically run compiled code, or do I have to activate cython or something?
For example:
When I run the code
g = graphs.CompleteGraph(10)
g.traveling_salesman_problem()
in a notebook, without anything else, the second command contains instances of 'MixedIntegerLinearProgram', which appears to be a cdef from a pyx file. I've learnt today that this means it is written in cython, and I would like to confirm that if MixedIntegerLinearProgram gets called in g.traveling_salesman_problem(), that it does indeed run compiled code, and that I don't have to do anything special to activate it.Thu, 24 Apr 2014 08:54:25 +0200https://ask.sagemath.org/question/11360/built-in-cython-integration-beginner/Answer by kcrisman for <p>When I run a built-in sage function that is defined as cython code, does it automatically run compiled code, or do I have to activate cython or something?</p>
<p>For example:</p>
<p>When I run the code</p>
<pre><code>g = graphs.CompleteGraph(10)
g.traveling_salesman_problem()
</code></pre>
<p>in a notebook, without anything else, the second command contains instances of 'MixedIntegerLinearProgram', which appears to be a cdef from a pyx file. I've learnt today that this means it is written in cython, and I would like to confirm that if MixedIntegerLinearProgram gets called in g.traveling_salesman_problem(), that it does indeed run compiled code, and that I don't have to do anything special to activate it.</p>
https://ask.sagemath.org/question/11360/built-in-cython-integration-beginner/?answer=16118#post-id-16118Yes.
You can find much of this out by trying
sage: g.traveling_salesman_problem??
to read the code. Note that in this case the function itself is in a .py (uncompiled, though in byte code I think) file. But the line
from sage.numerical.mip import MixedIntegerLinearProgram
indicates it uses MILP, and this is indeed a compiled file (as you can see by doing
sage: sage.numerical.mip.MixedIntegerLinearProgram?
where it indicates an .so file type.
However, in truth this calls an outside program (which you can set, e.g. CPLEX) to do the LP, so the compiled piece is less relevant than the fact that it uses a dedicated library to do the LP.Thu, 24 Apr 2014 09:54:32 +0200https://ask.sagemath.org/question/11360/built-in-cython-integration-beginner/?answer=16118#post-id-16118