def get_sos_decomposition(sdp, y_mat=None, threshold=<NUM_LIT:0.0>):
if len(sdp.monomial_sets) != <NUM_LIT:1>:<EOL><INDENT>raise Exception("<STR_LIT>" +<EOL>"<STR_LIT>")<EOL><DEDENT>elif len(sdp.y_mat[<NUM_LIT:1>:]) != len(sdp.constraints):<EOL><INDENT>raise Exception("<STR_LIT>" +<EOL>"<STR_LIT>")<EOL><DEDENT>elif sdp.status == "<STR_LIT>" and y_mat is None:<EOL><INDENT>raise Exception("<STR_LIT>" +<EOL>"<STR_LIT>")<EOL><DEDENT>elif sdp.status != "<STR_LIT>" and y_mat is None:<EOL><INDENT>y_mat = sdp.y_mat<EOL><DEDENT>sos = []<EOL>for y_mat_block in y_mat:<EOL><INDENT>term = <NUM_LIT:0><EOL>vals, vecs = np.linalg.eigh(y_mat_block)<EOL>for j, val in enumerate(vals):<EOL><INDENT>if val < -<NUM_LIT>:<EOL><INDENT>raise Exception("<STR_LIT>" + val +<EOL>"<STR_LIT>")<EOL><DEDENT>elif val > <NUM_LIT:0>:<EOL><INDENT>sub_term = <NUM_LIT:0><EOL>for i, entry in enumerate(vecs[:, j]):<EOL><INDENT>sub_term += entry * sdp.monomial_sets[<NUM_LIT:0>][i]<EOL><DEDENT>term += val * sub_term**<NUM_LIT:2><EOL><DEDENT><DEDENT>term = expand(term)<EOL>new_term = <NUM_LIT:0><EOL>if term.is_Mul:<EOL><INDENT>elements = [term]<EOL><DEDENT>else:<EOL><INDENT>elements = term.as_coeff_mul()[<NUM_LIT:1>][<NUM_LIT:0>].as_coeff_add()[<NUM_LIT:1>]<EOL><DEDENT>for element in elements:<EOL><INDENT>_, coeff = separate_scalar_factor(element)<EOL>if abs(coeff) > threshold:<EOL><INDENT>new_term += element<EOL><DEDENT><DEDENT>sos.append(new_term)<EOL><DEDENT>return sos<EOL>
Given a solution of the dual problem, it returns the SOS
    decomposition.

    :param sdp: The SDP relaxation to be solved.
    :type sdp: :class:`ncpol2sdpa.sdp`.
    :param y_mat: Optional parameter providing the dual solution of the
                  moment matrix. If not provided, the solution is extracted
                  from the sdp object.
    :type y_mat: :class:`numpy.array`.
    :param threshold: Optional parameter for specifying the threshold value
                      below which the eigenvalues and entries of the
                      eigenvectors are disregarded.
    :type threshold: float.
    :returns: The SOS decomposition of [sigma_0, sigma_1, ..., sigma_m]
    :rtype: list of :class:`sympy.core.exp.Expr`.