14.3.15 Class Expression

mosek.fusion.Expression

Abstract base class for all objects which can be used as linear expressions of the form \(Ax+b.\)

The main use of this class is to store the result of expressions created by the static methods provided by Expr.

Members:

Expression.eval – Evaluate the expression and push the result onto the work stack.

Expression.getDim – Return the d’th dimension in the expression.

Expression.getModel – Get the associated model.

Expression.getND – Return the number of dimensions in the expression.

Expression.getShape (.shape) – Get the shape of the expression.

Expression.getSize – Return the total number of elements in the expression (the product of the dimensions).

Expression.index ([]) – Get a single element in the expression.

Expression.pick ([]) – Pick a number of elements from the expression.

Expression.slice ([]) – Get a slice of the expression.

Expression.toString – Return a string representation of the expression object.

Implemented by:

BaseExpression, Parameter, Variable

Expression.eval
eval(WorkStack rs, WorkStack ws, WorkStack xs)

Evaluate the expression and push the result onto the rs work stack.

Parameters:
  • rs (WorkStack) – The stack where the result of the evaluation is stored.

  • ws (WorkStack) – The stack used by evaluation to perform intermediate computations. It will be returned in the same state as when the function is called.

  • xs (WorkStack) – An auxiliary stack.

Expression.getDim
getDim(int d) -> int

Return the d’th dimension in the expression.

Parameters:

d (int)

Return:

(int)

Expression.getModel
getModel() -> Model

Get the associated model.

Return:

(Model)

Expression.getND
getND() -> int

Return the number of dimensions in the expression.

Return:

(int)

Expression.getShape (.shape)
getShape() -> int[]

Get the shape of the expression.

The Python operator/property .shape can also be used for this purpose. See Sec. 14.2 (Pythonic extensions) for details.

Return:

(int[])

Expression.getSize
getSize() -> int

Return the total number of elements in the expression (the product of the dimensions).

Return:

(int)

Expression.index ([])
index(int i) -> Expression
index(int[] indexes) -> Expression

Get a single element in the expression.

The Python operator/property [] can also be used for this purpose. See Sec. 14.2 (Pythonic extensions) for details.

Parameters:
  • i (int) – Index of the element to pick.

  • indexes (int[]) – Multi-dimensional index of the element to pick.

Return:

(Expression)

Expression.pick ([])
pick(int[] indexes) -> Expression
pick(int[][] indexrows) -> Expression

Picks a number of elements from the expression and returns them as a one-dimensional expression.

The Python operator/property [] can also be used for this purpose. See Sec. 14.2 (Pythonic extensions) for details.

Parameters:
  • indexes (int[]) – Indexes of the elements to pick

  • indexrows (int[][]) – Indexes of the elements to pick. Each row defines a separate multi-dimensional index.

Return:

(Expression)

Expression.slice ([])
slice(int first, int last) -> Expression
slice(int[] firsta, int[] lasta) -> Expression

Get a slice of the expression.

The Python operator/property [] can also be used for this purpose. See Sec. 14.2 (Pythonic extensions) for details.

Parameters:
  • first (int) – Index of the first element in the slice.

  • last (int) – Index of the last element in the slice plus one.

  • firsta (int[]) – Multi-dimensional index of the first element in the slice.

  • lasta (int[]) – Multi-dimensional index of the element after the end of the slice.

Return:

(Expression)

Expression.toString
toString() -> str

Return a string representation of the expression object.

Return:

(str)