@@ -88,59 +88,10 @@ function compile(proc) {
88
88
return CACHED_CWiseOp [ proc . funcName ]
89
89
}
90
90
91
- function Procedure ( ) {
92
- this . argTypes = [ ]
93
- this . shimArgs = [ ]
94
- this . arrayArgs = [ ]
95
- this . arrayBlockIndices = [ ]
96
- this . scalarArgs = [ ]
97
- this . offsetArgs = [ ]
98
- this . offsetArgIndex = [ ]
99
- this . indexArgs = [ ]
100
- this . shapeArgs = [ ]
101
- this . funcName = ""
102
- this . pre = null
103
- this . body = null
104
- this . post = null
105
- }
106
-
107
91
function cwiseCompiler ( user_args ) {
108
- //Create procedure
109
- var proc = new Procedure ( )
110
-
111
- //Parse blocks
112
- proc . pre = user_args . pre
113
- proc . body = user_args . body
114
- proc . post = user_args . post
115
-
116
- //Parse arguments
117
- var proc_args = user_args . args . slice ( 0 )
118
- proc . argTypes = proc_args
119
- for ( var i = 0 ; i < proc_args . length ; ++ i ) {
120
- var arg_type = proc_args [ i ]
121
- if ( arg_type === "array" || ( typeof arg_type === "object" && arg_type . blockIndices ) ) {
122
- proc . argTypes [ i ] = "array"
123
- proc . arrayArgs . push ( i )
124
- proc . arrayBlockIndices . push ( arg_type . blockIndices ? arg_type . blockIndices : 0 )
125
- proc . shimArgs . push ( "array" + i )
126
- } else if ( arg_type === "scalar" ) {
127
- proc . scalarArgs . push ( i )
128
- proc . shimArgs . push ( "scalar" + i )
129
- } else if ( arg_type === "index" ) {
130
- proc . indexArgs . push ( i )
131
- } else if ( arg_type === "shape" ) {
132
- proc . shapeArgs . push ( i )
133
- } else if ( typeof arg_type === "object" && arg_type . offset ) {
134
- proc . argTypes [ i ] = "offset"
135
- proc . offsetArgs . push ( { array : arg_type . array , offset :arg_type . offset } )
136
- proc . offsetArgIndex . push ( i )
137
- }
138
- }
139
-
140
- //Retrieve name
141
- proc . funcName = user_args . funcName || "cwise"
142
-
143
- return createThunk ( proc )
92
+ return createThunk ( {
93
+ funcName : user_args . funcName
94
+ } )
144
95
}
145
96
146
97
@@ -155,94 +106,18 @@ var EmptyProc = {
155
106
}
156
107
157
108
var centralDiff = cwiseCompiler ( {
158
- args : [ 'array' , 'array' , 'array' ] ,
159
- pre : EmptyProc ,
160
- post : EmptyProc ,
161
- body : {
162
- args : [ {
163
- name : 'out' ,
164
- lvalue : true ,
165
- rvalue : false ,
166
- count : 1
167
- } , {
168
- name : 'left' ,
169
- lvalue : false ,
170
- rvalue : true ,
171
- count : 1
172
- } , {
173
- name : 'right' ,
174
- lvalue : false ,
175
- rvalue : true ,
176
- count : 1
177
- } ] ,
178
- body : "out=0.5*(left-right)" ,
179
- thisVars : [ ] ,
180
- localVars : [ ]
181
- } ,
182
109
funcName : 'cdiff'
183
110
} )
184
111
185
112
var zeroOut = cwiseCompiler ( {
186
- args : [ 'array' ] ,
187
- pre : EmptyProc ,
188
- post : EmptyProc ,
189
- body : {
190
- args : [ {
191
- name : 'out' ,
192
- lvalue : true ,
193
- rvalue : false ,
194
- count : 1
195
- } ] ,
196
- body : "out=0" ,
197
- thisVars : [ ] ,
198
- localVars : [ ]
199
- } ,
200
113
funcName : 'zero'
201
114
} )
202
115
203
116
function generateTemplate ( d ) {
204
117
if ( d in TEMPLATE_CACHE ) {
205
118
return TEMPLATE_CACHE [ d ]
206
119
}
207
- var code = [ ]
208
- for ( var i = 0 ; i < d ; ++ i ) {
209
- code . push ( 'out' , i , 's=0.5*(inp' , i , 'l-inp' , i , 'r);' )
210
- }
211
- var args = [ 'array' ]
212
- var names = [ 'junk' ]
213
- for ( var i = 0 ; i < d ; ++ i ) {
214
- args . push ( 'array' )
215
- names . push ( 'out' + i + 's' )
216
- var o = dup ( d )
217
- o [ i ] = - 1
218
- args . push ( {
219
- array : 0 ,
220
- offset : o . slice ( )
221
- } )
222
- o [ i ] = 1
223
- args . push ( {
224
- array : 0 ,
225
- offset : o . slice ( )
226
- } )
227
- names . push ( 'inp' + i + 'l' , 'inp' + i + 'r' )
228
- }
229
120
return TEMPLATE_CACHE [ d ] = cwiseCompiler ( {
230
- args : args ,
231
- pre : EmptyProc ,
232
- post : EmptyProc ,
233
- body : {
234
- body : code . join ( '' ) ,
235
- args : names . map ( function ( n ) {
236
- return {
237
- name : n ,
238
- lvalue : n . indexOf ( 'out' ) === 0 ,
239
- rvalue : n . indexOf ( 'inp' ) === 0 ,
240
- count : ( n !== 'junk' ) | 0
241
- }
242
- } ) ,
243
- thisVars : [ ] ,
244
- localVars : [ ]
245
- } ,
246
121
funcName : 'fdTemplate' + d
247
122
} )
248
123
}
0 commit comments