# Buggy code
def set_params(self, **kwargs):
    """
    Take in a dictionary of parameters and applies defence-specific checks before saving them as attributes.

    :param prob: Probability of the Bernoulli distribution.
    :type prob: `float`
    :param norm: The norm (positive integer).
    :type norm: `int`
    :param lam: The lambda parameter in the objective function.
    :type lam: `float`
    :param solver: Current support: L-BFGS-B, CG, Newton-CG
    :type solver: `string`
    :param maxiter: Maximum number of iterations in an optimization.
    :type maxiter: `int`
    """
    # Save defense-specific parameters
    super(TotalVarMin, self).set_params(**kwargs)

    if not isinstance(self.prob, (float, int)) or self.prob < 0.0 or self.prob > 1.0:
        logger.error("Probability must be between 0 and 1.")
        raise ValueError("Probability must be between 0 and 1.")

    if not isinstance(self.norm, (int, np.int)) or self.norm <= 0:
        logger.error("Norm must be a positive integer.")
        raise ValueError("Norm must be a positive integer.")

    if not (
        self.solver == "L-BFGS-B" or self.solver == "CG" or self.solver == "Newton-CG"
    ):
        logger.error("Current support only L-BFGS-B, CG, Newton-CG.")
        raise ValueError("Current support only L-BFGS-B, CG, Newton-CG.")

    if not isinstance(self.maxiter, (int, np.int)) or self.maxiter <= 0:
        logger.error("Number of iterations must be a positive integer.")
        raise ValueError("Number of iterations must be a positive integer.")

    return True


# Traceback (IndexError)
Traceback (most recent call last):
File "cw_pytorch.py", line 172, in <module>
x_test_adv = cl2m.generate(inputs, **params)
File "/home/weitian/anaconda3/envs/xnor/lib/python3.6/site-packages/art/attacks/carlini.py", line 380, in generate
x_adv_batch_tanh[active_and_update_adv] = x_adv_batch_tanh[update_adv] + \
IndexError: boolean index did not match indexed array along dimension 0; dimension is 18 but corresponding boolean dimension is 17

# Fixed code
def set_params(self, **kwargs):
    """
    Take in a dictionary of parameters and applies defence-specific checks before saving them as attributes.

    :param prob: Probability of the Bernoulli distribution.
    :type prob: `float`
    :param norm: The norm (positive integer).
    :type norm: `int`
    :param lamb: The lambda parameter in the objective function.
    :type lamb: `float`
    :param solver: Current support: L-BFGS-B, CG, Newton-CG.
    :type solver: `str`
    :param max_iter: Maximum number of iterations in an optimization.
    :type max_iter: `int`
    """
    # Save defense-specific parameters
    super(TotalVarMin, self).set_params(**kwargs)

    if not isinstance(self.prob, (float, int)) or self.prob < 0.0 or self.prob > 1.0:
        logger.error("Probability must be between 0 and 1.")
        raise ValueError("Probability must be between 0 and 1.")

    if not isinstance(self.norm, (int, np.int)) or self.norm <= 0:
        logger.error("Norm must be a positive integer.")
        raise ValueError("Norm must be a positive integer.")

    if not (
        self.solver == "L-BFGS-B" or self.solver == "CG" or self.solver == "Newton-CG"
    ):
        logger.error("Current support only L-BFGS-B, CG, Newton-CG.")
        raise ValueError("Current support only L-BFGS-B, CG, Newton-CG.")

    if not isinstance(self.max_iter, (int, np.int)) or self.max_iter <= 0:
        logger.error("Number of iterations must be a positive integer.")
        raise ValueError("Number of iterations must be a positive integer.")

    return True