File: count-cpp-options

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (68 lines) | stat: -rwxr-xr-x 2,060 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3

import os
import re
import yaml
try:
    from yaml import CDumper as MyDumper
    from yaml import CLoader as MyLoader
except ImportError:
    from yaml import Dumper as MyDumper
    from yaml import Loader as MyLoader

import numpy as np


with open(os.path.join("split", "abinit_cpp_map.yml"), "r") as yaml_file:
    cpp_data = yaml.load(yaml_file, Loader=MyLoader)

cpp_map = cpp_data["cpp_map"]
tree_map = cpp_data["tree_map"]

cpp_options = sorted(cpp_map.keys())
cpp_cats = {}
for key, val in tree_map.items():
    for srcdir in val:
        cpp_cats[srcdir] = key

cpp_by_cats = {}
cpp_in_cats = {key: [] for key in tree_map.keys()}
for opt in cpp_options:
    opt_cats = {key: 0 for key in tree_map.keys()} 
    for srcdir in cpp_map[opt].keys():
        opt_cats[cpp_cats[srcdir]] += 1
        cpp_in_cats[cpp_cats[srcdir]].append(opt)
    cpp_by_cats[opt] = opt_cats

for key, val in cpp_in_cats.items():
    cpp_in_cats[key] = sorted(list(set(val)))

cpp_candidates = {key: [] for key in tree_map.keys()}
cpp_exclusive = {key: [] for key in tree_map.keys()}
cpp_profiles = []
for opt, counts in cpp_by_cats.items():
    scores = sorted(list(counts.items()), key=lambda x: x[1])
    cpp_profiles.append([item[1] for item in scores])
    if (scores[0][1] == 0) and (scores[1][1] == 2):
        print(opt, scores)
    elif (scores[0][1] == 0) and (scores[1][1] == 1):
        cpp_candidates[scores[2][0]].append([opt, scores[1][0]])
    elif (scores[0][1] == 0) and (scores[1][1] == 0):
        cpp_exclusive[scores[2][0]].append(opt)
cpp_profiles = np.unique(cpp_profiles, axis=0)
print(cpp_profiles)

stats_data = {
        "candidates": cpp_candidates,
        "counts": cpp_by_cats,
        "cpp_groups": cpp_in_cats,
        "exclusive": cpp_exclusive,
}

with open(os.path.join("split", "abinit_cpp_stats.yml"), "w") as map_file:
    yaml.dump(stats_data, stream=map_file, Dumper=MyDumper,
        default_flow_style=False,
        explicit_start=True,
        explicit_end=True,
        version=(1, 1),
        indent=2)