def _derivative_convergence(self):
        """Verify that the derivative is a first-order approximation.

        The code verifies if

            ``||A(x+c*p) - A(x) - A'(x)(c*p)|| / c = o(c)``

        for ``c --> 0``.
        """
        with FailCounter(
                test_name='Verifying that derivative is a first-order '
                          'approximation',
                err_msg="error = inf_c ||A(x+c*p)-A(x)-A'(x)(c*p)|| / c",
                logger=self.log) as counter:
            for [name_x, x], [name_dx, dx] in samples(self.operator.domain,
                                                      self.operator.domain):
                # Precompute some values
                deriv = self.operator.derivative(x)
                derivdx = deriv(dx)
                opx = self.operator(x)

                c = 1e-4  # initial step
                derivative_ok = False

                minerror = float('inf')
                while c > 1e-14:
                    exact_step = self.operator(x + dx * c) - opx
                    expected_step = c * derivdx
                    err = (exact_step - expected_step).norm() / c

                    # Need to be slightly more generous here due to possible
                    # numerical instabilities.
                    # TODO: perform more tests to find a good threshold here.
                    if err < 10 * self.tol:
                        derivative_ok = True
                        break
                    else:
                        minerror = min(minerror, err)

                    c /= 10.0

                if not derivative_ok:
                    counter.fail('x={:15s} p={:15s}, error={}'
                                 ''.format(name_x, name_dx, minerror))
def _derivative_convergence ( self ) : with FailCounter ( test_name = 'Verifying that derivative is a first-order ' 'approximation' , err_msg = "error = inf_c ||A(x+c*p)-A(x)-A'(x)(c*p)|| / c" , logger = self . log ) as counter : for [ name_x , x ] , [ name_dx , dx ] in samples ( self . operator . domain , self . operator . domain ) : deriv = self . operator . derivative ( x ) derivdx = deriv ( dx ) opx = self . operator ( x ) c = 1e-4 derivative_ok = False minerror = float ( 'inf' ) while c > 1e-14 : exact_step = self . operator ( x + dx * c ) - opx expected_step = c * derivdx err = ( exact_step - expected_step ) . norm ( ) / c if err < 10 * self . tol : derivative_ok = True break else : minerror = min ( minerror , err ) c /= 10.0 if not derivative_ok : counter . fail ( 'x={:15s} p={:15s}, error={}' '' . format ( name_x , name_dx , minerror ) )
Verify that the derivative is a first-order approximation.

        The code verifies if

            ``||A(x+c*p) - A(x) - A'(x)(c*p)|| / c = o(c)``

        for ``c --> 0``.