Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Adding custom pool functions

Matias Vazquez-Levi edited this page Feb 14, 2021 · 7 revisions

Back to Home


Pool functions are stored in an Object value named poolfuncs. In the browser, it is set as a global value.
For nodejs you can require such object like so:

const dn = require('dannjs');
const poolfuncs = dn.poolfuncs;

To add your own function, add a new Object property referencing the function you want to add.

poolfuncs.name = function;

Here's an example with the pre-existing 'avgpool' pool function under a different name:

const dn = require('dannjs');     //nodejs only
const poolfuncs = dn.poolfuncs;   //nodejs only

poolfuncs.myCustomFunc = function (arr) {
    let sum = 0;
    let len = arr.length;
    for (let i = 0; i < len; i++) {
        sum += arr[i];
    }
    return sum/len;
}

const layer = new Layer('myCustomFuncpool', 9, 2, 1);

To use this function in a pool layer you need to specify the type as 'functionName' + 'pool'.


Function arguments

A pool function is used to select/compute a value out of an array.

  • array
    An array used to compute a numeric value as an output.

  • returns
    A numeric value


Clone this wiki locally