array-map [was: last call] Per Bothner (22 Jul 2019 05:13 UTC)
Re: array-map [was: last call] Lassi Kortela (24 Jul 2019 10:37 UTC)
Re: array-map [was: last call] Per Bothner (25 Jul 2019 15:43 UTC)
Re: array-map [was: last call] Lassi Kortela (28 Jul 2019 15:25 UTC)
Re: array-map [was: last call] Per Bothner (04 Aug 2019 23:28 UTC)
Re: array-map [was: last call] Lassi Kortela (07 Aug 2019 18:07 UTC)
Re: array-map [was: last call] John Cowan (24 Jul 2019 11:01 UTC)
Re: array-map [was: last call] Per Bothner (25 Jul 2019 15:35 UTC)
Re: array-map [was: last call] John Cowan (25 Jul 2019 18:49 UTC)

Re: array-map [was: last call] Per Bothner 25 Jul 2019 15:34 UTC

For what it is worth, one could express

   (array-map + a1 a2)

as:

   (array-copy
    (build-array (array-shape a1)
                 (lambda (I)
                   (+ (array-ref a1 I) (array-ref a2 I))))))

This uses array-copy, which could be defined as:

(define (array-copy arr)
   (array-reshape (array-flatten arr) (array-shape arr)))

Using array-as-procedure and Kawa argument splicing:

   (array-copy
    (build-array (array-shape a1)
                 (lambda (I)
                   (+ (a1 @I) (a2 @I))))))

Using array-as-procedure and Kawa pattern matching:

    (build-array (array-shape a1)
                 (lambda ([i j])
                   (+ (a1 i j) (a2 i j))))))

This is not to argue that array-map doesn't belong in an
arraya API (I think it does), but to show that it is only
a modest reduction in boilerplate.  And using build-array
is obviously more flexible. Performance-wise (and assuming no
non-trivial optimizations) build-array is probably more expensive
than a single array-map, but is probably cheaper than multiple
array-maps.  (You can often use build-array to manually merge
multiple array-maps.)
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/