def SolveForZ(self):
    """Solve for z in (alpha + beta.wd.wd^T)z = wd . x + alpha z_est - gamma exactly.

    Output goes in z. temp is a matrix to store wd^Twd.
    """
    input_layer = self.input_layer
    code_layer = self.code_layer
    z = code_layer.state
    wd = self.decoder.params['weight']
    hyp = code_layer.hyperparams
    alpha = hyp.sc_alpha
    beta = hyp.sc_beta
    gamma = hyp.sc_gamma
    temp = code_layer.m_by_m
    temp2 = code_layer.deriv
    eye_m_by_m = code_layer.eye_m_by_m

    cm.dot(wd, wd.T, target=temp)
    temp.mult(beta)
    temp.add(alpha)
    z_est.mult(alpha, target=temp2)
    temp2.add_dot(wd, x, mult=beta)
    temp2.subtract(gamma)

    # Copy matrices to cpu.
    A = temp.asarray()
    B = temp2.asarray()

    # Solve AZ = B
    Z = scipy.linalg.solve(A, B, overwrite_a=True, overwrite_b=True)
    
    # Copy result back to gpu.
    z.overwrite(Z)
Solve for z in (alpha + beta.wd.wd^T)z = wd . x + alpha z_est - gamma exactly.

    Output goes in z. temp is a matrix to store wd^Twd.
    
deepnet/sparse_coder.py