Here are the examples of the python api cpmoptimize.cpmoptimize taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
Example 1
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))
3
Example 2
def check_exception(exception, regexp, args=[], kwargs={}, iters_limit=0):
def decorator(func):
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)
testcase_method.func_name = func.func_name
testcase_method.func_doc = func.func_doc
return testcase_method
return decorator
0
Example 3
def check_correctness(args=[], kwargs={}, strict=True, iters_limit=0):
def decorator(func):
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)
testcase_method.func_name = func.func_name
testcase_method.func_doc = func.func_doc
return testcase_method
return decorator