def get_solution(tableau, basis, x, lambd, b_signs):
    """
    Fetch the optimal solution and value from an optimal tableau.

    Parameters
    ----------
    tableau : ndarray(float, ndim=2)
        ndarray of shape (L+1, n+m+L+1) containing the optimal tableau,
        where L=m+k.

    basis : ndarray(int, ndim=1)
        ndarray of shape (L,) containing the optimal basis.

    x : ndarray(float, ndim=1)
        Empty ndarray of shape (n,) to store the primal solution.
        Modified in place.

    lambd : ndarray(float, ndim=1)
        Empty ndarray of shape (L,) to store the dual solution. Modified
        in place.

    b_signs : ndarray(bool, ndim=1)
        ndarray of shape (L,) whose i-th element is True iff the i-th
        element of the vector (b_ub, b_eq) is positive.

    Returns
    -------
    fun : float
        The optimal value.

    """
    n, L = x.size, lambd.size
    aux_start = tableau.shape[1] - L - 1

    x[:] = 0
    for i in range(L):
        if basis[i] < n:
            x[basis[i]] = tableau[i, -1]
    for j in range(L):
        lambd[j] = tableau[-1, aux_start+j]
        if lambd[j] != 0 and b_signs[j]:
            lambd[j] *= -1
    fun = tableau[-1, -1] * (-1)

    return fun