|
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({ |
49 | 60 | funcName: 'zeroCrossings'
|
50 | 61 | })
|
0 commit comments