# 16.3 Class Env¶

mosek.Env

The MOSEK global environment.

Env.Env
Env(licensefile=None, debugfile=None)


Constructor of a new environment.

Parameters:

• licensefile (str) – License file to use. (input)
• debugfile (str) – File where the memory debugging log is written. (input)
Env.Task
def Task (maxnumcon=0, maxnumvar=0) -> task


Parameters:

• maxnumcon (int) – An optional hint about the maximal number of constraints in the task. (input)
• maxnumvar (int) – An optional hint about the maximal number of variables in the task. (input)
Return:

task (Task) – A new task.

Env.__del__
def __del__ ()


Free the underlying native allocation.

Env.axpy
def axpy (n, alpha, x, y)


Adds $$\alpha x$$ to $$y$$, i.e. performs the update

$y := \alpha x + y.$

Note that the result is stored overwriting $$y$$.

Parameters:

• n (int) – Length of the vectors. (input)
• alpha (float) – The scalar that multiplies $$x$$. (input)
• x (float[]) – The $$x$$ vector. (input)
• y (float[]) – The $$y$$ vector. (input/output)
Groups:

Linear algebra

Env.checkinall
def checkinall ()


Groups:
Environment management
Env.checkinlicense
def checkinlicense (feature)


Check in a license feature to the license server. By default all licenses consumed by functions using a single environment are kept checked out for the lifetime of the MOSEK environment. This function checks in a given license feature back to the license server immediately.

If the given license feature is not checked out at all, or it is in use by a call to Task.optimize, calling this function has no effect.

Please note that returning a license to the license server incurs a small overhead, so frequent calls to this function should be avoided.

Parameters:
feature (mosek.feature) – Feature to check in to the license system. (input)
Groups:
Environment management
Env.checkoutlicense
def checkoutlicense (feature)


Checks out a license feature from the license server. Normally the required license features will be automatically checked out the first time they are needed by the function Task.optimize. This function can be used to check out one or more features ahead of time.

The feature will remain checked out until the environment is deleted or the function Env.checkinlicense is called.

If a given feature is already checked out when this function is called, the call has no effect.

Parameters:
feature (mosek.feature) – Feature to check out from the license system. (input)
Groups:
Environment management
Env.computesparsecholesky
def computesparsecholesky (multithread, ordermethod, tolsingular, anzc, aptrc, asubc, avalc) -> perm, diag, lnzc, lptrc, lensubnval, lsubc, lvalc


The function computes a Cholesky factorization of a sparse positive semidefinite matrix. Sparsity is exploited during the computations to reduce the amount of space and work required. Both the input and output matrices are represented using the sparse format.

To be precise, given a symmetric matrix $$A \in \real^{n\times n}$$ the function computes a nonsingular lower triangular matrix $$L$$, a diagonal matrix $$D$$ and a permutation matrix $$P$$ such that

$LL^T - D = P A P^T.$

If ordermethod is zero then reordering heuristics are not employed and $$P$$ is the identity.

If a pivot during the computation of the Cholesky factorization is less than

$-\rho\cdot\max((PAP^T)_{jj},1.0)$

then the matrix is declared negative semidefinite. On the hand if a pivot is smaller than

$\rho\cdot\max((PAP^T)_{jj},1.0),$

then $$D_{jj}$$ is increased from zero to

$\rho\cdot\max((PAP^T)_{jj},1.0).$

Therefore, if $$A$$ is sufficiently positive definite then $$D$$ will be the zero matrix. Here $$\rho$$ is set equal to value of tolsingular.

Parameters:

• multithread (int) – If nonzero then the function may exploit multiple threads. (input)
• ordermethod (int) – If nonzero, then a sparsity preserving ordering will be employed. (input)
• tolsingular (float) – A positive parameter controlling when a pivot is declared zero. (input)
• anzc (int[]) – anzc[j] is the number of nonzeros in the $$j$$-th column of $$A$$. (input)
• aptrc (int[]) – aptrc[j] is a pointer to the first element in column $$j$$ of $$A$$. (input)
• asubc (int[]) – Row indexes for each column stored in increasing order. (input)
• avalc (float[]) – The value corresponding to row indexed stored in asubc. (input)
Return:

• perm (int[]) – Permutation array used to specify the permutation matrix $$P$$ computed by the function.
• diag (float[]) – The diagonal elements of matrix $$D$$.
• lnzc (int[]) – lnzc[j] is the number of non zero elements in column $$j$$ of $$L$$.
• lptrc (int[]) – lptrc[j] is a pointer to the first row index and value in column $$j$$ of $$L$$.
• lensubnval (int) – Number of elements in lsubc and lvalc.
• lsubc (int[]) – Row indexes for each column stored in increasing order.
• lvalc (float[]) – The values corresponding to row indexed stored in lsubc.
Groups:

Linear algebra

Env.dot
def dot (n, x, y) -> xty


Computes the inner product of two vectors $$x,y$$ of length $$n\geq 0$$, i.e

$x\cdot y= \sum_{i=1}^n x_i y_i.$

Note that if $$n=0$$, then the result of the operation is 0.

Parameters:

