def compute_reconstruction_error(ae, X, sess, y=None, dropout=False):
    """
    Compute the reconstruction error for a autoencoder.

    Args:
        ae (model): auto_encoder which have loss, input_tensor and can have dropout attribute.
        X (np.array): data on wich the error is calculted
        sess (tf.Session): current running Session
        y (np.array): labels of X
        dropout (Boolean): Is the autoencoder denoising ?

    Returns:
        float: the computed error
    """
    if dropout:
        feed_dict = {ae.input_tensor: X}
        for i in ae.dropout:
            feed_dict[i] = 1.
    else:
        feed_dict = {ae.input_tensor: X}
    if y is not None:
        feed_dict[ae.true_labels] = y.reshape((-1,))
    return sess.run(ae.loss, feed_dict=feed_dict)