Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 7738392

Browse files
authored
Merge pull request #1 from plotly/inline-cwise-functions
Inline function constructors of zero-crossings module
2 parents 82235d9 + bb8ea62 commit 7738392

File tree

4 files changed

+63
-81
lines changed

4 files changed

+63
-81
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ logs
1212
results
1313

1414
npm-debug.log
15+
package-lock.json
1516
node_modules/*
1617
*.DS_Store

lib/generate-module.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/zc-core.js

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,61 @@
1-
module.exports = require('cwise-compiler')({
2-
args: ['array', {
3-
offset: [1],
4-
array: 0
5-
}, 'scalar', 'scalar', 'index'],
6-
pre: {
7-
"body": "{}",
8-
"args": [],
9-
"thisVars": [],
10-
"localVars": []
11-
},
12-
post: {
13-
"body": "{}",
14-
"args": [],
15-
"thisVars": [],
16-
"localVars": []
17-
},
18-
body: {
19-
"body": "{\n var _inline_1_da = _inline_1_arg0_ - _inline_1_arg3_\n var _inline_1_db = _inline_1_arg1_ - _inline_1_arg3_\n if((_inline_1_da >= 0) !== (_inline_1_db >= 0)) {\n _inline_1_arg2_.push(_inline_1_arg4_[0] + 0.5 + 0.5 * (_inline_1_da + _inline_1_db) / (_inline_1_da - _inline_1_db))\n }\n }",
20-
"args": [{
21-
"name": "_inline_1_arg0_",
22-
"lvalue": false,
23-
"rvalue": true,
24-
"count": 1
25-
}, {
26-
"name": "_inline_1_arg1_",
27-
"lvalue": false,
28-
"rvalue": true,
29-
"count": 1
30-
}, {
31-
"name": "_inline_1_arg2_",
32-
"lvalue": false,
33-
"rvalue": true,
34-
"count": 1
35-
}, {
36-
"name": "_inline_1_arg3_",
37-
"lvalue": false,
38-
"rvalue": true,
39-
"count": 2
40-
}, {
41-
"name": "_inline_1_arg4_",
42-
"lvalue": false,
43-
"rvalue": true,
44-
"count": 1
45-
}],
46-
"thisVars": [],
47-
"localVars": ["_inline_1_da", "_inline_1_db"]
48-
},
1+
"use strict"
2+
3+
function CWiseOp() {
4+
return function(SS, a0, t0, p0, Y0, Y1) {
5+
var s0 = SS[0],
6+
t0p0 = t0[0],
7+
index = [0],
8+
q0 = t0p0
9+
p0 |= 0
10+
var i0 = 0,
11+
d0s0 = t0p0
12+
for (i0 = 0; i0 < s0; ++i0) {
13+
{
14+
var da = a0[p0] - Y1
15+
var db = a0[p0 + q0] - Y1
16+
if (da >= 0 !== db >= 0) {
17+
Y0.push(index[0] + 0.5 + (0.5 * (da + db)) / (da - db))
18+
}
19+
}
20+
p0 += d0s0
21+
++index[0]
22+
}
23+
}
24+
}
25+
26+
//Generates a cwise operator
27+
function generateCWiseOp() {
28+
return CWiseOp()
29+
}
30+
31+
var compile = generateCWiseOp
32+
33+
function thunk(compile) {
34+
var CACHED = {}
35+
return function zeroCrossings_cwise_thunk(array0, scalar2, scalar3) {
36+
var t0 = array0.dtype,
37+
r0 = array0.order,
38+
type = [t0, r0.join()].join(),
39+
proc = CACHED[type]
40+
41+
if (!proc) {
42+
CACHED[type] = proc = compile([t0, r0])
43+
}
44+
45+
return proc(array0.shape.slice(0), array0.data, array0.stride, array0.offset | 0, scalar2, scalar3)
46+
}
47+
}
48+
49+
function createThunk(proc) {
50+
return thunk(compile.bind(undefined, proc))
51+
}
52+
53+
function compileCwise(user_args) {
54+
return createThunk({
55+
funcName: user_args.funcName
56+
})
57+
}
58+
59+
module.exports = compileCwise({
4960
funcName: 'zeroCrossings'
5061
})

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
"directories": {
77
"test": "test"
88
},
9-
"dependencies": {
10-
"cwise-compiler": "^1.0.0"
11-
},
9+
"dependencies": {},
1210
"devDependencies": {
13-
"cwise-parser": "^0.0.1",
1411
"ndarray": "^1.0.11",
15-
"tape": "^2.12.3",
16-
"js-beautify": "^1.4.2"
12+
"tape": "^2.12.3"
1713
},
1814
"scripts": {
19-
"test": "tape test/*.js",
20-
"build": "node lib/generate-module.js > lib/zc-core.js"
15+
"test": "tape test/*.js"
2116
},
2217
"repository": {
2318
"type": "git",

0 commit comments

Comments
 (0)