— Function: **grid:map-grid**` &key source source-affi source-dims destination destination-affi destination-specification initial-element element-function combination-function`

Although this function has other uses, it can be used to create a grid
using a function of the index values. For example,
in the file Make a new grid by mapping on an existing grid or on indices. :source The source grid; if not a grid, it is taken as a function to apply to the grid indices to make the element of the destination; if this is supplied, source is ignored and element-function is only applied to the default value.

:source-affi The affi to be used for extraction; defaults to- making an affi from source-dims, then destination-specification.
:source-dims The dimensions of the source if source not supplied;- if
`nil`

, dimensions are taken from destination-specification.:destination The destination grid, if not supplied, it will be made- according to destination-affi and destination-specification.
:destination-affi The affi for injection, defaults to (affi destination)- if destination is supplied, then makes an affi if destination-specification is supplied, otherwise source-affi.
:destination-specification The specification to use for the destination to be make,- defaults to the specification of source.
:initial-element The default value to set in a newly-created destination.:element-function The function to apply to each element of the source; defaults- to coercing element to the element type of the destination.
:combination-function- A designator for a function of two arguments, or nil (default). If a function, it will be funcalled on the destination element and the transformed source element. If nil, the destination element is overwritten.

`index-fill-decadal`

that multiplies increasing powers of ten by
each argument in succession, and adds the result. The array
`*array-3-4-double-float*`

is created with this function:
(defparameter *array-3-4-double-float* (map-grid :source 'index-fill-decadal :source-dims '(3 4)))

which gives

*array-3-4-double-float* #2A((0.0d0 1.0d0 2.0d0 3.0d0) (10.0d0 11.0d0 12.0d0 13.0d0) (20.0d0 21.0d0 22.0d0 23.0d0))

(see also the function 'test-grid-double-float).

Take the square root of every element of an array:

(map-grid :source #m((0.0d0 1.0d0 2.0d0) (10.0d0 11.0d0 12.0d0) (20.0d0 21.0d0 22.0d0)) :element-function 'sqrt)

Make a foreign vector with each element the square root of its index:

(map-grid :source 'sqrt :destination-specification '((foreign-array 6) double-float))