- pointwise-extend scalar-procedureprocedure
Produces a dyadic (arity 2) procedure that is the pointwise extension of a dyadic (arity 2) scalar procedure.
The resulting procedure will accept any two scalars or arrays that have compatible dimensions and will perform the scalar procedure across those dimensions. Two arrays have compatible dimensions iff:
- The shape of the arrays is the exact same
- The shape of one of the arrays is a lower rank than the other, and the sub-dimension of the first array is compatible with the second. e.g. #(5 1) would be compatible with the sub-dimension of #(3 5 1).
- One or two of the arguments are scalars, and not arrays.
The scalar-proc must be a procedure with at least arity of 2. It is applied with the ordering such that all operations will respect similar ordering to the caller. For example, if your scalar-proc was string-append, you would not see arguments re-ordered, but instead the resulting procedure produced by pointwise-extend (which takes two arguments, lets say A and B) would apply the scalar procedure such that individual array elements would be ordered as though the procedure was called as (scalar-proc a b).
The returned procedure takes an optional 3rd argument, which is the storage class that the final array (as a result of the extended operation) should use. This defaults to the storage class of the first argument (if it is an array), and then the storage-class of the second argument, if the first is not an array.
(define +^ (pointwise-extend +)) (define a #a2v((1 2 3) (4 5 6))) (define b #a2v((2 1 3))) (+^ a b) ;=> #a2v((3 3 6) (6 6 9))
Note that a monadic (single argument) version of pointwise extension is not necessary, as that would roughly translate into (for e.g. the sqrt procedure):
(define a #a2v((1 4 9) (16 25 36))) (transduce array-fold (map sqrt) (collect-array (array-storage-class a) (interval-end (array-shape a))) a) ;=> #a2v((1 2 3) (4 5 6))