Changeset 826 for soft/giet_vm/applications/rosenfeld/scripts/common.py
- Timestamp:
- Jul 13, 2017, 11:01:58 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/scripts/common.py
r822 r826 4 4 import subprocess 5 5 import sys 6 7 6 import shutil 7 import random 8 8 9 9 … … 51 51 shutil.copy(src, dst) 52 52 53 def my_symlink(target, link_name): 54 if not os.path.exists(link_name): 55 print("ln -s %s %s" % (short_path(target), short_path(link_name))) 56 os.symlink(target, link_name) 57 53 58 54 59 def get_random_img_file(density, x, y, granularity, seed): … … 60 65 61 66 return "rand_" + str(x) + "_" + str(y) + "_" + density_str + "_G" + str(granularity) + ".pgm" 67 68 69 # for the HDD constraint of 8 chars 70 def get_short_random_img_file(density, granularity): 71 density_str = str(density) 72 granularity_str = str(granularity) 73 if density < 10: 74 density_str = "0" + density_str 75 if density < 100: 76 density_str = "0" + density_str 77 if granularity < 10: 78 granularity_str = "0" + granularity_str 79 80 return "G" + granularity_str + "_D" + density_str + ".pgm" 81 82 83 84 def get_dirname(dir, nthreads, config, ftrs, granularity, start_den, end_den, basename): 85 start_den_str = str(start_den) 86 end_den_str = str(end_den) 87 if start_den < 10: 88 start_den_str = "0" + start_den_str 89 if start_den < 100: 90 start_den_str = "0" + start_den_str 91 if end_den < 10: 92 end_den_str = "0" + end_den_str 93 if end_den < 100: 94 end_den_str = "0" + end_den_str 95 96 if ftrs: 97 ftrs_str = "_FEATURES_1" 98 else: 99 ftrs_str = "_FEATURES_0" 100 101 config_keys = list(config.keys()) # duplicates list 102 try: 103 config_keys.remove('FEATURES') 104 except: 105 pass 106 config_keys = sorted(config_keys) 107 dirname = os.path.join(dir, basename + "_T" + str(nthreads) + "_G" + str(granularity) + "_D" + start_den_str + "-" + end_den_str + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ftrs_str) 108 109 return dirname 110 111 112 def get_graph_filename(dir, nthreads, granularity, config, ext): 113 config_keys = list(config.keys()) # duplicates list 114 config_keys = sorted(config_keys) 115 filename = os.path.join(dir, "random_T" + str(nthreads) + "_G" + str(granularity) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ext) 116 117 return filename 118 62 119 63 120 … … 74 131 pass 75 132 config_keys = sorted(config_keys) 76 filename = os.path.join(dir, basename + "_ " + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ftrs_str + ".txt")133 filename = os.path.join(dir, basename + "_T" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ftrs_str + ".txt") 77 134 78 135 return filename 79 80 81 def get_graph_filename(dir, nthreads, config, ext):82 config_keys = list(config.keys()) # duplicates list83 config_keys = sorted(config_keys)84 filename = os.path.join(dir, "random_" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ext)85 86 return filename87 88 136 89 137 … … 92 140 retval = subprocess.call(cmd) 93 141 return retval 142 143 144 def print_call_and_check(cmd): 145 retval = print_and_call(cmd) 146 if retval != 0: 147 print("*** Error: command '%s' returned %d\n" % (subprocess.list2cmdline(cmd), retval)) 148 sys.exit(1) 149 94 150 95 151 def print_and_popen(cmd, abs_outfile): … … 113 169 114 170 171 def gen_random_image(filename, x, y, granularity, density, seed): 172 random.seed(seed) 173 img = [[0 for a in range(x)] for b in range(y)] 174 for i in range(0, x, granularity): 175 for j in range(0, y, granularity): 176 r = random.random(); 177 if r < density: 178 px = 255 179 else: 180 px = 0 181 182 for di in range(0, granularity): 183 for dj in range(0, granularity): 184 if i + di < x and j + dj < y: 185 img[i + di][j + dj] = px; 186 187 f = open(filename, 'wb') 188 f.write("P5\n%d %d\n255\n" % (x, y)) 189 for j in range(0, y): 190 bimg = bytearray(img[j]) 191 f.write(bimg) 192 f.close() 193 194
Note: See TracChangeset
for help on using the changeset viewer.