linux - permutation with two sets in itertools using python -
i having trouble in rewriting length python code in more pythonic way. here have tried, contains example how want final code like
#!/usr/bin/env python import time import itertools import os freq = [2400000,2000000,1600000,1200000,800000] freq_set = [ [ in itertools.combinations(freq,1)], [ in itertools.combinations(freq,2)], [ in itertools.combinations(freq,3)], [ in itertools.combinations(freq,4)] ] cores = [[0,4],[1,5],[2,6],[3,7]] sets = [[0,4],[0,4,1,5],[0,4,1,5,2,6],[0,4,1,5,2,6,3,7]] # 5 10 10 5 ; 1 3 5 7 freq_set_val in range(0, len(freq_set)): if freq_set_val == 0: change = "echo "+ freq_set[freq_set_val][0] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][0] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" print "do something" change = "echo "+ freq_set[freq_set_val][1] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][1] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" print "do something" change = "echo "+ freq_set[freq_set_val][2] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][2] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" print "do something" change = "echo "+ freq_set[freq_set_val][3] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][3] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" print "do something" change = "echo "+ freq_set[freq_set_val][4] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][4] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" print "do something" if freq_set_val == 1: change = "echo "+ freq_set[freq_set_val][0] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][0] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][1] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][2] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][1] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][3] + "/cpufreq/scaling_setspeed" print "do something" change = "echo "+ freq_set[freq_set_val][1] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][1] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][2] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][2] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][2] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][3] + "/cpufreq/scaling_setspeed" print "do something" change = "echo "+ freq_set[freq_set_val][2] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][2] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][3] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][2] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][3] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][3] + "/cpufreq/scaling_setspeed" print "do something" print "so onn" if freq_set_val == 2: change = "echo "+ freq_set[freq_set_val][0] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][0] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][0] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][1] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][1] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][2] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][1] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][3] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][2] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][4] + "/cpufreq/scaling_setspeed" change = "echo "+ freq_set[freq_set_val][2] +"> /sys/devices/system/cpu/cpu"+ sets[freq_set_val][5] + "/cpufreq/scaling_setspeed" print "do something"
essentially want keep flipping set of cores particular frequency level. after every change
statement. write os.system(change)
could please me out here? tried implementing same using shell. problem not having itertools
package. please feel free change title of question
did not know how phrase it.
this how looks now. prettier version better :) did not know how enhance it
for freq_set_val in range(0, len(freq_set)): if freq_set_val == 0: freq in range(0, len(freq_set[freq_set_val])): val in range(0, len(freq_set[freq_set_val][freq])): change = "echo "+ str(freq_set[freq_set_val][freq][val]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][0]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][val]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][1]) + "/cpufreq/scaling_setspeed" print "do something" if freq_set_val == 1: freq in range(0, len(freq_set[freq_set_val])): change = "echo "+ str(freq_set[freq_set_val][freq][0]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][0]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][0]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][1]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][1]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][2]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][1]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][3]) + "/cpufreq/scaling_setspeed" print "do something" if freq_set_val == 2: freq in range(0, len(freq_set[freq_set_val])): change = "echo "+ str(freq_set[freq_set_val][freq][0]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][0]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][0]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][1]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][1]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][2]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][1]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][3]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][2]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][4]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][2]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][5]) + "/cpufreq/scaling_setspeed" print "do something" if freq_set_val == 3: freq in range(0, len(freq_set[freq_set_val])): change = "echo "+ str(freq_set[freq_set_val][freq][0]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][0]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][0]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][1]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][1]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][2]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][1]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][3]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][2]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][4]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][2]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][5]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][3]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][6]) + "/cpufreq/scaling_setspeed" change = "echo "+ str(freq_set[freq_set_val][freq][3]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][7]) + "/cpufreq/scaling_setspeed" print "do something"
is looking for?
def change_freq(freq_set, freq_set_val, freq, i1, i2): change = "echo "+ str(freq_set[freq_set_val][freq][i1]) +"> /sys/devices/system/cpu/cpu"+ str(sets[freq_set_val][i2]) + "/cpufreq/scaling_setspeed" # os.system(change) freq_set_val in range(0, len(freq_set)): freq in range(0, len(freq_set[freq_set_val])): in range(0, (freq_set_val+1)*2): change_freq(freq_set, freq_set_val, freq, i/2, i) if freq_set_val == 0: print "dosomething" if freq_set_val == 1: print "dosomething" if freq_set_val == 2: print "dosomething" if freq_set_val == 3: print "dosomething"
Comments
Post a Comment