CVXMOD – template language

Alert!

CVXMOD is discontinued!

Unfortunately CVXMOD has not been developed since 2008. It is incomplete, somewhat buggy and not supported. Please instead try the replacement package CVXPY. Or, try CVXOPT if you are prepared to work at a lower level, CVX if you are ok with Matlab, or CVXGEN if you want small (but super high speed) QP solvers.

The CVXMOD template language allows you to write a mixture of C and Python code within one source file. Usually this will mean a C file with special symbols that indicate Python sections. During code generation, the Python sections are executed and the output is collected and saved, along with the C, to the output file.

There are three kinds of markup.

Embedding values

Use the result of a simple Python expression in a C file.

for (i = 0; i < @pyval{n}@; i++)

Python code blocks

Python code is executed within the Python namespace, with stdout text appearing in the output file.

@py{
    print '// Produced by CVXMOD, %s.\n' % strftime("%Y-%m-%d %H:%M:%S")
}@

Optional blocks

The bracketed expression on the first line is evaluated within the Python namespace. If true, the rest of the block is added to the output file. The remainder of the block may include @py statements.

@pyif{ (cholmod)
    cholmodsolve(work, params);
}@

@pyif{ (not cholmod)
    ldlsolve(work, params);
}@