• n (int) – Length of the vectors. (input)
• x (float[]) – The $$x$$ vector. (input)
• y (float[]) – The $$y$$ vector. (input)
Return:

xty (float) – The result of the inner product between $$x$$ and $$y$$.

Groups:

Linear algebra

Env.echointro
def echointro (longver)


Prints an intro to message stream.

Parameters:
longver (int) – If non-zero, then the intro is slightly longer. (input)
Groups:
Env.gemm
def gemm (transa, transb, m, n, k, alpha, a, b, beta, c)


Performs a matrix multiplication plus addition of dense matrices. Given $$A$$, $$B$$ and $$C$$ of compatible dimensions, this function computes

$C:= \alpha op(A)op(B) + \beta C$

where $$\alpha,\beta$$ are two scalar values. The function $$op(X)$$ denotes $$X$$ if transX is transpose.no, or $$X^T$$ if set to transpose.yes. The matrix $$C$$ has $$m$$ rows and $$n$$ columns, and the other matrices must have compatible dimensions.

The result of this operation is stored in $$C$$.

Parameters:

• transa (mosek.transpose) – Indicates whether the matrix $$A$$ must be transposed. (input)
• transb (mosek.transpose) – Indicates whether the matrix $$B$$ must be transposed. (input)
• m (int) – Indicates the number of rows of matrix $$C$$. (input)
• n (int) – Indicates the number of columns of matrix $$C$$. (input)
• k (int) – Specifies the common dimension along which $$op(A)$$ and $$op(B)$$ are multiplied. For example, if neither $$A$$ nor $$B$$ are transposed, then this is the number of columns in $$A$$ and also the number of rows in $$B$$. (input)
• alpha (float) – A scalar value multiplying the result of the matrix multiplication. (input)
• a (float[]) – The pointer to the array storing matrix $$A$$ in a column-major format. (input)
• b (float[]) – The pointer to the array storing matrix $$B$$ in a column-major format. (input)
• beta (float) – A scalar value that multiplies $$C$$. (input)
• c (float[]) – The pointer to the array storing matrix $$C$$ in a column-major format. (input/output)
Groups:

Linear algebra

Env.gemv
def gemv (transa, m, n, alpha, a, x, beta, y)


Computes the multiplication of a scaled dense matrix times a dense vector, plus a scaled dense vector. Precisely, if trans is transpose.no then the update is

$y := \alpha A x + \beta y,$

and if trans is transpose.yes then

$y := \alpha A^T x + \beta y,$

where $$\alpha,\beta$$ are scalar values and $$A$$ is a matrix with $$m$$ rows and $$n$$ columns.

Note that the result is stored overwriting $$y$$.

Parameters:

• transa (mosek.transpose) – Indicates whether the matrix $$A$$ must be transposed. (input)
• m (int) – Specifies the number of rows of the matrix $$A$$. (input)
• n (int) – Specifies the number of columns of the matrix $$A$$. (input)
• alpha (float) – A scalar value multiplying the matrix $$A$$. (input)
• a (float[]) – A pointer to the array storing matrix $$A$$ in a column-major format. (input)
• x (float[]) – A pointer to the array storing the vector $$x$$. (input)
• beta (float) – A scalar value multiplying the vector $$y$$. (input)
• y (float[]) – A pointer to the array storing the vector $$y$$. (input/output)
Groups:

Linear algebra

Env.getcodedesc
@staticmethod
def getcodedesc (code) -> symname, str


Obtains a short description of the meaning of the response code given by code.

Parameters:

code (mosek.rescode) – A valid MOSEK response code. (input)

Return:

• symname (str) – Symbolic name corresponding to code.
• str (str) – Obtains a short description of a response code.
Groups:

Env.getversion
@staticmethod
def getversion () -> major, minor, build, revision


Obtains MOSEK version information.

Return:

• major (int) – Major version number.
• minor (int) – Minor version number.
• build (int) – Build number.
• revision (int) – Revision number.
Env.licensecleanup
@staticmethod


Stops all threads and deletes all handles used by the license system. If this function is called, it must be called as the last MOSEK API call. No other MOSEK API calls are valid after this.

Groups:
Environment management
Env.linkfiletostream
def linkfiletostream (whichstream, filename, append)


Sends all output from the stream defined by whichstream to the file given by filename.

Parameters:

• whichstream (mosek.streamtype) – Index of the stream. (input)
• filename (str) – A valid file name. (input)
• append (int) – If this argument is 0 the file will be overwritten, otherwise it will be appended to. (input)
Groups:

Logging

Env.potrf
def potrf (uplo, n, a)


Computes a Cholesky factorization of a real symmetric positive definite dense matrix.

Parameters:

• uplo (mosek.uplo) – Indicates whether the upper or lower triangular part of the matrix is stored. (input)
• n (int) – Dimension of the symmetric matrix. (input)
• a (float[]) – A symmetric matrix stored in column-major order. Only the lower or the upper triangular part is used, accordingly with the uplo parameter. It will contain the result on exit. (input/output)
Groups:

Linear algebra

Env.putlicensecode
def putlicensecode (code)


