def _compute_stat(fit, residuals, weights):
    if (weights is None):
        fit['rmse'] = float(np.sqrt(np.mean((2 * (residuals ** 2)))))
        fit['mae'] = float(np.mean(np.linalg.norm(residuals, axis=1)))
        fit['std'] = float(np.linalg.norm(residuals.std(axis=0)))
    else:
        npts = len(weights)
        wt = np.sum(weights)
        if ((npts == 0) or (wt == 0.0)):
            fit['rmse'] = float('nan')
            fit['mae'] = float('nan')
            fit['std'] = float('nan')
            return
        w = (weights / wt)
        fit['rmse'] = float(np.sqrt(np.sum(np.dot(w, (residuals ** 2)))))
        fit['mae'] = float(np.dot(w, np.linalg.norm(residuals, axis=1)))
        if (npts == 1):
            fit['std'] = 0.0
        else:
            wmean = np.dot(w, residuals)
            fit['std'] = float(np.sqrt(np.sum((np.dot(w, ((residuals - wmean) ** 2)) / (1.0 - np.sum((w ** 2)))))))
def _compute_stat(fit, residuals, weights):
    if (weights is None):
        fit['rmse'] = float(np.sqrt(np.mean((2 * (residuals ** 2)))))
        fit['mae'] = float(np.mean(np.linalg.norm(residuals, axis=1)))
        fit['std'] = float(np.linalg.norm(residuals.std(axis=0)))
    else:
        npts = len(weights)
        wt = np.sum(weights)
        if ((npts == 0) or (wt == 0.0)):
            fit['rmse'] = float('nan')
            fit['mae'] = float('nan')
            fit['std'] = float('nan')
            return
        w = (weights / wt)
        fit['rmse'] = float(np.sqrt(np.sum(np.dot(w, (residuals ** 2)))))
        fit['mae'] = float(np.dot(w, np.linalg.norm(residuals, axis=1)))
        if (npts == 1):
            fit['std'] = 0.0
        else:
            wmean = np.dot(w, residuals)
            fit['std'] = float(np.sqrt(np.sum((np.dot(w, ((residuals - wmean) ** 2)) / (1.0 - np.sum((w ** 2)))))))