MCPcopy Create free account
hub / github.com/numpy/numpy / _generate_config

Method _generate_config

numpy/distutils/ccompiler_opt.py:2586–2646  ·  view source on GitHub ↗
(self, output_dir, dispatch_src, targets, has_baseline=False)

Source from the content-addressed store, hash-verified

2584 return wrap_path
2585
2586 def _generate_config(self, output_dir, dispatch_src, targets, has_baseline=False):
2587 config_path = os.path.basename(dispatch_src)
2588 config_path = os.path.splitext(config_path)[0] + '.h'
2589 config_path = os.path.join(output_dir, config_path)
2590 # check if targets didn't change to avoid recompiling
2591 cache_hash = self.cache_hash(targets, has_baseline)
2592 try:
2593 with open(config_path) as f:
2594 last_hash = f.readline().split("cache_hash:")
2595 if len(last_hash) == 2 and int(last_hash[1]) == cache_hash:
2596 return True
2597 except OSError:
2598 pass
2599
2600 os.makedirs(os.path.dirname(config_path), exist_ok=True)
2601
2602 self.dist_log("generate dispatched config -> ", config_path)
2603 dispatch_calls = []
2604 for tar in targets:
2605 if isinstance(tar, str):
2606 target_name = tar
2607 else: # multi target
2608 target_name = '__'.join([t for t in tar])
2609 req_detect = self.feature_detect(tar)
2610 req_detect = '&&'.join([
2611 "CHK(%s)" % f for f in req_detect
2612 ])
2613 dispatch_calls.append(
2614 "\t%sCPU_DISPATCH_EXPAND_(CB((%s), %s, __VA_ARGS__))" % (
2615 self.conf_c_prefix_, req_detect, target_name
2616 ))
2617 dispatch_calls = ' \\\n'.join(dispatch_calls)
2618
2619 if has_baseline:
2620 baseline_calls = (
2621 "\t%sCPU_DISPATCH_EXPAND_(CB(__VA_ARGS__))"
2622 ) % self.conf_c_prefix_
2623 else:
2624 baseline_calls = ''
2625
2626 with open(config_path, "w") as fd:
2627 fd.write(textwrap.dedent("""\
2628 // cache_hash:{cache_hash}
2629 /**
2630 * AUTOGENERATED DON'T EDIT
2631 * Please make changes to the code generator (distutils/ccompiler_opt.py)
2632 */
2633 #ifndef {pfx}CPU_DISPATCH_EXPAND_
2634 #define {pfx}CPU_DISPATCH_EXPAND_(X) X
2635 #endif
2636 #undef {pfx}CPU_DISPATCH_BASELINE_CALL
2637 #undef {pfx}CPU_DISPATCH_CALL
2638 #define {pfx}CPU_DISPATCH_BASELINE_CALL(CB, ...) \\
2639 {baseline_calls}
2640 #define {pfx}CPU_DISPATCH_CALL(CHK, CB, ...) \\
2641 {dispatch_calls}
2642 """).format(
2643 pfx=self.conf_c_prefix_, baseline_calls=baseline_calls,

Callers 1

try_dispatchMethod · 0.95

Calls 7

openFunction · 0.85
cache_hashMethod · 0.80
feature_detectMethod · 0.80
joinMethod · 0.45
splitMethod · 0.45
dist_logMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected