N Dimensional Array Function Generator
install using npm
npm install typed-array-function
Create an operator:
var typed = ;var addeq = ;var X = typedvar Y = typed//Add them together
Typed-array Function Notation
Pass a string or a function. If a function is passed it is immedietly converted ot a string, but this allows source code to be correctly check by a jslint like precessor.
The text is split in to 3 sections on the "// ----" separator. If only a single "section" is supplied it is used as the loop body.
The first section is the preparatory code.
The second section is enclosed in the element wise loops.
The third section is the post code. If no third section is supplied the function's first argument is returned.
The indicies of the element wise loop are accessed via dedicated variables.
Or via an array named "index".
The starting and ending index of each dimensions can be adjusted by the prepratory code by updating the ranges in the start and end arrays.
Multiply an array by a value (could be a scaler or another array).
var mul =
Initialize an array with with the last index, this is an inconpatible difference with cwise.
var mgrid = ;
Check if any element is set.
var any =
Compute the sum of all the elements in an array.
var sum =;
Create a function to fill each element of the array with the return value of a function. The current indicies are passed as arguments.
var fill = ;
Compute the RMS of the values in an array.
var rms =;
Compute the index of the maximum element of an array:
var argmin =;//Usage:
A significant portion of the execution time of a typed-array function can be consumed looking up the funcitons type signature in the function cache to see if it has been generated before. If the data types of the arguments of a function that will be called multple time from a particular context are fixed, the function can be pre generated and saved in a local variable. I've called this process "baking".
The baking API is still very beta.
These functions are added as menbers of the main typed function. For example:
var copy = typed;
Is it fast?
How does it work?
(c) (2014) John B. Roll
Inspired by the ndarray cwise compiler by Mikola Lysenko. This README is cribbed directly from cwise.