Skip to content

Commit 28f575c

Browse files
committed
simplify more
1 parent 19b7f95 commit 28f575c

File tree

1 file changed

+3
-128
lines changed

1 file changed

+3
-128
lines changed

fdg.js

+3-128
Original file line numberDiff line numberDiff line change
@@ -88,59 +88,10 @@ function compile(proc) {
8888
return CACHED_CWiseOp[proc.funcName]
8989
}
9090

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-
10791
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+
})
14495
}
14596

14697

@@ -155,94 +106,18 @@ var EmptyProc = {
155106
}
156107

157108
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-
},
182109
funcName: 'cdiff'
183110
})
184111

185112
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-
},
200113
funcName: 'zero'
201114
})
202115

203116
function generateTemplate(d) {
204117
if(d in TEMPLATE_CACHE) {
205118
return TEMPLATE_CACHE[d]
206119
}
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-
}
229120
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-
},
246121
funcName: 'fdTemplate' + d
247122
})
248123
}

0 commit comments

Comments
 (0)