Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with string functions #729

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backend/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ class Kernel {
addFunction(source, settings = {}) {
if (source.name && source.source && source.argumentTypes && 'returnType' in source) {
this.functions.push(source);
} else if ('settings' in source && 'source' in source) {
this.functions.push(this.functionToIGPUFunction(source.source, source.settings));
} else if (typeof source === 'string' || typeof source === 'function') {
this.functions.push(this.functionToIGPUFunction(source, settings));
} else if ('settings' in source && 'source' in source) {
this.functions.push(this.functionToIGPUFunction(source.source, source.settings));
} else {
throw new Error(`function not properly defined`);
}
Expand Down
45 changes: 45 additions & 0 deletions test/internal/functions-as-strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { assert, skip, test, module: describe, only } = require('qunit');
const { GPU } = require('../../src');

describe('internal: functions-as-atrings');

function functionsAsStrings(mode) {
const gpu = new GPU({ mode });
const kernel = gpu.createKernel(`function() {
let x = frodo(0)
return x;
}`, {
output: [1],
});
kernel.addFunction(`function frodo(a){
return a + 1
}`)
const result = kernel();
console.log('result',result)
assert.equal(result[0],1);
gpu.destroy();
}

test('boolean expression false auto', () => {
functionsAsStrings();
});

test('boolean expression false gpu', () => {
functionsAsStrings('gpu');
});

(GPU.isWebGLSupported ? test : skip)('boolean expression false webgl', () => {
functionsAsStrings('webgl');
});

(GPU.isWebGL2Supported ? test : skip)('boolean expression false webgl2', () => {
functionsAsStrings('webgl2');
});

(GPU.isHeadlessGLSupported ? test : skip)('boolean expression false headlessgl', () => {
functionsAsStrings('headlessgl');
});

test('boolean expression false cpu', () => {
functionsAsStrings('cpu');
});