apl: each f¨ monadic + dyadic (+14 tests, 139/139)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s

This commit is contained in:
2026-05-06 21:14:49 +00:00
parent c56f400403
commit 3489c9f131
3 changed files with 125 additions and 2 deletions

View File

@@ -961,3 +961,38 @@
(rest col))))
(range 0 inner-size)))
(range 0 first-dim)))))))))
(define
apl-each
(fn
(f arr)
(let
((shape (get arr :shape)) (ravel (get arr :ravel)))
(make-array
shape
(map (fn (x) (disclose (f (apl-scalar x)))) ravel)))))
(define
apl-each-dyadic
(fn
(f a b)
(cond
((and (scalar? a) (scalar? b)) (apl-scalar (disclose (f a b))))
((scalar? a)
(make-array
(get b :shape)
(map (fn (x) (disclose (f a (apl-scalar x)))) (get b :ravel))))
((scalar? b)
(make-array
(get a :shape)
(map (fn (x) (disclose (f (apl-scalar x) b))) (get a :ravel))))
(else
(if
(equal? (get a :shape) (get b :shape))
(make-array
(get a :shape)
(map
(fn (x y) (disclose (f (apl-scalar x) (apl-scalar y))))
(get a :ravel)
(get b :ravel)))
(error "length error: shape mismatch"))))))