apl: ⍸ where — monadic indices-of-truthy + dyadic interval-index
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s

- apl-where (monadic): ravel scan, filter non-zero, +⎕IO offsets
- apl-interval-index (dyadic): count of breaks ≤ y; broadcasts over
  scalar or vector Y
- Wired into apl-monadic-fn / apl-dyadic-fn cond chains
- +10 pipeline tests covering both arities, ⎕IO offsetting, edge cases
  (empty mask, all-truthy, y below/above all breaks)
- pipeline 109/109
This commit is contained in:
2026-05-08 22:35:35 +00:00
parent 58c6ec27f3
commit 8cdebbe305
4 changed files with 71 additions and 1 deletions

View File

@@ -827,6 +827,31 @@
((new-ravel (reduce (fn (acc r) (append acc (map (fn (j) (nth ravel (+ (* r cols) j))) (range 0 cols)))) (list) kept-rows)))
(make-array (cons (len kept-rows) (rest shape)) new-ravel))))))))
(define
apl-where
(fn
(arr)
(let
((ravel (get arr :ravel)) (io (disclose (apl-quad-io))))
(let
((indices (filter (fn (i) (not (= (nth ravel i) 0))) (range 0 (len ravel)))))
(apl-vector (map (fn (i) (+ i io)) indices))))))
(define
apl-interval-index
(fn
(breaks vals)
(let
((b-ravel (get breaks :ravel))
(v-ravel
(if (scalar? vals) (list (disclose vals)) (get vals :ravel))))
(let
((result (map (fn (y) (len (filter (fn (b) (<= b y)) b-ravel))) v-ravel)))
(if
(scalar? vals)
(apl-scalar (first result))
(make-array (get vals :shape) result))))))
(define
apl-primes
(fn