Last active
October 27, 2018 09:01
-
-
Save enobufs/0ac640afb9ea231b05f91a84e7a4a858 to your computer and use it in GitHub Desktop.
Scan NdArray in row-major oder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nj = require('numjs'); | |
function scan(ndarr, cb) { | |
const args = Array(ndarr.shape.length).fill(0); | |
function _scan(ndarr, cb) { | |
const shape = ndarr.shape; | |
const argi = args.length - shape.length; | |
for (args[argi] = 0; args[argi] < shape[0]; ++args[argi]) { | |
if (shape.length > 1) { | |
const d = ndarr.pick(args[argi]); | |
_scan(d, cb); | |
} else { | |
cb(...args); | |
} | |
} | |
} | |
_scan(ndarr, cb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment