Skip to content

Commit 2599966

Browse files
fix: Better defining internal lookups of types and documentation
1 parent d561fcf commit 2599966

File tree

17 files changed

+567
-418
lines changed

17 files changed

+567
-418
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ megaKernel(a, b, c);
346346
This gives you the flexibility of using parts of a single transformation without the performance penalty, resulting in much much _MUCH_ faster operation.
347347

348348
## Adding custom functions
349-
Do you have a custom function you'd like to use on the gpu? Although limited, you can:
349+
use `gpu.addFunction(function() {}, options)` for adding custom functions. Example:
350+
351+
350352
```js
351353
gpu.addFunction(function mySuperFunction(a, b) {
352354
return a - b;
@@ -360,6 +362,30 @@ const kernel = gpu.createKernel(function(a, b) {
360362
}).setOutput([20]);
361363
```
362364

365+
### Adding strongly typed functions
366+
367+
To strongly type a function you may use options. Options take an optional hash values:
368+
`returnType`: optional, defaults to float, the value you'd like to return from the function
369+
`paramTypes`: optional, defaults to float for each param, a hash of param names with values of the return types
370+
371+
Types: that may be used for `returnType` or for each property of `paramTypes`:
372+
'Array'
373+
'Array(2)'
374+
'Array(3)'
375+
'Array(4)'
376+
'Integer'
377+
'HTMLImage'
378+
'HTMLImageArray'
379+
'Number'
380+
381+
Example:
382+
```js
383+
gpu.addFunction(function mySuperFunction(a, b) {
384+
return [a - b[1], b[0] - a];
385+
}, { paramTypes: { a: 'Integer', b: 'Array(2)'}, returnType: 'Array(2)' });
386+
```
387+
388+
363389
## Adding custom functions directly to kernel
364390
```js
365391
function mySuperFunction(a, b) {

bin/gpu-core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 1.9.1
8-
* @date Wed Oct 24 2018 15:14:26 GMT-0400 (EDT)
7+
* @version 1.10.0
8+
* @date Sun Oct 28 2018 13:54:33 GMT-0400 (EDT)
99
*
1010
* @license MIT
1111
* The MIT License

bin/gpu-core.min.js

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

0 commit comments

Comments
 (0)