# 14.2.2 Class BaseVariable¶

- mosek.fusion.BaseVariable¶
An abstract variable object. This is class provides various default implementations of methods in

`Variable`

.- Members:
BaseVariable.Antidiag – Return the antidiagonal of a square variable matrix.

BaseVariable.AsExpr – Create an expression corresponding to the variable object.

BaseVariable.Diag – Return the diagonal of a square variable matrix.

BaseVariable.Dual – Get the dual solution value of the variable.

BaseVariable.Eval – Evaluate the expression and push the result onto the work stack.

BaseVariable.FromTril – Convert from a trilinear representation into a square variable.

BaseVariable.GetDim – Return the d’th dimension in the expression.

BaseVariable.GetModel – Get the Model object that the variable belongs to.

BaseVariable.GetND – Get the number of dimensions in the variable shape.

BaseVariable.GetShape – Get the variable shape.

BaseVariable.GetSize – Get the total number of elements in the variable.

BaseVariable.Index – Return a variable slice of size 1 corresponding to a single element in the variable object..

BaseVariable.Level – Get the primal solution value of the variable.

BaseVariable.MakeContinuous – Drop integrality constraints on the variable, if any.

BaseVariable.MakeInteger – Apply integrality constraints on the variable. Has no effect on elements of semidefinite matrix variables.

BaseVariable.Pick – Create a one-dimensional variable by picking a list of indexes from this variable.

BaseVariable.Remove – Remove the variable from the model.

BaseVariable.Reshape – Reshape the variable. The new shape must have the same total size as the current.

BaseVariable.SetLevel – Input solution values for this variable

BaseVariable.Slice – Create a slice variable by picking a range of indexes for each variable dimension.

BaseVariable.ToString – Create a string representation of the variable.

BaseVariable.Transpose – Transpose the variable.

BaseVariable.Tril – Convert from a square variable to a trilinear representation.

- Implemented by:

- BaseVariable.Antidiag¶
Variable Antidiag() Variable Antidiag(int index)

Return the antidiagonal of a square variable matrix.

- Parameters:
`index`

(`int`

) – Index of the anti-diagonal- Return:
(

`Variable`

)

- BaseVariable.AsExpr¶
Expression AsExpr()

Create an

`Expression`

object corresponding to \(I\cdot V\), where \(I\) is the identity matrix and \(V\) is this variable.- Return:

- BaseVariable.Diag¶
Variable Diag() Variable Diag(int index)

Return the diagonal of a square variable matrix.

- Parameters:
`index`

(`int`

) – Index of the anti-diagonal- Return:
(

`Variable`

)

- BaseVariable.Dual¶
double[] Dual()

Get the dual solution value of the variable as an array. When the selected slice is multi-dimensional, this corresponds to the flattened slice of solution values.

- Return:
(

`double`

[])

- BaseVariable.Eval¶
void Eval(WorkStack rs, WorkStack ws, WorkStack xs)

Evaluate the expression and push the result onto the

`rs`

work stack.

- BaseVariable.FromTril¶
Variable FromTril(int d) Variable FromTril(int dim0, int d)

Convert from a trilinear representation into a square variable.

- Parameters:
`d`

(`int`

) – Dimension of the square variable.`dim0`

(`int`

) – Index of the trilinear variable slices in a multi-dimensional representation.

- Return:
(

`Variable`

)

- BaseVariable.GetDim¶
int GetDim(int d)

Return the d’th dimension in the expression.

- Parameters:
`d`

(`int`

)- Return:
(

`int`

)

- BaseVariable.GetModel¶
Model GetModel()

Get the Model object that the variable belongs to.

- Return:
(

`Model`

)

- BaseVariable.GetND¶
int GetND()

Get the number of dimensions in the variable shape.

- Return:
(

`int`

)

- BaseVariable.GetShape¶
int[] GetShape()

Get the variable shape.

- Return:
(

`int`

[])

