Skip to content

Commit

Permalink
Merge pull request #266 from gpujs/259-intercept-atan2
Browse files Browse the repository at this point in the history
fix #259 by handling when atan2 is used directly in the interpreter
  • Loading branch information
robertleeplummerjr authored Feb 27, 2018
2 parents 225946b + 01299be commit 8a88552
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bin/gpu-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* GPU Accelerated JavaScript
*
* @version 1.0.1
* @date Sun Feb 25 2018 19:14:46 GMT-0500 (EST)
* @date Tue Feb 27 2018 13:04:39 GMT-0500 (EST)
*
* @license MIT
* The MIT License
Expand Down
2 changes: 1 addition & 1 deletion bin/gpu-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion bin/gpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* GPU Accelerated JavaScript
*
* @version 1.0.1
* @date Sun Feb 25 2018 19:14:47 GMT-0500 (EST)
* @date Tue Feb 27 2018 13:04:40 GMT-0500 (EST)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -2634,6 +2634,10 @@ module.exports = function (_FunctionNodeBase) {
funcName = funcName.slice(localPrefix.length);
}

if (funcName === 'atan2') {
funcName = 'atan';
}

if (funcParam.calledFunctions.indexOf(funcName) < 0) {
funcParam.calledFunctions.push(funcName);
}
Expand Down
10 changes: 5 additions & 5 deletions bin/gpu.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dist/backend/web-gl/function-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,11 @@ module.exports = function (_FunctionNodeBase) {
funcName = funcName.slice(localPrefix.length);
}

// if this if grows to more than one, lets use a switch
if (funcName === 'atan2') {
funcName = 'atan';
}

// Register the function into the called registry
if (funcParam.calledFunctions.indexOf(funcName) < 0) {
funcParam.calledFunctions.push(funcName);
Expand Down
5 changes: 5 additions & 0 deletions src/backend/web-gl/function-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,11 @@ module.exports = class WebGLFunctionNode extends FunctionNodeBase {
funcName = funcName.slice(localPrefix.length);
}

// if this if grows to more than one, lets use a switch
if (funcName === 'atan2') {
funcName = 'atan';
}

// Register the function into the called registry
if (funcParam.calledFunctions.indexOf(funcName) < 0) {
funcParam.calledFunctions.push(funcName);
Expand Down
17 changes: 17 additions & 0 deletions test/html/issues/259-atan2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GPU.JS: createKernelMap with floatOutput</title>
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">

<!-- gpu.js scripts -->
<script src="../../../bin/gpu.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../../../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../../src/issues/259.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions test/html/test-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<script src="../src/issues/207-same-function-reuse.js"></script>
<script src="../src/issues/212-funky-function-support.js"></script>
<script src="../src/issues/233-kernel-map-float-output.js"></script>
<script src="../src/issues/259-atan2.js"></script>
<script src="../src/issues/263-to-string.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions test/src/issues/259-atan2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function buildAtan2KernelResult(mode) {
const gpu = new GPU({ mode });
const kernel = gpu.createKernel(function() {
return Math.atan2(1, 2);
}, {
output: [1]
});
return kernel();
}

QUnit.test('Issue #259 atan2 - auto', () => {
QUnit.assert.equal(buildAtan2KernelResult()[0].toFixed(7), 0.4636476);
});

QUnit.test('Issue #259 atan2 - gpu', () => {
QUnit.assert.equal(buildAtan2KernelResult('gpu')[0].toFixed(7), 0.4636476);
});

QUnit.test('Issue #259 atan2 - cpu', () => {
QUnit.assert.equal(buildAtan2KernelResult('cpu')[0].toFixed(7), 0.4636476);
});

0 comments on commit 8a88552

Please sign in to comment.