-
Notifications
You must be signed in to change notification settings - Fork 3
/
utilityFunc.py
94 lines (84 loc) · 2.41 KB
/
utilityFunc.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import numpy
KERNEL_TYPE_MAP = {\
'byte': 'char',\
'ubyte': 'unsigned char',\
'short': 'short',\
'ushort': 'unsigned short',\
'int': 'int',\
'uint': 'unsigned int',\
'float': 'float',\
'long': 'long',\
'string': 'char*'\
}
DS_TYPE_TO_NUMPY_TYPE = {
'byte' : numpy.int8,
'ubyte' : numpy.uint8,
'short' : numpy.int16,
'ushort' : numpy.uint16,
'int' : numpy.int32,
'uint' : numpy.uint32,
'float' : numpy.float32,
'long' : numpy.int64,
'string' : numpy.object
}
DS_TYPE_TO_NUMPY_STRING_TYPE = {
'byte' : 'numpy.int8',
'ubyte' : 'numpy.uint8',
'short' : 'numpy.int16',
'ushort' : 'numpy.uint16',
'int' : 'numpy.int32',
'uint' : 'numpy.uint32',
'float' : 'numpy.float32',
'long' : 'numpy.int64',
'string' : 'numpy.object'
}
def splitNameToWords(strName):
lstSplitWords = []
idxBegin = -1
for idx, c in enumerate(strName):
if c.isupper():
if idxBegin >= 0:
w = strName[idxBegin:idx]
lstSplitWords.append(w)
idxBegin = idx
if idx == (len(strName)-1):
w = strName[idxBegin:]
lstSplitWords.append(w)
return lstSplitWords
def getStructFileName(strName, strFolder=None):
lstSplitWords = splitNameToWords(strName)
ret = ''
for w in lstSplitWords:
ret += w.lower()
ret += '_'
ret += 'structs.h'
if strFolder is not None:
if not os.path.exists(strFolder):
os.makedirs(strFolder)
return os.path.join(strFolder, ret)
else:
return ret
def getKernelFileName(strName, strFolder=None):
lstSplitWords = splitNameToWords(strName)
ret = ''
for w in lstSplitWords:
ret += w.lower()
if w != lstSplitWords[-1]:
ret += '_'
ret += '.c'
if strFolder is not None:
if not os.path.exists(strFolder):
os.makedirs(strFolder)
return os.path.join(strFolder, ret)
else:
return ret
def getKernelType(dataType):
return KERNEL_TYPE_MAP[dataType] if dataType in KERNEL_TYPE_MAP else None
def getPyFileName(strName, strFolder=None):
ret = strName + '.py'
if strFolder is not None:
if not os.path.exists(strFolder):
os.makedirs(strFolder)
return os.path.join(strFolder, ret)
return ret