Parameters:
code (int[]) – A runtime license code. (input)
Groups:
Environment management
Env.putlicensedebug
def putlicensedebug (licdebug)


Enables debug information for the license system. If licdebug is non-zero, then MOSEK will print debug info regarding the license checkout.

Parameters:
licdebug (int) – Whether license checkout debug info should be printed. (input)
Groups:
Environment management
Env.putlicensepath
def putlicensepath (licensepath)


Set the path to the license file.

Parameters:
licensepath (str) – A path specifying where to search for the license. (input)
Groups:
Environment management
Env.putlicensewait
def putlicensewait (licwait)


Control whether MOSEK should wait for an available license if no license is available. If licwait is non-zero, then MOSEK will wait for licwait-1 milliseconds between each check for an available license.

Parameters:
licwait (int) – Whether MOSEK should wait for a license if no license is available. (input)
Groups:
Environment management
Env.set_Stream
def set_Stream (whichstream, callback)


Directs all output from a environment stream to a callback function.

Parameters:

Env.sparsetriangularsolvedense
def sparsetriangularsolvedense (transposed, lnzc, lptrc, lsubc, lvalc, b)


The function solves a triangular system of the form

$L x = b$

or

$L^T x = b$

where $$L$$ is a sparse lower triangular nonsingular matrix. This implies in particular that diagonals in $$L$$ are nonzero.

Parameters:

• transposed (mosek.transpose) – Controls whether to use with $$L$$ or $$L^T$$. (input)
• lnzc (int[]) – lnzc[j] is the number of nonzeros in column j. (input)
• lptrc (int[]) – lptrc[j] is a pointer to the first row index and value in column j. (input)
• lsubc (int[]) – Row indexes for each column stored sequentially. Must be stored in increasing order for each column. (input)
• lvalc (float[]) – The value corresponding to the row index stored in lsubc. (input)
• b (float[]) – The right-hand side of linear equation system to be solved as a dense vector. (input/output)
Groups:

Linear algebra

Env.syeig
def syeig (uplo, n, a, w)


Computes all eigenvalues of a real symmetric matrix $$A$$. Given a matrix $$A\in\real^{n\times n}$$ it returns a vector $$w\in\real^n$$ containing the eigenvalues of $$A$$.

Parameters:

• uplo (mosek.uplo) – Indicates whether the upper or lower triangular part is used. (input)
• n (int) – Dimension of the symmetric input matrix. (input)
• a (float[]) – A symmetric matrix $$A$$ stored in column-major order. Only the part indicated by uplo is used. (input)
• w (float[]) – Array of length at least n containing the eigenvalues of $$A$$. (output)
Groups:

Linear algebra

Env.syevd
def syevd (uplo, n, a, w)


Computes all the eigenvalues and eigenvectors a real symmetric matrix. Given the input matrix $$A\in \real^{n\times n}$$, this function returns a vector $$w\in \real^n$$ containing the eigenvalues of $$A$$ and it also computes the eigenvectors of $$A$$. Therefore, this function computes the eigenvalue decomposition of $$A$$ as

$A= U V U^T,$

where $$V=\diag(w)$$ and $$U$$ contains the eigenvectors of $$A$$.

Note that the matrix $$U$$ overwrites the input data $$A$$.

Parameters:

• uplo (mosek.uplo) – Indicates whether the upper or lower triangular part is used. (input)
• n (int) – Dimension of the symmetric input matrix. (input)
• a (float[]) – A symmetric matrix $$A$$ stored in column-major order. Only the part indicated by uplo is used. On exit it will be overwritten by the matrix $$U$$. (input/output)
• w (float[]) – Array of length at least n containing the eigenvalues of $$A$$. (output)
Groups:

Linear algebra

Env.syrk
def syrk (uplo, trans, n, k, alpha, a, beta, c)


Performs a symmetric rank-$$k$$ update for a symmetric matrix.

Given a symmetric matrix $$C\in \real^{n\times n}$$, two scalars $$\alpha,\beta$$ and a matrix $$A$$ of rank $$k\leq n$$, it computes either

$C := \alpha A A^T + \beta C,$

when trans is set to transpose.no and $$A\in \real^{n\times k}$$, or

$C := \alpha A^T A + \beta C,$

when trans is set to transpose.yes and $$A\in \real^{k\times n}$$.

Only the part of $$C$$ indicated by uplo is used and only that part is updated with the result.

Parameters:

• uplo (mosek.uplo) – Indicates whether the upper or lower triangular part of $$C$$ is used. (input)
• trans (mosek.transpose) – Indicates whether the matrix $$A$$ must be transposed. (input)
• n (int) – Specifies the order of $$C$$. (input)
• k (int) – Indicates the number of rows or columns of $$A$$, depending on whether or not it is transposed, and its rank. (input)
• alpha (float) – A scalar value multiplying the result of the matrix multiplication. (input)
• a (float[]) – The pointer to the array storing matrix $$A$$ in a column-major format. (input)
• beta (float) – A scalar value that multiplies $$C$$. (input)
• c (float[]) – The pointer to the array storing matrix $$C$$ in a column-major format. (input/output)
Groups:

Linear algebra