- BaseVariable.GetSize¶
long GetSize()

Get the total number of elements in the variable.

- Return:
(

`long`

)

- BaseVariable.Index¶
Variable Index(int index) Variable Index(int[] index) Variable Index(int i0, int i1) Variable Index(int i0, int i1, int i2)

Return a variable slice of size 1 corresponding to a single element in the variable object..

- Parameters:
`index`

(`int`

)`index`

(`int`

[])`i0`

(`int`

) – Index in the first dimension of the element requested.`i1`

(`int`

) – Index in the second dimension of the element requested.`i2`

(`int`

) – Index in the second dimension of the element requested.

- Return:
(

`Variable`

)

- BaseVariable.Level¶
double[] Level()

Get the primal solution value of the variable as an array. When the selected slice is multi-dimensional, this corresponds to the flattened slice of solution values.

- Return:
(

`double`

[])

- BaseVariable.MakeContinuous¶
void MakeContinuous()

Drop integrality constraints on the variable, if any.

- BaseVariable.MakeInteger¶
void MakeInteger()

Apply integrality constraints on the variable. Has no effect on elements of semidefinite matrix variables.

- BaseVariable.Pick¶
Variable Pick(int[] idxs) Variable Pick(int[,] midxs) Variable Pick(int[] i0, int[] i1) Variable Pick(int[] i0, int[] i1, int[] i2)

Create a one-dimensional variable by picking a list of indexes from this variable.

- Parameters:
`idxs`

(`int`

[]) – Indexes of the elements requested.`midxs`

(`int`

[,]) – A sequence of multi-dimensional indexes of the elements requested.`i0`

(`int`

[]) – Index along the first dimension.`i1`

(`int`

[]) – Index along the second dimension.`i2`

(`int`

[]) – Index along the third dimension.

- Return:
(

`Variable`

)

- BaseVariable.Remove¶
void Remove()

Remove the variable from the model and remove it from any constraints where it appears. Using the variable object after this method has been called results in undefined behavior.

- BaseVariable.Reshape¶
Variable Reshape(int[] shape) Variable Reshape(int dim0) Variable Reshape(int dim0, int dim1) Variable Reshape(int dim0, int dim1, int dim2)

Reshape the variable. The new shape must have the same total size as the current.

- Parameters:
`shape`

(`int`

[]) – The new shape.`dim0`

(`int`

) – First dimension of new shape`dim1`

(`int`

) – Second dimension of new shape`dim2`

(`int`

) – Third dimension of new shape

- Return:
(

`Variable`

)

- BaseVariable.SetLevel¶
void SetLevel(double[] v)

Set values for an initial solution for this variable. Note that these values are buffered until the solver is called; they are not available through the

`level()`

methods.- Parameters:
`v`

(`double`

[]) – An array of values to be assigned to the variable.

- BaseVariable.Slice¶
Variable Slice(int first, int last) Variable Slice(int[] first, int[] last)

Create a slice variable by picking a range of indexes for each variable dimension.

- Parameters:
`first`

(`int`

) – The index from which the slice begins.`first`

(`int`

[]) – The index from which the slice begins.`last`

(`int`

) – The index after the last element of the slice.`last`

(`int`

[]) – The index after the last element of the slice.

- Return:
(

`Variable`

)

- BaseVariable.ToString¶
string ToString()

Create a string representation of the variable.

- Return:
(

`string`

)

- BaseVariable.Transpose¶
Variable Transpose()

Return the transpose of the current variable. The variable must have at most two dimensions.

- Return:
(

`Variable`

)

- BaseVariable.Tril¶
Variable Tril() Variable Tril(int dim1, int dim2)

Convert from a square variable to a trilinear representation.

- Parameters:
`dim1`

(`int`

) – First dimension in the current shape containing the square variables.`dim2`

(`int`

) – Second dimension in the current shape containing the square variables.

- Return:
(

`Variable`

)