forked from translunar/nmatrix
-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathttable_helper.rb
executable file
·115 lines (99 loc) · 2.12 KB
/
ttable_helper.rb
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/ruby
# A helper file for generating and maintaining template tables.
DTYPES = [
:uint8_t,
:int8_t,
:int16_t,
:int32_t,
:int64_t,
:float32_t,
:float64_t,
:'nm::Complex64',
:'nm::Complex128',
:'nm::RubyObject'
]
def nullify(disabled = []) #:nodoc:
DTYPES.map { |t| if disabled.include?(t) then :NULL else t end }
end
ITYPES = [
:uint8_t,
:uint16_t,
:uint32_t,
:uint64_t
]
EWOPS = [
:'nm::EW_ADD',
:'nm::EW_SUB',
:'nm::EW_MUL',
:'nm::EW_DIV',
:'nm::EW_POW',
:'nm::EW_MOD',
:'nm::EW_EQEQ',
:'nm::EW_NEQ',
:'nm::EW_LT',
:'nm::EW_GT',
:'nm::EW_LEQ',
:'nm::EW_GEQ'
]
LR_ALLOWED = {
:uint8_t => DTYPES,
:int8_t => DTYPES,
:int16_t => DTYPES,
:int32_t => DTYPES,
:int64_t => DTYPES,
:float32_t => DTYPES,
:float64_t => DTYPES,
:'nm::Complex64' => DTYPES,
:'nm::Complex128' => DTYPES,
:'nm::RubyObject' => DTYPES
}
lines =
case ARGV[0]
when 'OPLR'
'{' +
EWOPS.map do |op|
'{' +
DTYPES.map do |l_dtype|
'{' +
LR_ALLOWED[l_dtype].map do |r_dtype|
if r_dtype == :NULL
'NULL'
else
"fun<#{op}, #{l_dtype}, #{r_dtype}>"
end
end.join(', ') +
'}'
end.join(",\n") +
'}'
end.join(",\n") +
'}'
when 'OPID'
'{' +
EWOPS.map do |op|
'{' +
ITYPES.map do |itype|
'{' +
DTYPES.map do |dtype|
if dtype == :NULL
'NULL'
else
"fun<#{op}, #{itype}, #{dtype}>"
end
end.join(",") +
'}'
end.join(",\\\n") +
'}'
end.join(",\\\n") +
'}'
when 'LR'
'{' + DTYPES.map do |l_dtype|
'{' + LR_ALLOWED[l_dtype].map do |r_dtype|
if r_dtype == :NULL
'NULL'
else
"fun<#{l_dtype}, #{r_dtype}>"
end
end.join(', ') + '}'
end.join(",\n") + '}'
end
puts lines