# Buggy code
def __init__(
    self,
    classifier,
    confidence=0.0,
    targeted=True,
    learning_rate=0.01,
    binary_search_steps=10,
    max_iter=10,
    initial_const=0.01,
    max_halving=5,
    max_doubling=5,
    batch_size=128,
):
    """
    Create a Carlini L_2 attack instance.

    :param classifier: A trained model.
    :type classifier: :class:`Classifier`
    :param confidence: Confidence of adversarial examples: a higher value produces examples that are farther away,
            from the original input, but classified with higher confidence as the target class.
    :type confidence: `float`
    :param targeted: Should the attack target one specific class.
    :type targeted: `bool`
    :param learning_rate: The initial learning rate for the attack algorithm. Smaller values produce better results
            but are slower to converge.
    :type learning_rate: `float`
    :param binary_search_steps: number of times to adjust constant with binary search (positive value).
    :type binary_search_steps: `int`
    :param max_iter: The maximum number of iterations.
    :type max_iter: `int`
    :param initial_const: The initial trade-off constant `c` to use to tune the relative importance of distance and
            confidence. If `binary_search_steps` is large, the initial constant is not important, as discussed in
            Carlini and Wagner (2016).
    :type initial_const: `float`
    :param max_halving: Maximum number of halving steps in the line search optimization.
    :type max_halving: `int`
    :param max_doubling: Maximum number of doubling steps in the line search optimization.
    :type max_doubling: `int`
    :param batch_size: Internal size of batches on which adversarial samples are generated.
    :type batch_size: `int`
    """
    super(CarliniL2Method, self).__init__(classifier)

    kwargs = {
        "confidence": confidence,
        "targeted": targeted,
        "learning_rate": learning_rate,
        "binary_search_steps": binary_search_steps,
        "max_iter": max_iter,
        "initial_const": initial_const,
        "max_halving": max_halving,
        "max_doubling": max_doubling,
        "batch_size": batch_size,
    }
    assert self.set_params(**kwargs)

    # There are internal hyperparameters:
    # Abort binary search for c if it exceeds this threshold (suggested in Carlini and Wagner (2016)):
    self._c_upper_bound = 10e10
    # Smooth arguments of arctanh by multiplying with this constant to avoid division by zero:
    self._tanh_smoother = 0.999999


# 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 __init__(
    self,
    classifier,
    confidence=0.0,
    targeted=True,
    learning_rate=0.01,
    binary_search_steps=10,
    max_iter=10,
    initial_const=0.01,
    max_halving=5,
    max_doubling=5,
    batch_size=128,
    expectation=None,
):
    """
    Create a Carlini L_2 attack instance.

    :param classifier: A trained model.
    :type classifier: :class:`Classifier`
    :param confidence: Confidence of adversarial examples: a higher value produces examples that are farther away,
            from the original input, but classified with higher confidence as the target class.
    :type confidence: `float`
    :param targeted: Should the attack target one specific class.
    :type targeted: `bool`
    :param learning_rate: The initial learning rate for the attack algorithm. Smaller values produce better results
            but are slower to converge.
    :type learning_rate: `float`
    :param binary_search_steps: number of times to adjust constant with binary search (positive value).
    :type binary_search_steps: `int`
    :param max_iter: The maximum number of iterations.
    :type max_iter: `int`
    :param initial_const: The initial trade-off constant `c` to use to tune the relative importance of distance and
            confidence. If `binary_search_steps` is large, the initial constant is not important, as discussed in
            Carlini and Wagner (2016).
    :type initial_const: `float`
    :param max_halving: Maximum number of halving steps in the line search optimization.
    :type max_halving: `int`
    :param max_doubling: Maximum number of doubling steps in the line search optimization.
    :type max_doubling: `int`
    :param batch_size: Internal size of batches on which adversarial samples are generated.
    :type batch_size: `int`
    :param expectation: An expectation over transformations to be applied when computing
                        classifier gradients and predictions.
    :type expectation: :class:`ExpectationOverTransformations`
    """
    super(CarliniL2Method, self).__init__(classifier)

    kwargs = {
        "confidence": confidence,
        "targeted": targeted,
        "learning_rate": learning_rate,
        "binary_search_steps": binary_search_steps,
        "max_iter": max_iter,
        "initial_const": initial_const,
        "max_halving": max_halving,
        "max_doubling": max_doubling,
        "batch_size": batch_size,
        "expectation": expectation,
    }
    assert self.set_params(**kwargs)

    # There are internal hyperparameters:
    # Abort binary search for c if it exceeds this threshold (suggested in Carlini and Wagner (2016)):
    self._c_upper_bound = 10e10
    # Smooth arguments of arctanh by multiplying with this constant to avoid division by zero:
    self._tanh_smoother = 0.999999