OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [remove_cycle/] [helper_funs.py] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
import numpy as np
2
import subprocess
3
import os
4
 
5
 
6
def dir_tail_name(file_name):
7
        import os.path
8
        dir_name = os.path.dirname(file_name)
9
        head, tail = os.path.split(file_name)
10
        print("dir name: %s, file_name: %s" % (dir_name,tail))
11
        return dir_name,tail
12
 
13
 
14
def run_command(command,is_print = False):
15
        print command
16
        p = subprocess.Popen(command,shell = True, stdout = subprocess.PIPE)
17
        o = p.communicate()
18
        if is_print:
19
                print o[0]
20
 
21
 
22
def normalize_dict(d,method = "min_max"):
23
        values = d.values()
24
        if method == "min_max":
25
                min_v = min(values)
26
                max_v = max(values)
27
                return {key:(value - min_v)*1.0/(max_v - min_v) for key,value in d.iteritems()}
28
        elif method == "z_score":
29
                mean = np.mean(values)
30
                std = np.std(values)
31
                return {key:(value - mean)*1.0/(std) for key,value in d.iteritems()}
32
 
33
 
34
 
35
def pick_from_dict(d, order = "max"):
36
        min_k, min_v = 0, 10000
37
 
38
        min_items = []
39
        max_k, max_v=  0, -10000
40
 
41
        max_items = []
42
        for k,v in d.iteritems():
43
                if v > max_v:
44
                        max_v = v
45
                        max_items = [(k,max_v)]
46
                elif v == max_v:
47
                        max_items.append((k,v))
48
 
49
                if v < min_v:
50
                        min_v = v
51
                        min_items = [(k,min_v)]
52
                elif v == min_v:
53
                        min_items.append((k,v))
54
 
55
        max_k,max_v = pick_randomly(max_items)
56
        min_k,min_v = pick_randomly(min_items)
57
 
58
        if order == "max":
59
                return max_k,max_v
60
        if order == "min":
61
                return min_k,min_v
62
        else:
63
                return max_k,max_v,min_k,min_v
64
 
65
 
66
def pick_randomly(source):
67
        np.random.shuffle(source)
68
        np.random.shuffle(source)
69
        np.random.shuffle(source)
70
        return source[0]

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.