예제 #1
0
 def testcase_method(self):
     options_variants = itertools.product([False, True], repeat=2)
     for opt_min_rows, opt_clear_stack in options_variants:
         bound_decorator = cpmoptimize(
             strict=True, iters_limit=iters_limit,
             opt_min_rows=opt_min_rows, opt_clear_stack=opt_clear_stack,
             verbose=True)
         with self.assertRaisesRegexp(exception, regexp):
             bound_decorator(func)(*args, **kwargs)
 def testcase_method(self):
     options_variants = itertools.product([False, True], repeat=2)
     for opt_min_rows, opt_clear_stack in options_variants:
         bound_decorator = cpmoptimize(
             strict=True, iters_limit=iters_limit,
             opt_min_rows=opt_min_rows, opt_clear_stack=opt_clear_stack,
             verbose=True)
         with self.assertRaisesRegexp(exception, regexp):
             bound_decorator(func)(*args, **kwargs)
예제 #3
0
def apply_options(settings, naive_func, clear_stack, min_rows):
    name = 'cpm'
    if not clear_stack or not min_rows:
        name += ' -'
    if not clear_stack:
        name += 'c'
    if not min_rows:
        name += 'm'

    return (name,
            cpmoptimize(opt_clear_stack=clear_stack,
                        opt_min_rows=min_rows, **settings)(naive_func))
예제 #4
0
def apply_options(settings, naive_func, clear_stack, min_rows):
    name = 'cpm'
    if not clear_stack or not min_rows:
        name += ' -'
    if not clear_stack:
        name += 'c'
    if not min_rows:
        name += 'm'

    return (name, cpmoptimize(
        opt_clear_stack=clear_stack, opt_min_rows=min_rows, **settings
    )(naive_func))
예제 #5
0
        def testcase_method(self):
            expected = func(*args, **kwargs)
            options_variants = itertools.product([False, True], repeat=2)
            actual_variants = []
            for opt_min_rows, opt_clear_stack in options_variants:
                bound_decorator = cpmoptimize(
                    strict=strict, iters_limit=iters_limit,
                    opt_min_rows=opt_min_rows, opt_clear_stack=opt_clear_stack,
                    verbose=True)
                # Debug messages will be generated in verbose mode (so, we can
                # check that this process doesn't cause exceptions),
                # but they won't be shown here (`logging` module
                # doesn't show messages with DEBUG level by default).
                actual_variants.append(bound_decorator(func)(*args, **kwargs))

            for actual in actual_variants:
                self.assertEqual(expected, actual)
        def testcase_method(self):
            expected = func(*args, **kwargs)
            options_variants = itertools.product([False, True], repeat=2)
            actual_variants = []
            for opt_min_rows, opt_clear_stack in options_variants:
                bound_decorator = cpmoptimize(
                    strict=strict, iters_limit=iters_limit,
                    opt_min_rows=opt_min_rows, opt_clear_stack=opt_clear_stack,
                    verbose=True)
                # Debug messages will be generated in verbose mode (so, we can
                # check that this process doesn't cause exceptions),
                # but they won't be shown here (`logging` module
                # doesn't show messages with DEBUG level by default).
                actual_variants.append(bound_decorator(func)(*args, **kwargs))

            for actual in actual_variants:
                self.assertEqual(expected, actual)
예제 #7
0
        res += elem
    return res

def formula(count):
    return (start * 2 + step * (count - 1)) * count / 2

pow10_wrapper = lambda func: (lambda arg: func(10 ** arg))

if __name__ == '__main__':
    common.run(
        'arith_sum', 'N elements',
        common.optimized(naive) + [
            ('formula', formula),
        ],
        [
            ('linear', None, common.linear_scale(600000, 5)),
        ],
        exec_compare=False, draw_plot=False,
    )
    common.run(
        'arith_sum', '10 ** N elements',
        [
            ('cpm', pow10_wrapper(cpmoptimize()(naive))),
            ('formula', pow10_wrapper(formula)),
        ],
        [
            ('exp', None, common.linear_scale(10000, 5)),
        ],
        exec_compare=False, draw_plot=False,
    )