Skip to content

Commit 33a2395

Browse files
fix: Add nested custom function support
1 parent 07cb307 commit 33a2395

File tree

7 files changed

+57
-11
lines changed

7 files changed

+57
-11
lines changed

dist/gpu-browser-core.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.4
8-
* @date Tue Oct 08 2019 10:27:37 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.5
8+
* @date Fri Oct 11 2019 07:23:33 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -2023,6 +2023,7 @@ class FunctionBuilder {
20232023
triggerImplyArgumentType,
20242024
triggerImplyArgumentBitRatio,
20252025
onFunctionCall,
2026+
onNestedFunction,
20262027
}));
20272028
}
20282029

@@ -2392,6 +2393,7 @@ class FunctionBuilder {
23922393
module.exports = {
23932394
FunctionBuilder
23942395
};
2396+
23952397
},{}],9:[function(require,module,exports){
23962398
const acorn = require('acorn');
23972399
const { utils } = require('../utils');

dist/gpu-browser-core.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gpu-browser.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.4
8-
* @date Tue Oct 08 2019 10:27:37 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.5
8+
* @date Fri Oct 11 2019 07:23:33 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -6787,6 +6787,7 @@ class FunctionBuilder {
67876787
triggerImplyArgumentType,
67886788
triggerImplyArgumentBitRatio,
67896789
onFunctionCall,
6790+
onNestedFunction,
67906791
}));
67916792
}
67926793

@@ -7156,6 +7157,7 @@ class FunctionBuilder {
71567157
module.exports = {
71577158
FunctionBuilder
71587159
};
7160+
71597161
},{}],10:[function(require,module,exports){
71607162
const acorn = require('acorn');
71617163
const { utils } = require('../utils');

dist/gpu-browser.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gpu.js",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "GPU Accelerated JavaScript",
55
"engines": {
66
"node": ">=8.0.0"

src/backend/function-builder.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class FunctionBuilder {
174174
triggerImplyArgumentType,
175175
triggerImplyArgumentBitRatio,
176176
onFunctionCall,
177+
onNestedFunction,
177178
}));
178179
}
179180

test/features/nested-function.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,44 @@ test('nested_sum gpu', () => {
5050
test('nested_sum cpu', () => {
5151
nestedSumABTest('cpu');
5252
});
53+
54+
function testNestedInCustomFunction(mode) {
55+
function custom1() {
56+
function nested1() {
57+
return 1;
58+
}
59+
60+
return nested1();
61+
}
62+
const gpu = new GPU({ mode });
63+
gpu.addFunction(custom1);
64+
const kernel = gpu.createKernel(function() {
65+
return custom1();
66+
}, { output: [1] });
67+
assert.deepEqual(kernel(), new Float32Array([1]));
68+
gpu.destroy();
69+
}
70+
71+
test('nested in custom auto', () => {
72+
testNestedInCustomFunction();
73+
});
74+
75+
test('nested in custom gpu', () => {
76+
testNestedInCustomFunction('gpu');
77+
});
78+
79+
(GPU.isWebGLSupported ? test : skip)('nested in custom webgl', () => {
80+
testNestedInCustomFunction('webgl');
81+
});
82+
83+
(GPU.isWebGL2Supported ? test : skip)('nested in custom webgl2', () => {
84+
testNestedInCustomFunction('webgl2');
85+
});
86+
87+
(GPU.isHeadlessGLSupported ? test : skip)('nested in custom headlessgl', () => {
88+
testNestedInCustomFunction('headlessgl');
89+
});
90+
91+
test('nested in custom cpu', () => {
92+
testNestedInCustomFunction('cpu');
93+
});

0 commit comments

Comments
 (0)