apl: at @ replace+apply (+10 tests, 211/211)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-05-07 00:27:40 +00:00
parent 9eecbde61e
commit 4c71c5a75e
3 changed files with 137 additions and 2 deletions

View File

@@ -1108,3 +1108,47 @@
(make-array
(append frame-shape (get (first results) :shape))
(flatten (map (fn (r) (get r :ravel)) results))))))))))))
(define
apl-at-replace
(fn
(vals idxs arr)
(let
((vals-ravel (get vals :ravel))
(idxs-ravel (get idxs :ravel))
(arr-ravel (get arr :ravel))
(arr-shape (get arr :shape))
(vals-scalar? (= (len (get vals :shape)) 0)))
(make-array
arr-shape
(map
(fn
(i)
(let
((pos (index-of idxs-ravel (+ i apl-io))))
(if
pos
(if vals-scalar? (first vals-ravel) (nth vals-ravel pos))
(nth arr-ravel i))))
(range 0 (len arr-ravel)))))))
(define
apl-at-apply
(fn
(f idxs arr)
(let
((idxs-ravel (get idxs :ravel))
(arr-ravel (get arr :ravel))
(arr-shape (get arr :shape)))
(make-array
arr-shape
(map
(fn
(i)
(let
((pos (index-of idxs-ravel (+ i apl-io))))
(if
pos
(disclose (f (apl-scalar (nth arr-ravel i))))
(nth arr-ravel i))))
(range 0 (len arr-ravel)))))))