ndarray-stencil
Stencil iterators for ndarrays. This code can be used to implement things like cellular automata or various PDE operations on ndarrays.
Example
var zeros = var points = -1 0 1 0 0-1 0 1 var diffuse = points { return 025 * a + b + c + d} var x = var y = x //Now://// y =[ [ 0, 0, 0, 0, 0 ],// [ 0, 0, 0.25, 0, 0 ],// [ 0, 0.25, 0, 0.25, 0 ],// [ 0, 0, 0.25, 0, 0 ],// [ 0, 0, 0, 0, 0 ] ]
Install
npm install ndarray-stencil
require("ndarray-stencil")(points, stencil_func[, options])
Creates a stencil operator for an ndarray.
points
is a list of points that the stencil will be evaluated onstencil_func(...)
is a function that takes in n arguments, wheren
is the number points to evaluate the stencil on, and returns the new value of the grid on the given point.options
is an object containing a list of optional properties:useIndex
If this flag is set, add an extra index parameter as the last argument tostencil_func
. (Defaultfalse
)sameOutput
if set, then the output is not sliced and instead the result of the stencil operation is applied directly to output
Returns A function that applies the stencil to two arrays. The first argument is the output array, and the second is the input.
Credits
(c) 2013 Mikola Lysenko. MIT License