def test_on_all_class_methods_without_decorator(self):
     with capture_stdout_and_stderr() as out:
         cls = ExpensiveClass4()
         do_profile(follow=[cls._get_number4])(cls.expensive_method4)()
     results = _extract_do_profile_results(out[0])
     print(results)
     msg = str(results)
     assert len(results) > 0, msg
     assert results[0] == FIRST_LINE, msg
     assert results[1][5].strip() == 'def expensive_method4(self):', msg
     assert results[2][5].strip() == 'for x in self._get_number4():', msg
     assert results[2][1] == 5001, msg
     assert results[2][2] > 10, msg
     assert results[5] == FIRST_LINE, msg
     assert results[6][5].strip() == 'def _get_number4(self):', msg
Ejemplo n.º 2
0
def profile_hessian(n_values=(4, 8, 16, 32, 64, 96)):
    for n in n_values:
        f = BenchmarkFunction(n)

        step = nd.step_generators.one_step
        cls = nd.Hessian(f, step=step, method='central')
        follow = [cls._derivative_nonzero_order,
                  cls._apply_fd_rule,
                  cls._get_finite_difference_rule,
                  cls._vstack,
                  cls._central_even]
#         cls = nds.Hessian(f, step=None, method='central')
#         follow = [cls._derivative_nonzero_order, ]

        x = 3 * np.ones(n)

        do_profile(follow=follow)(cls)(x)
Ejemplo n.º 3
0
def main0():
    for n in 4, 8, 16, 32, 64, 96:
        f = BenchmarkFunction(n)

        cls = nd.Jacobian(f, method='central')
        function = do_profile(follow=[cls._derivative_nonzero_order,
                                      cls._apply_fd_rule,
                                      cls._get_finite_difference_rule,
                                      cls._vstack])(cls)
        x = 3 * np.ones(n)
        val = function(x)
Ejemplo n.º 4
0
    def test_on_all_class_methods_without_decorator(self):
        with capture_stdout_and_stderr() as out:
            cls = ExpensiveClass4()
            _test4 = do_profile(follow=[cls._get_number4])(
                cls.expensive_method4)()
        results = _extract_do_profile_results(out[0])

        print(results)
        self.assertEqual(results[0], FIRST_LINE)
        self.assertEqual(results[1][5].strip(), 'def expensive_method4(self):')
        self.assertEqual(results[2][5].strip(),
                         'for x in self._get_number4():')
        self.assertEqual(results[2][1], 5001)
        self.assertTrue(results[2][2] > 10)
        self.assertEqual(results[5], FIRST_LINE)
        self.assertEqual(results[6][5].strip(), 'def _get_number4(self):')