Email list hosting service & mailing list manager

Ideas for an advanced array procedure SRFI John Cowan (11 Jan 2020 23:57 UTC)
Re: Ideas for an advanced array procedure SRFI Arthur A. Gleckler (12 Jan 2020 01:07 UTC)
Re: Ideas for an advanced array procedure SRFI John Cowan (12 Jan 2020 01:36 UTC)
Re: Ideas for an advanced array procedure SRFI Arthur A. Gleckler (12 Jan 2020 02:38 UTC)
Re: Ideas for an advanced array procedure SRFI John Cowan (12 Jan 2020 02:48 UTC)
Re: Ideas for an advanced array procedure SRFI Arthur A. Gleckler (12 Jan 2020 05:02 UTC)
Re: Ideas for an advanced array procedure SRFI Lassi Kortela (12 Jan 2020 12:36 UTC)
Re: Ideas for an advanced array procedure SRFI John Cowan (12 Jan 2020 19:26 UTC)
Re: Ideas for an advanced array procedure SRFI Lassi Kortela (13 Jan 2020 19:17 UTC)
Re: Ideas for an advanced array procedure SRFI Arthur A. Gleckler (13 Jan 2020 21:57 UTC)
Re: Ideas for an advanced array procedure SRFI Bradley Lucier (12 Jan 2020 18:11 UTC)
Re: Ideas for an advanced array procedure SRFI Bradley Lucier (26 Jan 2020 19:37 UTC)
Re: Ideas for an advanced array procedure SRFI Bradley Lucier (17 Jan 2020 00:07 UTC)
Re: Ideas for an advanced array procedure SRFI John Cowan (17 Jan 2020 03:10 UTC)
Re: Ideas for an advanced array procedure SRFI Bradley Lucier (05 May 2022 15:36 UTC)

Re: Ideas for an advanced array procedure SRFI Bradley Lucier 26 Jan 2020 19:37 UTC

On 1/12/20 1:11 PM, Lucier, Bradley J wrote:
> That being said, I tried my hand as implementing some of these
> procedures using the updated SRFI-122.
>
> (define (array-inner-product sum sum-knil product a1 a2)
>     (let ((rotated-a2
>            ;; move the first index of a2 to the end,
>            ;; keeping all others the same
>            (let* ((n2 (array-dimension a2))
>                   (permutation (make-vector n2)))
>              (do ((i 1 (fx+ i 1)))
>                  ((fx= i n2)
>                   (vector-set! permutation (fx- n2 1) 0))
>                (vector-set! permutation (fx- i 1) i))
>              (array-permute a2 permutation))))
>       (array-outer-product
>        (lambda (sub1 sub2)
>          (array-fold sum sum-knil
>                      (array-map product sub1 sub2)))
>        (array-curry a1 1)
>        (array-curry rotated-a2 1))))

With the new array-rotate and array-reduce procedures I just added to
SRFI 179, this would be

(define (array-inner-product sum product a1 a2)

   ;; Assumes that both a1 and a2 are both of
   ;; dimension higher than 1.

   ;; Otherwise, must use the array-reduce in the
   ;; following lambda.

   (array-outer-product
    (lambda (sub1 sub2)
      (array-reduce sum (array-map product sub1 sub2)))
    ;; make subarrays with the rightmost index
    (array-curry a1 1)
    ;; rotate to put the leftmost index on the right,
    ;; then make subarrays
    (array-curry (array-rotate a2 1) 1)))

But neither code will work for the usual vector x vector -> scalar inner
product.

Brad