1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-29 08:20:20 +02:00

(Array Mapping): Reword for clarity, and in

particular have the same parameter names in the text and prototypes.
This commit is contained in:
Kevin Ryde 2003-06-04 15:33:13 +00:00
parent d0624e391b
commit d23496c0c7

View file

@ -1386,43 +1386,74 @@ memory.
@node Array Mapping @node Array Mapping
@subsection Array Mapping @subsection Array Mapping
@deffn {Scheme Procedure} array-map! ra0 proc . lra @c FIXME: array-map! accepts no source arrays at all, and in that
@deffnx {Scheme Procedure} array-map-in-order! ra0 proc . lra @c case makes calls "(proc)". Is that meant to be a documented
@deffnx {C Function} scm_array_map_x (ra0, proc, lra) @c feature?
@var{array1}, @dots{} must have the same number of dimensions as @c
@var{array0} and have a range for each index which includes the range @c FIXME: array-for-each doesn't say what happens if the sources have
for the corresponding index in @var{array0}. @var{proc} is applied to @c different index ranges. The code currently iterates over the
each tuple of elements of @var{array1} @dots{} and the result is stored @c indices of the first and expects the others to cover those. That
as the corresponding element in @var{array0}. The value returned is @c at least vaguely matches array-map!, but is is meant to be a
unspecified. The order of application is unspecified. @c documented feature?
@deffn {Scheme Procedure} array-map! dst proc src1 @dots{} srcN
@deffnx {Scheme Procedure} array-map-in-order! dst proc src1 @dots{} srcN
@deffnx {C Function} scm_array_map_x (dst, proc, srclist)
Set each element of the @var{dst} array to values obtained from calls
to @var{proc}. The value returned is unspecified.
Each call is @code{(@var{proc} @var{elem1} @dots{} @var{elemN})},
where each @var{elem} is from the corresponding @var{src} array, at
the @var{dst} index. @code{array-map-in-order!} makes the calls in
row-major order, @code{array-map!} makes them in an unspecified order.
The @var{src} arrays must have the same number of dimensions as
@var{dst}, and must have a range for each dimension which covers the
range in @var{dst}. This ensures all @var{dst} indices are valid in
each @var{src}.
@end deffn @end deffn
@deffn {Scheme Procedure} array-for-each proc ra0 . lra @deffn {Scheme Procedure} array-for-each proc src1 @dots{} srcN
@deffnx {C Function} scm_array_for_each (proc, ra0, lra) @deffnx {C Function} scm_array_for_each (proc, src1, srclist)
Apply @var{proc} to each tuple of elements of @var{array0} @dots{} Apply @var{proc} to each tuple of elements of @var{src1} @dots{}
in row-major order. The value returned is unspecified. @var{srcN}, in row-major order. The value returned is unspecified.
@end deffn @end deffn
@deffn {Scheme Procedure} array-index-map! ra proc @deffn {Scheme Procedure} array-index-map! dst proc
@deffnx {C Function} scm_array_index_map_x (ra, proc) @deffnx {C Function} scm_array_index_map_x (dst, proc)
Apply @var{proc} to the indices of each element of @var{array} in Set each element of the @var{dst} array to values returned by calls to
turn, storing the result in the corresponding element. The value @var{proc}. The value returned is unspecified.
returned and the order of application are unspecified.
One can implement @var{array-indexes} as Each call is @code{(@var{proc} @var{i1} @dots{} @var{iN})}, where
@lisp @var{i1}@dots{}@var{iN} is the destination index, one parameter for
(define (array-indexes array) each dimension. The order in which the calls are made is unspecified.
(let ((ra (apply make-array #f (array-shape array))))
(array-index-map! ra (lambda x x)) For example, to create a @m{4\times4, 4x4} matrix representing a
ra)) cyclic group,
@end lisp
Another example: @tex
@lisp \advance\leftskip by 2\lispnarrowing {
(define (apl:index-generator n) $\left(\matrix{%
(let ((v (make-uniform-vector n 1))) 0 & 1 & 2 & 3 \cr
(array-index-map! v (lambda (i) i)) 1 & 2 & 3 & 0 \cr
v)) 2 & 3 & 0 & 1 \cr
@end lisp 3 & 0 & 1 & 2 \cr
}\right)$} \par
@end tex
@ifnottex
@example
/ 0 1 2 3 \
| 1 2 3 0 |
| 2 3 0 1 |
\ 3 0 1 2 /
@end example
@end ifnottex
@example
(define a (make-array #f 4 4))
(array-index-map! a (lambda (i j)
(modulo (+ i j) 4)))
@end example
@end deffn @end deffn
@node Uniform Arrays @node Uniform Arrays