-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrixparser.py
executable file
·76 lines (62 loc) · 1.55 KB
/
matrixparser.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
#!/usr/bin/python3
import numpy
#csv_file = '/mnt/data/homedir/Documents/UT/Embedded_Computer_Architectures/MatrixValues.csv'
csv_file = '20MatrixValues.csv'
matrix_rows = []
A = numpy.loadtxt(open(csv_file, 'rb'), delimiter=',')
n = numpy.amin(A)
m = numpy.amax(A)
c_rows = []
for row, data in enumerate(A):
c_columns = ['\t{']
for column, value in enumerate(data):
output = "%d, " % int(value)
c_columns.append(output)
c_columns.append('},\n')
c_rows.append("".join(c_columns))
c_rows = "".join(c_rows)
row += 1
column += 1
code = "#ifndef ECAMATRIX_H\n\
#define ECAMATRIX_H\n\
#ifdef ARDUINO_TARGET\n\
const PROGMEM char A[%d][%d] = {\n\
#else\n\
const char A[%d][%d] = {\n\
#endif\n\
%s\n\
};\n\
#endif" % (row, column, row, column, c_rows)
print(code)
print('\n')
with open('ecamatrix.h', 'w') as header:
header.write(code)
C = numpy.dot(A, A)
x = numpy.amin(C)
y = numpy.amax(C)
c_rows = []
for row, data in enumerate(C):
c_columns = ['\t{']
for column, value in enumerate(data):
output = "%d, " % int(value)
c_columns.append(output)
c_columns.append('},\n')
c_rows.append("".join(c_columns))
c_rows = "".join(c_rows)
row += 1
column += 1
code = "#ifndef ANSMATRIX_H\n\
#define ANSAMATRIX_H\n\
#ifdef ARDUINO_TARGET\n\
const PROGMEM int C[%d][%d] = {\n\
#else\n\
const int C[%d][%d] = {\n\
#endif\n\
%s\n\
};\n\
#endif" % (row, column, row, column, c_rows)
print(code)
print('\n')
with open('ansmatrix.h', 'w') as header:
header.write(code)
print("range: %d -- %d --> %d -- %d" % (n, m, x, y))